XHTML formatter: CSS and other improvements v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 04 Jan 2014 23:27:17 +0100
branchv_0
changeset 135ef432015fdee
parent 134 f2510551b5bf
child 136 c0f9521900bf
XHTML formatter: CSS and other improvements
java/sql-dk/data/info/globalcode/sql/dk/formatter/XhtmlFormatter.css
java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/sql-dk/data/info/globalcode/sql/dk/formatter/XhtmlFormatter.css	Sat Jan 04 23:27:17 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +body {
     1.5 +	font-family: sans-serif;
     1.6 +	font-size: 16px;
     1.7 +	padding-left: 16px;
     1.8 +}
     1.9 +
    1.10 +pre {
    1.11 +	background-color: #ddd;
    1.12 +	padding: 6px;
    1.13 +	border-radius: 4px;
    1.14 +	overflow: auto;
    1.15 +
    1.16 +	-moz-tab-size: 4;
    1.17 +	-o-tab-size: 4;
    1.18 +	tab-size: 4;
    1.19 +}
    1.20 +
    1.21 +table {
    1.22 +	border-collapse:collapse;
    1.23 +	box-shadow: 3px 3px 3px grey;
    1.24 +	margin-top: 10px;
    1.25 +	margin-bottom: 20px;
    1.26 +}
    1.27 +td, th {
    1.28 +	border: 1px solid black;
    1.29 +	padding-top: 4px;
    1.30 +	padding-bottom: 4px;
    1.31 +	padding-left: 6px;
    1.32 +	padding-right: 6px;
    1.33 +	font-weight: normal;
    1.34 +}
    1.35 +td.number {
    1.36 +	text-align: right;
    1.37 +}
    1.38 +thead tr {
    1.39 +	background: #ddd;
    1.40 +	color:black;
    1.41 +}
    1.42 +tbody tr:hover {
    1.43 +	background-color: #eee;
    1.44 +	color:black;
    1.45 +}
    1.46 \ No newline at end of file
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java	Sat Jan 04 22:38:59 2014 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java	Sat Jan 04 23:27:17 2014 +0100
     2.3 @@ -25,9 +25,11 @@
     2.4  import info.globalcode.sql.dk.configuration.Properties;
     2.5  import info.globalcode.sql.dk.configuration.Property;
     2.6  import static info.globalcode.sql.dk.formatting.AbstractXmlFormatter.qname;
     2.7 +import java.util.Date;
     2.8  import java.util.HashMap;
     2.9  import java.util.List;
    2.10  import java.util.Map;
    2.11 +import java.util.Scanner;
    2.12  import javax.xml.namespace.QName;
    2.13  
    2.14  /**
    2.15 @@ -37,6 +39,7 @@
    2.16  public class XhtmlFormatter extends AbstractXmlFormatter {
    2.17  
    2.18  	public static final String NAME = "xhtml"; // bash-completion:formatter
    2.19 +	private static final String CSS_FILE = "info/globalcode/sql/dk/formatter/XhtmlFormatter.css";
    2.20  	private int resultSetCounter = 0;
    2.21  	private int updatesResultCounter = 0;
    2.22  
    2.23 @@ -64,11 +67,25 @@
    2.24  
    2.25  		printStartElement(qname("head"));
    2.26  		printTextElement(qname("title"), null, Constants.PROGRAM_NAME + ": batch results");
    2.27 +		printCss();
    2.28  		printEndElement();
    2.29  
    2.30  		printStartElement(qname("body"));
    2.31  	}
    2.32  
    2.33 +	private void printCss() {
    2.34 +
    2.35 +		try (Scanner css = new Scanner(getClass().getClassLoader().getResourceAsStream(CSS_FILE))) {
    2.36 +			Map<QName, String> attributes = new HashMap<>(1);
    2.37 +			attributes.put(qname("type"), "text/css");
    2.38 +			printStartElement(qname("style"), attributes);
    2.39 +			while (css.hasNext()) {
    2.40 +				printText(css.nextLine(), true);
    2.41 +			}
    2.42 +			printEndElement();
    2.43 +		}
    2.44 +	}
    2.45 +
    2.46  	@Override
    2.47  	public void writeEndBatch() {
    2.48  		super.writeEndBatch();
    2.49 @@ -81,6 +98,11 @@
    2.50  	public void writeStartDatabase(DatabaseDefinition databaseDefinition) {
    2.51  		super.writeStartDatabase(databaseDefinition);
    2.52  		printTextElement(qname("h1"), null, "Database: " + databaseDefinition.getName());
    2.53 +
    2.54 +		printStartElement(qname("p"));
    2.55 +		printText("This is XHTML output of batch executed at: ", true);
    2.56 +		printText(new Date().toString(), true);
    2.57 +		printEndElement();
    2.58  	}
    2.59  
    2.60  	@Override
    2.61 @@ -101,9 +123,9 @@
    2.62  
    2.63  			printStartElement(qname("table"));
    2.64  
    2.65 -			printStartElement(qname("theader"));
    2.66 +			printStartElement(qname("thead"));
    2.67  			printStartElement(qname("tr"));
    2.68 -			printTextElement(qname("td"), null, "number/name");
    2.69 +			printTextElement(qname("td"), null, "id");
    2.70  			printTextElement(qname("td"), null, "type");
    2.71  			printTextElement(qname("td"), null, "value");
    2.72  			printEndElement();
    2.73 @@ -121,7 +143,7 @@
    2.74  				}
    2.75  				printTextElement(qname("td"), null, numberOrName);
    2.76  				printTextElement(qname("td"), null, p.getType().name());
    2.77 -				printTextElement(qname("td"), null, toString(p.getValue()));
    2.78 +				printTableData(p.getValue());
    2.79  				printEndElement();
    2.80  			}
    2.81  			printEndElement();
    2.82 @@ -130,12 +152,20 @@
    2.83  		}
    2.84  	}
    2.85  
    2.86 +	private void printTableData(Object value) {
    2.87 +		Map<QName, String> attributes = new HashMap<>(1);
    2.88 +		if (value instanceof Number || value instanceof Boolean) {
    2.89 +			attributes.put(qname("class"), "number");
    2.90 +		}
    2.91 +		printTextElement(qname("td"), attributes, String.valueOf(value));
    2.92 +	}
    2.93 +
    2.94  	@Override
    2.95  	public void writeColumnsHeader(ColumnsHeader header) {
    2.96  		super.writeColumnsHeader(header);
    2.97  		printTextElement(qname("h3"), null, "Data:");
    2.98  		printStartElement(qname("table"));
    2.99 -		printStartElement(qname("theader"));
   2.100 +		printStartElement(qname("thead"));
   2.101  		printStartElement(qname("tr"));
   2.102  		for (ColumnDescriptor cd : header.getColumnDescriptors()) {
   2.103  			// TODO: type
   2.104 @@ -156,7 +186,7 @@
   2.105  	@Override
   2.106  	public void writeColumnValue(Object value) {
   2.107  		super.writeColumnValue(value);
   2.108 -		printTextElement(qname("td"), null, toString(value));
   2.109 +		printTableData(value);
   2.110  	}
   2.111  
   2.112  	@Override
   2.113 @@ -169,7 +199,8 @@
   2.114  	public void writeStartResultSet() {
   2.115  		super.writeStartResultSet();
   2.116  		resultSetCounter++;
   2.117 -		printTextElement(qname("h2"), null, "Result set " + resultSetCounter);
   2.118 +		printEmptyElement(qname("hr"), null);
   2.119 +		printTextElement(qname("h2"), null, "Result set #" + resultSetCounter);
   2.120  	}
   2.121  
   2.122  	@Override
   2.123 @@ -177,13 +208,16 @@
   2.124  		super.writeEndResultSet();
   2.125  		printEndElement();
   2.126  		printEndElement();
   2.127 +
   2.128 +		printTextElement(qname("p"), null, "Record count: " + getCurrentRowCount());
   2.129  	}
   2.130  
   2.131  	@Override
   2.132  	public void writeStartUpdatesResult() {
   2.133  		super.writeStartUpdatesResult();
   2.134  		updatesResultCounter++;
   2.135 -		printTextElement(qname("h2"), null, "Updates result " + updatesResultCounter);
   2.136 +		printEmptyElement(qname("hr"), null);
   2.137 +		printTextElement(qname("h2"), null, "Updates result #" + updatesResultCounter);
   2.138  	}
   2.139  
   2.140  	@Override
   2.141 @@ -191,8 +225,4 @@
   2.142  		super.writeUpdatedRowsCount(updatedRowsCount);
   2.143  		printTextElement(qname("p"), null, "Updated rows: " + updatedRowsCount);
   2.144  	}
   2.145 -
   2.146 -	protected String toString(Object value) {
   2.147 -		return String.valueOf(value);
   2.148 -	}
   2.149  }