Package org.europa.together.application
Class SaxTools
- java.lang.Object
-
- org.europa.together.application.SaxTools
-
- All Implemented Interfaces:
XmlTools
@Repository @FeatureToggle(featureID="CM-0010") public class SaxTools extends Object implements XmlTools
Implementation of useful XML Tools.
-
-
Field Summary
-
Fields inherited from interface org.europa.together.business.XmlTools
FEATURE_ID
-
-
Constructor Summary
Constructors Constructor Description SaxTools()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasExternalSchemaFile()
Check if a external Schema File s configured.boolean
isValid()
Validate well formed XML content (XML 1.0) against a given grammar.boolean
isWellFormed()
Check XML Content (XML 1.0) if is well formed.String
parseXmlFile(File xmlFile)
Parse a given XML File to grab the content.String
parseXmlString(String xml)
Parse a given XML String to grab the content.String
prettyPrintXml()
Before you write a XML Document on a file, especially computer generated XML Content, the content should formatted by a CodeBeautifier.void
resetExternalSchema()
Reset the external Schema File to NULL.void
setSchemaFile(File schema)
Set explicit the schema file for the validation option.String
shrinkContent(String content)
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.String
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.
-
-
-
Method Detail
-
parseXmlFile
public String parseXmlFile(File xmlFile)
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
public String parseXmlString(String xml)
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
public String prettyPrintXml()
Description copied from interface:XmlTools
Before you write 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
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 interfaceXmlTools
- 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 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
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 interfaceXmlTools
- Parameters:
schema
- as File
-
writeXmlToFile
public void writeXmlToFile(String content, String destinationFile)
Description copied from interface:XmlTools
Writes a XML String into a new File.- Specified by:
writeXmlToFile
in interfaceXmlTools
- Parameters:
content
- as stringdestinationFile
- as String
-
-