23 import info.globalcode.sql.dk.Xmlns; |
23 import info.globalcode.sql.dk.Xmlns; |
24 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
24 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
25 import info.globalcode.sql.dk.configuration.Properties; |
25 import info.globalcode.sql.dk.configuration.Properties; |
26 import info.globalcode.sql.dk.configuration.Property; |
26 import info.globalcode.sql.dk.configuration.Property; |
27 import static info.globalcode.sql.dk.formatting.AbstractXmlFormatter.qname; |
27 import static info.globalcode.sql.dk.formatting.AbstractXmlFormatter.qname; |
|
28 import java.sql.Array; |
|
29 import java.sql.SQLException; |
28 import java.util.Date; |
30 import java.util.Date; |
29 import java.util.HashMap; |
31 import java.util.HashMap; |
30 import java.util.List; |
32 import java.util.List; |
31 import java.util.Map; |
33 import java.util.Map; |
32 import java.util.Scanner; |
34 import java.util.Scanner; |
|
35 import java.util.logging.Level; |
|
36 import java.util.logging.Logger; |
33 import javax.xml.namespace.QName; |
37 import javax.xml.namespace.QName; |
34 |
38 |
35 /** |
39 /** |
36 * |
40 * |
37 * @author Ing. František Kučera (frantovo.cz) |
41 * @author Ing. František Kučera (frantovo.cz) |
38 */ |
42 */ |
39 public class XhtmlFormatter extends AbstractXmlFormatter { |
43 public class XhtmlFormatter extends AbstractXmlFormatter { |
40 |
44 |
|
45 private static final Logger log = Logger.getLogger(XhtmlFormatter.class.getName()); |
41 public static final String NAME = "xhtml"; // bash-completion:formatter |
46 public static final String NAME = "xhtml"; // bash-completion:formatter |
42 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\""; |
47 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\""; |
43 private static final String CSS_FILE = "info/globalcode/sql/dk/formatter/XhtmlFormatter.css"; |
48 private static final String CSS_FILE = "info/globalcode/sql/dk/formatter/XhtmlFormatter.css"; |
44 private int resultSetCounter = 0; |
49 private int resultSetCounter = 0; |
45 private int updatesResultCounter = 0; |
50 private int updatesResultCounter = 0; |
153 printEndElement(); |
158 printEndElement(); |
154 } |
159 } |
155 } |
160 } |
156 |
161 |
157 private void printTableData(Object value) { |
162 private void printTableData(Object value) { |
158 Map<QName, String> attributes = new HashMap<>(1); |
163 |
159 if (value instanceof Number) { |
164 if (value instanceof Array) { |
160 attributes.put(qname("class"), "number"); |
165 Array sqlArray = (Array) value; |
161 } else if (value instanceof Boolean) { |
166 try { |
162 attributes.put(qname("class"), "boolean"); |
167 Object[] array = (Object[]) sqlArray.getArray(); |
163 } |
168 printStartElement(qname("td")); |
164 printTextElement(qname("td"), attributes, String.valueOf(value)); |
169 printArray(array); |
|
170 printEndElement(); |
|
171 } catch (SQLException e) { |
|
172 log.log(Level.SEVERE, "Unable to format array", e); |
|
173 printTableData(String.valueOf(value)); |
|
174 } |
|
175 } else { |
|
176 Map<QName, String> attributes = new HashMap<>(1); |
|
177 if (value instanceof Number) { |
|
178 attributes.put(qname("class"), "number"); |
|
179 } else if (value instanceof Boolean) { |
|
180 attributes.put(qname("class"), "boolean"); |
|
181 } |
|
182 printTextElement(qname("td"), attributes, String.valueOf(value)); |
|
183 } |
|
184 } |
|
185 |
|
186 private void printArray(Object[] array) { |
|
187 printStartElement(qname("ul")); |
|
188 for (Object o : array) { |
|
189 if (o instanceof Object[]) { |
|
190 printStartElement(qname("li")); |
|
191 printTextElement(qname("p"), null, "nested array:"); |
|
192 printArray((Object[]) o); |
|
193 printEndElement(); |
|
194 } else { |
|
195 printTextElement(qname("li"), null, String.valueOf(o)); |
|
196 } |
|
197 } |
|
198 printEndElement(); |
165 } |
199 } |
166 |
200 |
167 @Override |
201 @Override |
168 public void writeColumnsHeader(ColumnsHeader header) { |
202 public void writeColumnsHeader(ColumnsHeader header) { |
169 super.writeColumnsHeader(header); |
203 super.writeColumnsHeader(header); |