Package org.openstreetmap.josm.tools
Class XmlUtils
- java.lang.Object
-
- org.openstreetmap.josm.tools.XmlUtils
-
public final class XmlUtils extends java.lang.Object
XML utils, mainly used to construct safe factories.- Since:
- 13901
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
FEATURE_DISALLOW_DOCTYPE_DECL
-
Constructor Summary
Constructors Modifier Constructor Description private
XmlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node parent)
Get the first child elementstatic javax.xml.parsers.DocumentBuilder
newSafeDOMBuilder()
Returns a new secure DOM builder, supporting XML namespaces.static javax.xml.parsers.SAXParser
newSafeSAXParser()
Returns a new secure SAX parser, supporting XML namespaces.static javax.xml.transform.TransformerFactory
newSafeTransformerFactory()
Returns a new secureTransformerFactory
.static javax.xml.validation.Validator
newSafeValidator(javax.xml.validation.Schema schema)
Returns a new secureValidator
.static javax.xml.stream.XMLInputFactory
newSafeXMLInputFactory()
Returns a new secureXMLInputFactory
.static javax.xml.validation.SchemaFactory
newXmlSchemaFactory()
Returns the W3C XML Schema factory implementation.static org.w3c.dom.Document
parseSafeDOM(java.io.InputStream is)
Parse the content givenInputStream
as XML.static void
parseSafeSAX(org.xml.sax.InputSource is, org.xml.sax.helpers.DefaultHandler dh)
Parse the content givenInputSource
as XML using the specifiedDefaultHandler
.
-
-
-
Field Detail
-
FEATURE_DISALLOW_DOCTYPE_DECL
private static final java.lang.String FEATURE_DISALLOW_DOCTYPE_DECL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlUtils
private XmlUtils()
-
-
Method Detail
-
newXmlSchemaFactory
public static javax.xml.validation.SchemaFactory newXmlSchemaFactory()
Returns the W3C XML Schema factory implementation. Robust method dealing with ContextClassLoader problems.- Returns:
- the W3C XML Schema factory implementation
-
newSafeDOMBuilder
public static javax.xml.parsers.DocumentBuilder newSafeDOMBuilder() throws javax.xml.parsers.ParserConfigurationException
Returns a new secure DOM builder, supporting XML namespaces.- Returns:
- a new secure DOM builder, supporting XML namespaces
- Throws:
javax.xml.parsers.ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.
-
parseSafeDOM
public static org.w3c.dom.Document parseSafeDOM(java.io.InputStream is) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXException
Parse the content givenInputStream
as XML. This method uses a secure DOM builder, supporting XML namespaces.- Parameters:
is
- The InputStream containing the content to be parsed.- Returns:
- the result DOM document
- Throws:
javax.xml.parsers.ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.java.io.IOException
- if any IO errors occur.org.xml.sax.SAXException
- for SAX errors.
-
newSafeSAXParser
public static javax.xml.parsers.SAXParser newSafeSAXParser() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Returns a new secure SAX parser, supporting XML namespaces.- Returns:
- a new secure SAX parser, supporting XML namespaces
- Throws:
javax.xml.parsers.ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException
- for SAX errors.
-
parseSafeSAX
public static void parseSafeSAX(org.xml.sax.InputSource is, org.xml.sax.helpers.DefaultHandler dh) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
Parse the content givenInputSource
as XML using the specifiedDefaultHandler
. This method uses a secure SAX parser, supporting XML namespaces.- Parameters:
is
- The InputSource containing the content to be parsed.dh
- The SAX DefaultHandler to use.- Throws:
javax.xml.parsers.ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException
- for SAX errors.java.io.IOException
- if any IO errors occur.
-
newSafeXMLInputFactory
public static javax.xml.stream.XMLInputFactory newSafeXMLInputFactory()
Returns a new secureXMLInputFactory
.- Returns:
- a new secure
XMLInputFactory
, for which external entities are not loaded
-
newSafeTransformerFactory
public static javax.xml.transform.TransformerFactory newSafeTransformerFactory() throws javax.xml.transform.TransformerConfigurationException
Returns a new secureTransformerFactory
.- Returns:
- a new secure
TransformerFactory
- Throws:
javax.xml.transform.TransformerConfigurationException
- if the factory or the Transformers or Templates it creates cannot support this feature.
-
newSafeValidator
public static javax.xml.validation.Validator newSafeValidator(javax.xml.validation.Schema schema)
Returns a new secureValidator
.- Parameters:
schema
- XML schema- Returns:
- a new secure
Validator
- Since:
- 14441
-
getFirstChildElement
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent)
Get the first child element- Parameters:
parent
- parent node- Returns:
- the first child element
- Since:
- 14348
-
-