property annotations: default values v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 10:34:18 +0200
branchv_0
changeset 2072bba68ef47c1
parent 206 e2f24eea8543
child 208 1a511d321ade
property annotations: default values
java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java	Sat Aug 15 10:20:39 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java	Sat Aug 15 10:34:18 2015 +0200
     1.3 @@ -24,6 +24,9 @@
     1.4  import java.lang.annotation.Target;
     1.5  
     1.6  /**
     1.7 + * Declaration of the (formatter) properties – for documentation purposes.
     1.8 + *
     1.9 + * TODO: automatically inject properties (configured, ad-hoc, default ones) to the formatters
    1.10   *
    1.11   * @author Ing. František Kučera (frantovo.cz)
    1.12   */
    1.13 @@ -46,4 +49,9 @@
    1.14  	 * @return documentation for the users
    1.15  	 */
    1.16  	String description();
    1.17 +
    1.18 +	/**
    1.19 +	 * @return default value of this property
    1.20 +	 */
    1.21 +	String defaultValue();
    1.22  }
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java	Sat Aug 15 10:20:39 2015 +0200
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java	Sat Aug 15 10:34:18 2015 +0200
     2.3 @@ -47,17 +47,14 @@
     2.4   *
     2.5   * @author Ing. František Kučera (frantovo.cz)
     2.6   */
     2.7 -@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
     2.8 -@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT, type = String.class, description = "tab or sequence of spaces used for indentation of nested elements")
     2.9 -@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT_TEXT, type = Boolean.class, description = "whether to indent text nodes")
    2.10 +@PropertyDeclaration(name = COLORFUL, defaultValue = "false", type = Boolean.class, description = COLORFUL_DESCRIPTION)
    2.11 +@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT, defaultValue = AbstractXmlFormatter.PROPERTY_INDENT_DEFAULT, type = String.class, description = "tab or sequence of spaces used for indentation of nested elements")
    2.12 +@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT_TEXT, defaultValue = "true", type = Boolean.class, description = "whether text with line breaks should be indented; if not original whitespace will be preserved.")
    2.13  public abstract class AbstractXmlFormatter extends AbstractFormatter {
    2.14  
    2.15  	private static final Logger log = Logger.getLogger(AbstractXmlFormatter.class.getName());
    2.16  	public static final String PROPERTY_INDENT = "indent";
    2.17 -	/**
    2.18 -	 * Whether text with line breaks should be indented (default). Otherwise original whitespace
    2.19 -	 * will be preserved.
    2.20 -	 */
    2.21 +	protected static final String PROPERTY_INDENT_DEFAULT = "\t";
    2.22  	public static final String PROPERTY_INDENT_TEXT = "indentText";
    2.23  	private static final TerminalColor ELEMENT_COLOR = TerminalColor.Magenta;
    2.24  	private static final TerminalColor ATTRIBUTE_NAME_COLOR = TerminalColor.Green;
    2.25 @@ -73,7 +70,7 @@
    2.26  		super(formatterContext);
    2.27  		boolean colorful = formatterContext.getProperties().getBoolean(COLORFUL, false);
    2.28  		out = new ColorfulPrintWriter(formatterContext.getOutputStream(), false, colorful);
    2.29 -		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, "\t");
    2.30 +		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, PROPERTY_INDENT_DEFAULT);
    2.31  		indentText = formatterContext.getProperties().getBoolean(PROPERTY_INDENT_TEXT, true);
    2.32  
    2.33  		if (!indent.matches("\\s*")) {
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java	Sat Aug 15 10:20:39 2015 +0200
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java	Sat Aug 15 10:34:18 2015 +0200
     3.3 @@ -28,7 +28,7 @@
     3.4   *
     3.5   * @author Ing. František Kučera (frantovo.cz)
     3.6   */
     3.7 -@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
     3.8 +@PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION)
     3.9  public class SingleRecordFormatter extends AbstractFormatter {
    3.10  
    3.11  	public static final String NAME = "record"; // bash-completion:formatter
     4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sat Aug 15 10:20:39 2015 +0200
     4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sat Aug 15 10:34:18 2015 +0200
     4.3 @@ -43,9 +43,9 @@
     4.4   * @see TabularPrefetchingFormatter
     4.5   * @see TabularWrappingFormatter
     4.6   */
     4.7 -@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
     4.8 -@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones")
     4.9 -@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, type = Boolean.class, description = "whether to trim the values to fit the column width")
    4.10 +@PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION)
    4.11 +@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, defaultValue = "false", type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones")
    4.12 +@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, defaultValue = "false", type = Boolean.class, description = "whether to trim the values to fit the column width")
    4.13  public class TabularFormatter extends AbstractFormatter {
    4.14  
    4.15  	public static final String NAME = "tabular"; // bash-completion:formatter
     5.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java	Sat Aug 15 10:20:39 2015 +0200
     5.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java	Sat Aug 15 10:34:18 2015 +0200
     5.3 @@ -32,7 +32,7 @@
     5.4   *
     5.5   * @author Ing. František Kučera (frantovo.cz)
     5.6   */
     5.7 -@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
     5.8 +@PropertyDeclaration(name = COLORFUL, defaultValue = "false", type = Boolean.class, description = COLORFUL_DESCRIPTION)
     5.9  public class TeXFormatter extends AbstractFormatter {
    5.10  
    5.11  	public static final String NAME = "tex"; // bash-completion:formatter
     6.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Sat Aug 15 10:20:39 2015 +0200
     6.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Sat Aug 15 10:34:18 2015 +0200
     6.3 @@ -43,7 +43,7 @@
     6.4   *
     6.5   * @author Ing. František Kučera (frantovo.cz)
     6.6   */
     6.7 -@PropertyDeclaration(name = XmlFormatter.PROPERTY_LABELED_COLUMNS, type = Boolean.class, description = "whether to add 'label' attribute to each 'column' element")
     6.8 +@PropertyDeclaration(name = XmlFormatter.PROPERTY_LABELED_COLUMNS, defaultValue = "false", type = Boolean.class, description = "whether to add 'label' attribute to each 'column' element")
     6.9  public class XmlFormatter extends AbstractXmlFormatter {
    6.10  
    6.11  	public static final String NAME = "xml"; // bash-completion:formatter