Package com.axelor.common
Class XMLUtils
- java.lang.Object
-
- com.axelor.common.XMLUtils
-
-
Constructor Summary
Constructors Constructor Description XMLUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DocumentBuilder
createDocumentBuilder()
Returns properly configuredDocumentBuilder
with security features.static DocumentBuilderFactory
createDocumentBuilderFactory(Boolean namespaceAware)
Returns properly configuredDocumentBuilderFactory
with security features and no external DTD and schema access.static SAXParser
createSAXParser()
Returns properly configuredSAXParser
with security features and no external DTD and schema access.static SAXParserFactory
createSAXParserFactory(Boolean namespaceAware)
Returns properly configuredSAXParserFactory
with security features.static TransformerFactory
createTransformerFactory()
Returns properly configuredTransformerFactory
with security features.static XPath
createXPath()
Returns properly configuredXPath
with security featuresstatic XPathFactory
createXPathFactory()
Returns properly configuredXPathFactory
with security features.static Iterator<Node>
iterator(NodeList nodes)
Create anIterator
for the given nodes.static Document
parse(File file)
Parse the content of the given file as an XML document.static Document
parse(InputStream is)
Parse the content of the givenInputStream
as an XML document.static Document
parse(Reader reader)
Parse the content of the givenReader
as an XML document.static Document
parse(URI uri)
Parse the content of the given URI as an XML document.static Document
parse(InputSource is)
Parse the content of the givenInputSource
as an XML document.static Spliterator<Node>
spliterator(NodeList nodes)
Create aSpliterator
for the given nodes.static Stream<Node>
stream(NodeList nodes)
Create aStream
of the nodes.static Stream<Element>
stream(Node node, String tagName)
Create aStream
of the child elements with the given tag name.static void
transform(Node node, Writer writer, String encoding)
Transform the given node to xml content.
-
-
-
Method Detail
-
createDocumentBuilderFactory
public static DocumentBuilderFactory createDocumentBuilderFactory(Boolean namespaceAware)
Returns properly configuredDocumentBuilderFactory
with security features and no external DTD and schema access.- Parameters:
namespaceAware
- whether the returned factory is to provide support for XML namespaces- Returns:
- configured
DocumentBuilderFactory
-
createDocumentBuilder
public static DocumentBuilder createDocumentBuilder() throws ParserConfigurationException
Returns properly configuredDocumentBuilder
with security features.- Returns:
- configured
DocumentBuilder
- Throws:
ParserConfigurationException
-
createSAXParserFactory
public static SAXParserFactory createSAXParserFactory(Boolean namespaceAware)
Returns properly configuredSAXParserFactory
with security features.- Parameters:
namespaceAware
- whether the returned factory is to provide support for XML namespaces- Returns:
- configured
SAXParserFactory
-
createSAXParser
public static SAXParser createSAXParser() throws ParserConfigurationException, SAXException
Returns properly configuredSAXParser
with security features and no external DTD and schema access.- Returns:
- configured
SAXParser
- Throws:
ParserConfigurationException
SAXException
-
createXPathFactory
public static XPathFactory createXPathFactory()
Returns properly configuredXPathFactory
with security features.- Returns:
- configured
XPathFactory
-
createXPath
public static XPath createXPath()
Returns properly configuredXPath
with security features- Returns:
- configured
XPath
-
createTransformerFactory
public static TransformerFactory createTransformerFactory()
Returns properly configuredTransformerFactory
with security features.- Returns:
- configured
TransformerFactory
-
parse
public static Document parse(File file) throws ParserConfigurationException, SAXException, IOException
Parse the content of the given file as an XML document.- Parameters:
file
- the file to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
DocumentBuilder.parse(File)
-
parse
public static Document parse(InputStream is) throws ParserConfigurationException, SAXException, IOException
Parse the content of the givenInputStream
as an XML document.- Parameters:
is
- the InputStream to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
DocumentBuilder.parse(InputStream)
-
parse
public static Document parse(InputSource is) throws ParserConfigurationException, SAXException, IOException
Parse the content of the givenInputSource
as an XML document.- Parameters:
is
- the InputSource to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
DocumentBuilder.parse(InputSource)
-
parse
public static Document parse(Reader reader) throws ParserConfigurationException, SAXException, IOException
Parse the content of the givenReader
as an XML document.- Parameters:
reader
- the Reader to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
-
parse
public static Document parse(URI uri) throws ParserConfigurationException, SAXException, IOException
Parse the content of the given URI as an XML document.- Parameters:
uri
- the location of the content to be parsed.- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
DocumentBuilder.parse(String)
-
transform
public static void transform(Node node, Writer writer, String encoding) throws TransformerException
Transform the given node to xml content.- Parameters:
node
- the node to transformwriter
- the writer where to write the contentencoding
- encoding to user for xml content- Throws:
TransformerException
-
iterator
public static Iterator<Node> iterator(NodeList nodes)
Create anIterator
for the given nodes.- Parameters:
nodes
- the nodes- Returns:
- an iterator
-
spliterator
public static Spliterator<Node> spliterator(NodeList nodes)
Create aSpliterator
for the given nodes.- Parameters:
nodes
- the nodes- Returns:
- a spliterator
-
stream
public static Stream<Node> stream(NodeList nodes)
Create aStream
of the nodes.- Parameters:
nodes
- the nodes- Returns:
- stream of the nodes
-
-