Package org.codice.ddf.platform.util
Class XMLUtils
java.lang.Object
org.codice.ddf.platform.util.XMLUtils
Utility for handling XML
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class is used with the processElements method. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat(Source sourceXml, TransformerProperties transformProperties) Formats XML into a Stringformat(Node nodeXml, TransformerProperties transformerProperties) static XMLUtilsgetRootNamespace(String xml) getSecureDocumentBuilder(boolean namespaceAware) getSecureDocumentBuilderFactory(String className, ClassLoader classLoader) getSecureSAXParser(boolean namespaceAware) getSecureSAXParserFactory(String className, ClassLoader classLoader) getSecureXmlParser(String className) getSecureXmlTransformerFactory(String className, ClassLoader classLoader) getXmlTransformer(boolean omitXml) parseDocument(InputStream inputStream, boolean namespaceAware) prettyFormat(Source sourceXml) Nicely formats XML into a StringprettyFormat(Node nodeXml) Nicely formats XML into a String<T> TprocessElements(String xml, BiFunction<XMLUtils.ResultHolder<T>, XMLStreamReader, Boolean> processElementFunction) Iterate through the elements of an XML document.transform(Source sourceXml, TransformerProperties transformProperties, Result result) Transforms XML into a Resulttransform(Node nodeXml, TransformerProperties transformerProperties, Result result)
-
Field Details
-
xmlInputFactory
-
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
getInstance
-
format
Formats XML into a String- Parameters:
sourceXml- to transform a given SourcetransformProperties- settings for transformer- Returns:
- XML string
-
format
- Parameters:
nodeXml- to transform a given NodetransformerProperties- settings for transformer- Returns:
- XML String
-
prettyFormat
Nicely formats XML into a String- Parameters:
sourceXml- to transform a given Source- Returns:
- XML string
-
prettyFormat
Nicely formats XML into a String- Parameters:
nodeXml- to transform a given Node- Returns:
- XML string
-
transform
Transforms XML into a Result- Parameters:
sourceXml- to transform a given SourcetransformProperties- settings for transformerresult- Result to transform into- Returns:
- XML Result
-
transform
- Parameters:
nodeXml- to transform a given NodetransformerProperties- settings for transformerresult- Result to transform into- Returns:
- XML Result
-
getRootNamespace
- Parameters:
xml- The XML whose root namespace you want- Returns:
- Root Namespace
-
processElements
public <T> T processElements(String xml, BiFunction<XMLUtils.ResultHolder<T>, XMLStreamReader, Boolean> processElementFunction) Iterate through the elements of an XML document. The processor calls the processElementFunction for each element. Call result.set() to change the value that will be returned.If the function returns true, processing continues to the next element. When the last element in the document is processed, the value in the result is returned.
If the lambda function returns false, processing stops. The value of the result is returned.
If the function encounters a processing exception, processing stops and null is returned.
- Parameters:
xml- The XML to processprocessElementFunction- Function that accepts an instance of XMLStreamReader and result holder. The function must return a boolean.- Returns:
The result of the processing
-
getSecureXmlInputFactory
-
getSecureDocumentBuilderFactory
public DocumentBuilderFactory getSecureDocumentBuilderFactory(String className, ClassLoader classLoader) -
getSecureDocumentBuilderFactory
-
getSecureDocumentBuilder
public DocumentBuilder getSecureDocumentBuilder(boolean namespaceAware) throws ParserConfigurationException - Throws:
ParserConfigurationException
-
parseDocument
public Document parseDocument(InputStream inputStream, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException -
getSecureXmlTransformerFactory
-
getSecureXmlTransformerFactory
-
getXmlTransformer
- Throws:
TransformerException
-
getSecureSAXParserFactory
-
getSecureSAXParserFactory
-
getSecureSAXParser
public SAXParser getSecureSAXParser(boolean namespaceAware) throws ParserConfigurationException, SAXException -
getSecureXmlParser
- Throws:
SAXException
-
getSecureXmlParser
- Throws:
SAXException
-