Class SaxTools

java.lang.Object
org.europa.together.application.SaxTools
All Implemented Interfaces:
XmlTools

@Repository public class SaxTools extends Object implements XmlTools
Implementation of XML Tools.
  • Field Summary

    Fields inherited from interface org.europa.together.business.XmlTools

    FEATURE_ID
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if a external schema file s configured.
    boolean
    Validate well formed XML content (XML 1.0) against a given grammar.
    boolean
    Check XML content (XML 1.0) if is well formed. the well formed rules for XML are defined as:
    - the structure of a XML document is a tree and each node is defined as TAG
    - each document contains exact one root tag
    - element tags are case-sensitive
    - content be delimited with a beginning and end tag
    - begin, end, and empty-element tags that delimit the elements are
    correctly nested, with none missing and none overlapping Detail
    - it contains only properly encoded legal Unicode characters
    - special characters like: > < & have to be encoded
    (StringUtils.escapeXmlCharacters()) Information: https://en.wikipedia.org/wiki/Well-formed_document
    parseXmlFile(File xmlFile)
    Parse a given XML File to grab the content.
    Parse a given XML String to grab the content.
    Before writeing a XML Document on a file, especially computer generated XML Content, the content should formatted by a CodeBeautifier.
    void
    Reset the external schema file to NULL.
    void
    Set explicit the schema file for the validation option.
    Shrink the XML content to reduce the file size for a higher performance in automated processing.
    transformXslt(File xml, File xslt)
    Transform an XML File by a given XSLT to a new Output.
    void
    writeXmlToFile(String content, String destinationFile)
    Writes a XML String into a new file.

    Methods inherited from class java.lang.Object

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

    • SaxTools

      public SaxTools()
      Constructor.
  • Method Details

    • parseXmlFile

      public String parseXmlFile(File xmlFile)
      Description copied from interface: XmlTools
      Parse a given XML File to grab the content.
      Specified by:
      parseXmlFile in interface XmlTools
      Parameters:
      xmlFile - as File
      Returns:
      content as String
    • parseXmlString

      public String parseXmlString(String xml)
      Description copied from interface: XmlTools
      Parse a given XML String to grab the content.
      Specified by:
      parseXmlString in interface XmlTools
      Parameters:
      xml - as String
      Returns:
      content as String
    • prettyPrintXml

      public String prettyPrintXml()
      Description copied from interface: XmlTools
      Before writeing a XML Document on a file, especially computer generated XML Content, the content should formatted by a CodeBeautifier. This function Beautifies the XML Sources with the following rules:
      - set content to UTF-8 without BOM (Byte Order Mark)
      - automated line breaks and indents
      - remove trailing space
      - replace TAB with 4 space characters
      Specified by:
      prettyPrintXml in interface XmlTools
      Returns:
      content as String
    • shrinkContent

      public String shrinkContent(String content)
      Description copied from interface: XmlTools
      Shrink the XML content to reduce the file size for a higher performance in automated processing. The following option will be executed: - remove XML comments
      - remove whitespace
      - remove linebreak
      The final result is an XML in one row without comments and whitespace in one line. input and output is not parsed or checked for well formed.
      Specified by:
      shrinkContent in interface XmlTools
      Parameters:
      content - as String
      Returns:
      shrink content as String
    • transformXslt

      public String transformXslt(File xml, File xslt)
      Description copied from interface: XmlTools
      Transform an XML File by a given XSLT to a new Output.
      Specified by:
      transformXslt in interface XmlTools
      Parameters:
      xml - as File
      xslt - as File
      Returns:
      transformation as String
    • hasExternalSchemaFile

      public boolean hasExternalSchemaFile()
      Description copied from interface: XmlTools
      Check if a external schema file s configured.
      Specified by:
      hasExternalSchemaFile in interface XmlTools
      Returns:
      true on success
    • isValid

      public boolean isValid()
      Description copied from interface: XmlTools
      Validate well formed XML content (XML 1.0) against a given grammar. Grammar files can be DTD or XML Schema. THe validation contains also a well formed test for the XML file.
      Specified by:
      isValid in interface XmlTools
      Returns:
      true on success
    • isWellFormed

      public boolean isWellFormed()
      Description copied from interface: XmlTools
      Check XML content (XML 1.0) if is well formed. the well formed rules for XML are defined as:
      - the structure of a XML document is a tree and each node is defined as TAG
      - each document contains exact one root tag
      - element tags are case-sensitive
      - content be delimited with a beginning and end tag
      - begin, end, and empty-element tags that delimit the elements are
      correctly nested, with none missing and none overlapping Detail
      - it contains only properly encoded legal Unicode characters
      - special characters like: > < & have to be encoded
      (StringUtils.escapeXmlCharacters()) Information: https://en.wikipedia.org/wiki/Well-formed_document
      Specified by:
      isWellFormed in interface XmlTools
      Returns:
      true on success
    • resetExternalSchema

      public void resetExternalSchema()
      Description copied from interface: XmlTools
      Reset the external schema file to NULL.
      Specified by:
      resetExternalSchema in interface XmlTools
    • setSchemaFile

      public void setSchemaFile(File schema)
      Description copied from interface: XmlTools
      Set explicit the schema file for the validation option. This method overwrites in the XML document declares Schemata.
      Specified by:
      setSchemaFile in interface XmlTools
      Parameters:
      schema - as File
    • writeXmlToFile

      public void writeXmlToFile(String content, String destinationFile) throws IOException
      Description copied from interface: XmlTools
      Writes a XML String into a new file.
      Specified by:
      writeXmlToFile in interface XmlTools
      Parameters:
      content - as string
      destinationFile - as String
      Throws:
      IOException