Class NumberTagWriter


  • public class NumberTagWriter
    extends SimpleTagWriter
    Basic tag writer for Number objects. Optionally it allows to pass a own number format string.
    • Constructor Detail

      • NumberTagWriter

        public NumberTagWriter​(XMLTagWriter parent,
                               java.lang.String tagName)
        Creates a new optional number tag writer.
        Parameters:
        parent - the parent tag writer
        tagName - the tag name
      • NumberTagWriter

        public NumberTagWriter​(XMLTagWriter parent,
                               java.lang.String tagName,
                               boolean mandatory)
        Creates a new number tag writer.
        Parameters:
        parent - the parent tag writer
        tagName - the tag name
        mandatory - tells whether or not the tag requires a non-null value
    • Method Detail

      • setFormat

        public void setFormat​(java.lang.String pattern)
                       throws java.lang.IllegalStateException
        Configures this tag writer by setting a DecimalFormat format pattern string.

        Be sure to call this prior to writing any object.

        Parameters:
        pattern - the decimal format pattern
        Throws:
        java.lang.IllegalStateException - if the tag has already begun to write any object
      • createNumberFormat

        protected java.text.NumberFormat createNumberFormat()
        Creates this tag's number format once. Use setFormat(String) to define a own format. Otherwise this method will return the format specified by NumberFormat.getNumberInstance().
      • getNumberFormat

        protected final java.text.NumberFormat getNumberFormat()
      • writeContent

        protected void writeContent​(org.znerd.xmlenc.XMLOutputter xmlOut,
                                    java.lang.Object object)
                             throws java.io.IOException
        Description copied from class: SimpleTagWriter
        Outputs the given objects by calling its Object.toString() method.
        Overrides:
        writeContent in class SimpleTagWriter
        Parameters:
        xmlOut - the XMLOutputter to write to
        object - the data object provided by the parent tag writer, may be null
        Throws:
        java.io.IOException