Package org.europa.together.application
Class SaxTools
java.lang.Object
org.europa.together.application.SaxTools
- All Implemented Interfaces:
XmlTools
Implementation of XML Tools.
-
Field Summary
Fields inherited from interface org.europa.together.business.XmlTools
FEATURE_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Check if a external schema file s configured.boolean
isValid()
Validate well formed XML content (XML 1.0) against a given grammar.boolean
Check XML content (XML 1.0) if is well formed.parseXmlFile
(File xmlFile) Parse a given XML File to grab the content.parseXmlString
(String xml) 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
setSchemaFile
(File schema) Set explicit the schema file for the validation option.shrinkContent
(String content) 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.
-
Constructor Details
-
SaxTools
public SaxTools()Constructor.
-
-
Method Details
-
parseXmlFile
Description copied from interface:XmlTools
Parse a given XML File to grab the content.- Specified by:
parseXmlFile
in interfaceXmlTools
- Parameters:
xmlFile
- as File- Returns:
- content as String
-
parseXmlString
Description copied from interface:XmlTools
Parse a given XML String to grab the content.- Specified by:
parseXmlString
in interfaceXmlTools
- Parameters:
xml
- as String- Returns:
- content as 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 interfaceXmlTools
- Returns:
- content as String
-
shrinkContent
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 interfaceXmlTools
- Parameters:
content
- as String- Returns:
- shrink content as String
-
transformXslt
Description copied from interface:XmlTools
Transform an XML File by a given XSLT to a new Output.- Specified by:
transformXslt
in interfaceXmlTools
- Parameters:
xml
- as Filexslt
- 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 interfaceXmlTools
- 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. -
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 interfaceXmlTools
- Returns:
- true on success
-
resetExternalSchema
public void resetExternalSchema()Description copied from interface:XmlTools
Reset the external schema file to NULL.- Specified by:
resetExternalSchema
in interfaceXmlTools
-
setSchemaFile
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 interfaceXmlTools
- Parameters:
schema
- as File
-
writeXmlToFile
Description copied from interface:XmlTools
Writes a XML String into a new file.- Specified by:
writeXmlToFile
in interfaceXmlTools
- Parameters:
content
- as stringdestinationFile
- as String- Throws:
IOException
-