java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java
branchv_0
changeset 152 7a3382823fc3
parent 142 da1e38386d84
child 155 eb3676c6929b
equal deleted inserted replaced
151:21eb46c5e2ec 152:7a3382823fc3
    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;
    28 import java.sql.Array;
    29 import java.sql.SQLException;
    29 import java.sql.SQLException;
    30 import java.util.Date;
    30 import java.util.Date;
    31 import java.util.HashMap;
       
    32 import java.util.List;
    31 import java.util.List;
    33 import java.util.Map;
    32 import java.util.Map;
    34 import java.util.Scanner;
    33 import java.util.Scanner;
    35 import java.util.logging.Level;
    34 import java.util.logging.Level;
    36 import java.util.logging.Logger;
    35 import java.util.logging.Logger;
    67 	@Override
    66 	@Override
    68 	public void writeStartBatch() {
    67 	public void writeStartBatch() {
    69 		super.writeStartBatch();
    68 		super.writeStartBatch();
    70 		printStartDocument();
    69 		printStartDocument();
    71 		printDoctype(DOCTYPE);
    70 		printDoctype(DOCTYPE);
    72 		Map<QName, String> attributes = new HashMap<>(1);
    71 		printStartElement(qname("html"), singleAttribute(qname("xmlns"), Xmlns.XHTML));
    73 		attributes.put(qname("xmlns"), Xmlns.XHTML);
       
    74 		printStartElement(qname("html"), attributes);
       
    75 
    72 
    76 		printStartElement(qname("head"));
    73 		printStartElement(qname("head"));
    77 		printTextElement(qname("title"), null, Constants.PROGRAM_NAME + ": batch results");
    74 		printTextElement(qname("title"), null, Constants.PROGRAM_NAME + ": batch results");
    78 		printCss();
    75 		printCss();
    79 		printEndElement();
    76 		printEndElement();
    82 	}
    79 	}
    83 
    80 
    84 	private void printCss() {
    81 	private void printCss() {
    85 
    82 
    86 		try (Scanner css = new Scanner(getClass().getClassLoader().getResourceAsStream(CSS_FILE))) {
    83 		try (Scanner css = new Scanner(getClass().getClassLoader().getResourceAsStream(CSS_FILE))) {
    87 			Map<QName, String> attributes = new HashMap<>(1);
    84 			printStartElement(qname("style"), singleAttribute(qname("type"), "text/css"));
    88 			attributes.put(qname("type"), "text/css");
       
    89 			printStartElement(qname("style"), attributes);
       
    90 			while (css.hasNext()) {
    85 			while (css.hasNext()) {
    91 				printText(css.nextLine(), true);
    86 				printText(css.nextLine(), true);
    92 			}
    87 			}
    93 			printEndElement();
    88 			printEndElement();
    94 		}
    89 		}
   171 			} catch (SQLException e) {
   166 			} catch (SQLException e) {
   172 				log.log(Level.SEVERE, "Unable to format array", e);
   167 				log.log(Level.SEVERE, "Unable to format array", e);
   173 				printTableData(String.valueOf(value));
   168 				printTableData(String.valueOf(value));
   174 			}
   169 			}
   175 		} else {
   170 		} else {
   176 			Map<QName, String> attributes = new HashMap<>(1);
   171 			Map<QName, String> attributes = null;
   177 			if (value instanceof Number) {
   172 			if (value instanceof Number) {
   178 				attributes.put(qname("class"), "number");
   173 				attributes = singleAttribute(qname("class"), "number");
   179 			} else if (value instanceof Boolean) {
   174 			} else if (value instanceof Boolean) {
   180 				attributes.put(qname("class"), "boolean");
   175 				attributes = singleAttribute(qname("class"), "boolean");
   181 			}
   176 			}
   182 			printTextElement(qname("td"), attributes, String.valueOf(value));
   177 			printTextElement(qname("td"), attributes, String.valueOf(value));
   183 		}
   178 		}
   184 	}
   179 	}
   185 
   180