java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java
branchv_0
changeset 206 e2f24eea8543
parent 155 eb3676c6929b
child 207 2bba68ef47c1
equal deleted inserted replaced
205:d6624c3b146a 206:e2f24eea8543
    21 import info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor;
    21 import info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor;
    22 import java.util.Stack;
    22 import java.util.Stack;
    23 import javax.xml.namespace.QName;
    23 import javax.xml.namespace.QName;
    24 import static info.globalcode.sql.dk.Functions.isEmpty;
    24 import static info.globalcode.sql.dk.Functions.isEmpty;
    25 import static info.globalcode.sql.dk.Functions.toHex;
    25 import static info.globalcode.sql.dk.Functions.toHex;
       
    26 import info.globalcode.sql.dk.configuration.PropertyDeclaration;
       
    27 import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL;
       
    28 import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL_DESCRIPTION;
    26 import java.nio.charset.Charset;
    29 import java.nio.charset.Charset;
    27 import java.util.EmptyStackException;
    30 import java.util.EmptyStackException;
    28 import java.util.HashMap;
    31 import java.util.HashMap;
    29 import java.util.LinkedHashMap;
    32 import java.util.LinkedHashMap;
    30 import java.util.Map;
    33 import java.util.Map;
    42  * Must be used with care – bad usage can lead to invalid XML (e.g. using undeclared namespaces).
    45  * Must be used with care – bad usage can lead to invalid XML (e.g. using undeclared namespaces).
    43  * </p>
    46  * </p>
    44  *
    47  *
    45  * @author Ing. František Kučera (frantovo.cz)
    48  * @author Ing. František Kučera (frantovo.cz)
    46  */
    49  */
       
    50 @PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
       
    51 @PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT, type = String.class, description = "tab or sequence of spaces used for indentation of nested elements")
       
    52 @PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT_TEXT, type = Boolean.class, description = "whether to indent text nodes")
    47 public abstract class AbstractXmlFormatter extends AbstractFormatter {
    53 public abstract class AbstractXmlFormatter extends AbstractFormatter {
    48 
    54 
    49 	private static final Logger log = Logger.getLogger(AbstractXmlFormatter.class.getName());
    55 	private static final Logger log = Logger.getLogger(AbstractXmlFormatter.class.getName());
    50 	public static final String PROPERTY_COLORFUL = "color";
       
    51 	public static final String PROPERTY_INDENT = "indent";
    56 	public static final String PROPERTY_INDENT = "indent";
    52 	/**
    57 	/**
    53 	 * Whether text with line breaks should be indented (default). Otherwise original whitespace
    58 	 * Whether text with line breaks should be indented (default). Otherwise original whitespace
    54 	 * will be preserved.
    59 	 * will be preserved.
    55 	 */
    60 	 */
    64 	private final String indent;
    69 	private final String indent;
    65 	private final boolean indentText;
    70 	private final boolean indentText;
    66 
    71 
    67 	public AbstractXmlFormatter(FormatterContext formatterContext) {
    72 	public AbstractXmlFormatter(FormatterContext formatterContext) {
    68 		super(formatterContext);
    73 		super(formatterContext);
    69 		boolean colorful = formatterContext.getProperties().getBoolean(PROPERTY_COLORFUL, false);
    74 		boolean colorful = formatterContext.getProperties().getBoolean(COLORFUL, false);
    70 		out = new ColorfulPrintWriter(formatterContext.getOutputStream(), false, colorful);
    75 		out = new ColorfulPrintWriter(formatterContext.getOutputStream(), false, colorful);
    71 		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, "\t");
    76 		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, "\t");
    72 		indentText = formatterContext.getProperties().getBoolean(PROPERTY_INDENT_TEXT, true);
    77 		indentText = formatterContext.getProperties().getBoolean(PROPERTY_INDENT_TEXT, true);
    73 
    78 
    74 		if (!indent.matches("\\s*")) {
    79 		if (!indent.matches("\\s*")) {