Class XMLTools

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

    public class XMLTools
    extends org.dom4j.io.XMLWriter
    • Field Summary

      • Fields inherited from class org.dom4j.io.XMLWriter

        DEFAULT_FORMAT, lastOutputNodeType, LEXICAL_HANDLER_NAMES, preserve, writer
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLTools()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encodeXML​(java.lang.CharSequence s)
      relplaces some entities like < , > and & with their escaped pendant like &lt;
      java.lang.String escapeAttributeEntities​(java.lang.String s)  
      java.lang.String escapeElementEntities​(java.lang.String s)  
      static byte[] getBytesFromStream​(java.io.InputStream fileinput)  
      static java.lang.String getNodeValue​(org.w3c.dom.Node node)
      returns the value of an node
      static java.lang.String nDigitFormat​(java.math.BigDecimal value, int scale)  
      static java.lang.String nDigitFormatDecimalRange​(java.math.BigDecimal value, int maxDecimals, int minDecimals)
      formats a number so that at least minDecimals are displayed but at the maximum maxDecimals are there, i.e.
      static byte[] removeBOM​(byte[] zugferdRaw)
      removes utf8 byte order marks from byte arrays, in case one is there
      static java.lang.String trimOrNull​(org.w3c.dom.Node node)  
      static java.math.BigDecimal tryBigDecimal​(java.lang.String nodeValue)
      tries to convert a String to BigDecimal.
      static java.math.BigDecimal tryBigDecimal​(org.w3c.dom.Node node)
      tries to convert a Node to a BigDecimal.
      static java.util.Date tryDate​(java.lang.String toParse)
      returns a util.Date from a 102 String yyyymmdd
      static java.util.Date tryDate​(org.w3c.dom.Node node)
      returns a util.Date from a 102 String yyyymmdd in a node
      • Methods inherited from class org.dom4j.io.XMLWriter

        characters, close, comment, createWriter, defaultMaximumAllowedCharacter, endCDATA, endDocument, endDTD, endElement, endEntity, endPrefixMapping, flush, getLexicalHandler, getMaximumAllowedCharacter, getOutputFormat, getProperty, handleException, ignorableWhitespace, indent, installLexicalHandler, isElementSpacePreserved, isEscapeText, isExpandEmptyElements, isNamespaceDeclaration, notationDecl, parse, println, processingInstruction, resolveEntityRefs, setDocumentLocator, setEscapeText, setIndentLevel, setLexicalHandler, setMaximumAllowedCharacter, setOutputStream, setProperty, setResolveEntityRefs, setWriter, shouldEncodeChar, startCDATA, startDocument, startDTD, startElement, startEntity, startPrefixMapping, unparsedEntityDecl, write, write, write, write, write, write, write, write, write, write, write, write, write, writeAttribute, writeAttribute, writeAttribute, writeAttributes, writeAttributes, writeCDATA, writeClose, writeClose, writeComment, writeDeclaration, writeDocType, writeDocType, writeElement, writeElementContent, writeEmptyElementClose, writeEntity, writeEntityRef, writeEscapeAttributeEntities, writeNamespace, writeNamespace, writeNamespaces, writeNamespaces, writeNode, writeNodeText, writeOpen, writePrintln, writeProcessingInstruction, writeString
      • Methods inherited from class org.xml.sax.helpers.XMLFilterImpl

        error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, skippedEntity, warning
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XMLTools

        public XMLTools()
    • Method Detail

      • escapeAttributeEntities

        public java.lang.String escapeAttributeEntities​(java.lang.String s)
        Overrides:
        escapeAttributeEntities in class org.dom4j.io.XMLWriter
      • escapeElementEntities

        public java.lang.String escapeElementEntities​(java.lang.String s)
        Overrides:
        escapeElementEntities in class org.dom4j.io.XMLWriter
      • nDigitFormat

        public static java.lang.String nDigitFormat​(java.math.BigDecimal value,
                                                    int scale)
      • getNodeValue

        public static java.lang.String getNodeValue​(org.w3c.dom.Node node)
        returns the value of an node
        Parameters:
        node - the Node to get the value from
        Returns:
        A String or empty String, if no value was found
      • tryBigDecimal

        public static java.math.BigDecimal tryBigDecimal​(java.lang.String nodeValue)
        tries to convert a String to BigDecimal.
        Parameters:
        nodeValue - The value as String
        Returns:
        a BigDecimal with the value provides as String or a BigDecimal with value 0.00 if an error occurs
      • tryBigDecimal

        public static java.math.BigDecimal tryBigDecimal​(org.w3c.dom.Node node)
        tries to convert a Node to a BigDecimal.
        Parameters:
        node - The value as String
        Returns:
        a BigDecimal with the value provides as String or a BigDecimal with value 0.00 if an error occurs
      • nDigitFormatDecimalRange

        public static java.lang.String nDigitFormatDecimalRange​(java.math.BigDecimal value,
                                                                int maxDecimals,
                                                                int minDecimals)
        formats a number so that at least minDecimals are displayed but at the maximum maxDecimals are there, i.e. cuts potential 0s off the end until minDecimals
        Parameters:
        value - the value to be formatted
        maxDecimals - number of maximal scale
        minDecimals - number of minimal scale
        Returns:
        value as String with decimals in the specified range
      • tryDate

        public static java.util.Date tryDate​(org.w3c.dom.Node node)
        returns a util.Date from a 102 String yyyymmdd in a node
        Parameters:
        node - the node
        Returns:
        a util.Date, or null, if not parseable
      • tryDate

        public static java.util.Date tryDate​(java.lang.String toParse)
        returns a util.Date from a 102 String yyyymmdd
        Parameters:
        toParse - the string
        Returns:
        a util.Date, or null, if not parseable
      • encodeXML

        public static java.lang.String encodeXML​(java.lang.CharSequence s)
        relplaces some entities like < , > and & with their escaped pendant like &lt;
        Parameters:
        s - the string
        Returns:
        the "safe" string
      • removeBOM

        public static byte[] removeBOM​(byte[] zugferdRaw)
        removes utf8 byte order marks from byte arrays, in case one is there
        Parameters:
        zugferdRaw - the CII XML
        Returns:
        the byte array without bom
      • getBytesFromStream

        public static byte[] getBytesFromStream​(java.io.InputStream fileinput)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • trimOrNull

        public static java.lang.String trimOrNull​(org.w3c.dom.Node node)