Package org.openstreetmap.josm.tools
Class XmlUtils
- java.lang.Object
-
- org.openstreetmap.josm.tools.XmlUtils
-
-
Field Summary
Fields Modifier and Type Field Description private static 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 Element
getFirstChildElement(Node parent)
Get the first child elementstatic DocumentBuilder
newSafeDOMBuilder()
Returns a new secure DOM builder, supporting XML namespaces.static SAXParser
newSafeSAXParser()
Returns a new secure SAX parser, supporting XML namespaces.static TransformerFactory
newSafeTransformerFactory()
Returns a new secureTransformerFactory
.static Validator
newSafeValidator(Schema schema)
Returns a new secureValidator
.static XMLInputFactory
newSafeXMLInputFactory()
Returns a new secureXMLInputFactory
.static SchemaFactory
newXmlSchemaFactory()
Returns the W3C XML Schema factory implementation.static Document
parseSafeDOM(InputStream is)
Parse the content givenInputStream
as XML.static void
parseSafeSAX(InputSource is, DefaultHandler dh)
Parse the content givenInputSource
as XML using the specifiedDefaultHandler
.
-
-
-
Field Detail
-
FEATURE_DISALLOW_DOCTYPE_DECL
private static final String FEATURE_DISALLOW_DOCTYPE_DECL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlUtils
private XmlUtils()
-
-
Method Detail
-
newXmlSchemaFactory
public static 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 DocumentBuilder newSafeDOMBuilder() throws ParserConfigurationException
Returns a new secure DOM builder, supporting XML namespaces.- Returns:
- a new secure DOM builder, supporting XML namespaces
- Throws:
ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.
-
parseSafeDOM
public static Document parseSafeDOM(InputStream is) throws ParserConfigurationException, IOException, 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:
ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.IOException
- if any IO errors occur.SAXException
- for SAX errors.
-
newSafeSAXParser
public static SAXParser newSafeSAXParser() throws ParserConfigurationException, SAXException
Returns a new secure SAX parser, supporting XML namespaces.- Returns:
- a new secure SAX parser, supporting XML namespaces
- Throws:
ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.SAXException
- for SAX errors.
-
parseSafeSAX
public static void parseSafeSAX(InputSource is, DefaultHandler dh) throws ParserConfigurationException, SAXException, 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:
ParserConfigurationException
- if a parser cannot be created which satisfies the requested configuration.SAXException
- for SAX errors.IOException
- if any IO errors occur.
-
newSafeXMLInputFactory
public static XMLInputFactory newSafeXMLInputFactory()
Returns a new secureXMLInputFactory
.- Returns:
- a new secure
XMLInputFactory
, for which external entities are not loaded
-
newSafeTransformerFactory
public static TransformerFactory newSafeTransformerFactory() throws TransformerConfigurationException
Returns a new secureTransformerFactory
.- Returns:
- a new secure
TransformerFactory
- Throws:
TransformerConfigurationException
- if the factory or the Transformers or Templates it creates cannot support this feature.
-
newSafeValidator
public static Validator newSafeValidator(Schema schema)
Returns a new secureValidator
.- Parameters:
schema
- XML schema- Returns:
- a new secure
Validator
- Since:
- 14441
-
getFirstChildElement
public static Element getFirstChildElement(Node parent)
Get the first child element- Parameters:
parent
- parent node- Returns:
- the first child element
- Since:
- 14348
-
-