1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java Sat Jan 04 23:44:34 2014 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java Sun Jan 05 00:17:27 2014 +0100
1.3 @@ -25,11 +25,15 @@
1.4 import info.globalcode.sql.dk.configuration.Properties;
1.5 import info.globalcode.sql.dk.configuration.Property;
1.6 import static info.globalcode.sql.dk.formatting.AbstractXmlFormatter.qname;
1.7 +import java.sql.Array;
1.8 +import java.sql.SQLException;
1.9 import java.util.Date;
1.10 import java.util.HashMap;
1.11 import java.util.List;
1.12 import java.util.Map;
1.13 import java.util.Scanner;
1.14 +import java.util.logging.Level;
1.15 +import java.util.logging.Logger;
1.16 import javax.xml.namespace.QName;
1.17
1.18 /**
1.19 @@ -38,6 +42,7 @@
1.20 */
1.21 public class XhtmlFormatter extends AbstractXmlFormatter {
1.22
1.23 + private static final Logger log = Logger.getLogger(XhtmlFormatter.class.getName());
1.24 public static final String NAME = "xhtml"; // bash-completion:formatter
1.25 private static final String DOCTYPE = "html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\" \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\"";
1.26 private static final String CSS_FILE = "info/globalcode/sql/dk/formatter/XhtmlFormatter.css";
1.27 @@ -155,13 +160,42 @@
1.28 }
1.29
1.30 private void printTableData(Object value) {
1.31 - Map<QName, String> attributes = new HashMap<>(1);
1.32 - if (value instanceof Number) {
1.33 - attributes.put(qname("class"), "number");
1.34 - } else if (value instanceof Boolean) {
1.35 - attributes.put(qname("class"), "boolean");
1.36 +
1.37 + if (value instanceof Array) {
1.38 + Array sqlArray = (Array) value;
1.39 + try {
1.40 + Object[] array = (Object[]) sqlArray.getArray();
1.41 + printStartElement(qname("td"));
1.42 + printArray(array);
1.43 + printEndElement();
1.44 + } catch (SQLException e) {
1.45 + log.log(Level.SEVERE, "Unable to format array", e);
1.46 + printTableData(String.valueOf(value));
1.47 + }
1.48 + } else {
1.49 + Map<QName, String> attributes = new HashMap<>(1);
1.50 + if (value instanceof Number) {
1.51 + attributes.put(qname("class"), "number");
1.52 + } else if (value instanceof Boolean) {
1.53 + attributes.put(qname("class"), "boolean");
1.54 + }
1.55 + printTextElement(qname("td"), attributes, String.valueOf(value));
1.56 }
1.57 - printTextElement(qname("td"), attributes, String.valueOf(value));
1.58 + }
1.59 +
1.60 + private void printArray(Object[] array) {
1.61 + printStartElement(qname("ul"));
1.62 + for (Object o : array) {
1.63 + if (o instanceof Object[]) {
1.64 + printStartElement(qname("li"));
1.65 + printTextElement(qname("p"), null, "nested array:");
1.66 + printArray((Object[]) o);
1.67 + printEndElement();
1.68 + } else {
1.69 + printTextElement(qname("li"), null, String.valueOf(o));
1.70 + }
1.71 + }
1.72 + printEndElement();
1.73 }
1.74
1.75 @Override