Class XMLUtils
- Author:
- Andrea Aime - GeoSolutions
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSAXErrorHandler that logs errors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidTests whether the TransformerFactory and SchemaFactory implementations support JAXP 1.5 properties to protect against XML external entity injection (XXE) attacks.static DocumentBuilderCreates a new document builder, as an alternative toDocumentBuilder.newDocument(), allowing GeoTools library configuration to be applied.static DocumentBuildernewDocumentBuilder(DocumentBuilderFactory factory) Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.static DocumentBuildernewDocumentBuilder(DocumentBuilderFactory factory, Hints hints) Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.static DocumentBuildernewDocumentBuilder(Hints hints) Creates a new document builder, as an alternative to direct use ofDocumentBuilder.newDocument(), allowing GeoTools library configuration to be applied.static DocumentBuilderFactoryCreate a new DocumentBuilderFactory allowing GeoTools library configuration to be applied.static DocumentBuilderFactorynewDocumentBuilderFactory(Hints hints) Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.static SAXParserCreates a new instance of a SAXParser using GeoTools configuration.static SAXParsernewSAXParser(SAXParserFactory factory) Creates a new instance of a SAXParser provided factory, applying GeoTools configuration.static SAXParsernewSAXParser(SAXParserFactory factory, Hints hints) Creates a new instance of a SAXParser provided factory, applying GeoTools configuration.static SAXParserFactoryCreate a new SAXParserFactory that respects library configuration.static SAXParserFactorynewSAXParserFactory(SAXParserFactory factory, Hints hints) Create a new SAXParser that respects library configuration.static SAXParserFactorynewSAXParserFactory(Hints hints) Create a new SAXParserFactory that respects library configuration.static SAXTransformerFactorystatic SAXTransformerFactorynewSaxTransformerFactory(Hints hints) static SchemaFactorynewSchemaFactory(String schemaLanguage) Creates a new SchemaFactory allowing GeoTools configuration to be applied.static SchemaFactorynewSchemaFactory(String schemaLanguage, Hints hints) Creates a new SchemaFactory allowing GeoTools configuration to be applied.static TransformerCreates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(Source source) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(Source source, Hints hints) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(TransformerFactory factory) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(TransformerFactory factory, Source source) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(TransformerFactory factory, Source source, Hints hints) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(TransformerFactory factory, Hints hints) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformernewTransformer(Hints hints) Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().static TransformerFactoryCreate a new TransformerFactory that respects library configuration.static TransformerFactorynewTransformerFactory(Hints hints) Create a new TransformerFactory that respects library configuration.static XMLInputFactoryCreates an XMLInputFactory configured with GeoTools library defaults.static XMLInputFactorynewXMLInputFactory(Hints hints) Creates an XMLInputFactory configured with GeoTools library defaults.static QNameqName(String name, NamespaceSupport namespaces) Creates a qualified name from a string by parsing out the colon as the prefix / local separator.static StringChecks the string for XML invalid chars, and in case any is found, create a copy with the invalid ones removed.static SAXSourcesax(InputSource inputSource, Hints hints) Alternative to direct use of InputSource allowing SAXSource setup with GeoTools configuration to be applied.static SourceAlternative to direct use ofSource, allowing GeoTools library configuration to be applied when traversal is required.static SourceAlternative to direct use ofSource, allowing GeoTools library configuration to be applied when traversal is required.static SourceAlternative to direct use ofDOMSOurce, allowing GeoTools library configuration to be applied when traversal is required.static XMLUtils.GTSAXParserFactorytoSAXParserFactory(SAXParserFactory factory, Hints hints) Cast / wraps to GTSAXParserFactory respecting GeoTools configuration.protected static TransformerFactorytoTransformerFactory(TransformerFactory factory, Hints hints) Cast /wraps to GTTransformerFactory or GTSAXTransformFactory respecting GeoTools configuration.
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
newXMLInputFactory
Creates an XMLInputFactory configured with GeoTools library defaults.- Returns:
- XMLInputFactory
-
newXMLInputFactory
Creates an XMLInputFactory configured with GeoTools library defaults.The XMLInputFactory provided will be configured to be more forgiving when
NullEntityResolveris used as this indicates the library is configured to work with local files.When working with EntityResolvers allowing `http` access, such as
`DefaultEntityResolver`more restrictions are enforced.- Parameters:
hints- Factory hints- Returns:
- XMLInputFactory
-
newSAXParserFactory
Create a new SAXParserFactory that respects library configuration.- Returns:
- SAX Parser Factory
-
newSAXParserFactory
Create a new SAXParserFactory that respects library configuration.- Parameters:
hints- Factory hints- Returns:
- SAX Parser Factory
-
newSAXParserFactory
Create a new SAXParser that respects library configuration.- Parameters:
hints- Factory hints- Returns:
- SAX Parser Factory
-
toSAXParserFactory
Cast / wraps to GTSAXParserFactory respecting GeoTools configuration.- Parameters:
factory- SAXParserFactory factory, ornullhints- Factory configuration- Returns:
- GTSAXParserFactory respecting GeoTools configuration.
-
newSAXParser
Creates a new instance of a SAXParser using GeoTools configuration.- Returns:
- SAXParser setup with library configuration
- Throws:
ParserConfigurationExceptionSAXException
-
newSAXParser
public static SAXParser newSAXParser(SAXParserFactory factory) throws ParserConfigurationException, SAXException Creates a new instance of a SAXParser provided factory, applying GeoTools configuration.- Parameters:
factory- SAXParserFactory factory, ornull- Returns:
- SAXParser
- Throws:
ParserConfigurationExceptionSAXException
-
newSAXParser
public static SAXParser newSAXParser(SAXParserFactory factory, Hints hints) throws ParserConfigurationException, SAXException Creates a new instance of a SAXParser provided factory, applying GeoTools configuration.- Parameters:
factory- SAXParserFactory factory, ornullhints- Factory configuration- Returns:
- SAXParser
- Throws:
ParserConfigurationExceptionSAXException
-
newTransformerFactory
Create a new TransformerFactory that respects library configuration.- Returns:
- Transformer Factory
-
newTransformerFactory
Create a new TransformerFactory that respects library configuration.- Parameters:
hints- Factory hints- Returns:
- Transformer Factory
-
newSaxTransformerFactory
-
newSaxTransformerFactory
-
newTransformer
Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer(). -
newTransformer
Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer(). -
newTransformer
public static Transformer newTransformer(TransformerFactory factory) throws TransformerConfigurationException Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
factory-- Throws:
TransformerConfigurationException
-
newTransformer
public static Transformer newTransformer(TransformerFactory factory, Hints hints) throws TransformerConfigurationException Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
factory- Factory pre-configured with information such as indentinghints- Factory configuration- Returns:
- XML transformer
- Throws:
TransformerConfigurationException
-
toTransformerFactory
Cast /wraps to GTTransformerFactory or GTSAXTransformFactory respecting GeoTools configuration.- Parameters:
factory- Transformer factory, ornullhints- Factory configuration- Returns:
- GTTransformerFactory or GTSAXTransformFactory respecting GeoTools configuration.
-
newTransformer
Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
source- Source input- Returns:
- XML transformer
- Throws:
TransformerConfigurationException
-
newTransformer
public static Transformer newTransformer(Source source, Hints hints) throws TransformerConfigurationException Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
source- Source inputhints- Factory configuration- Returns:
- XML transformer
- Throws:
TransformerConfigurationException
-
newTransformer
public static Transformer newTransformer(TransformerFactory factory, Source source) throws TransformerConfigurationException Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
source- Source inputfactory- Factory pre-configured with information such as indenting- Returns:
- XML transformer
- Throws:
TransformerConfigurationException
-
newTransformer
public static Transformer newTransformer(TransformerFactory factory, Source source, Hints hints) throws TransformerConfigurationException Creates a new Transformer as an alternative to direct use ofTransformerFactory.newTransformer().- Parameters:
source- Source inputfactory- Factory pre-configured with information such as indentinghints- Factory configuration- Returns:
- XML transformer
- Throws:
TransformerConfigurationException
-
source
Alternative to direct use ofDOMSOurce, allowing GeoTools library configuration to be applied when traversal is required.- Parameters:
dom- Document node- Returns:
- Source with any XML streaming subject to GeoTools configuration including
GeoTools.getEntityResolver(Hints).
-
source
Alternative to direct use ofSource, allowing GeoTools library configuration to be applied when traversal is required.- Parameters:
source-- Returns:
- Source with any XML streaming subject to GeoTools configuration including
GeoTools.getEntityResolver(Hints).
-
source
Alternative to direct use ofSource, allowing GeoTools library configuration to be applied when traversal is required.- Parameters:
source- transform sourcehints- GeoTools library configuration- Returns:
- Source with any XML streaming subject to GeoTools configuration including
GeoTools.getEntityResolver(Hints).
-
sax
Alternative to direct use of InputSource allowing SAXSource setup with GeoTools configuration to be applied.- Parameters:
inputSource- InputSourcehints- GeoTools library configuration- Returns:
- Source with any XML streaming subject to GeoTools configuration including
GeoTools.getEntityResolver(Hints).
-
newDocumentBuilder
Creates a new document builder, as an alternative toDocumentBuilder.newDocument(), allowing GeoTools library configuration to be applied.The document builder is configured using GeoTools configuration including
GeoTools.getEntityResolver(Hints).- Returns:
- DocumentBuilder configured with Ge
- Throws:
ParserConfigurationException
-
newDocumentBuilder
Creates a new document builder, as an alternative to direct use ofDocumentBuilder.newDocument(), allowing GeoTools library configuration to be applied.The document builder is configured using GeoTools configuration including
GeoTools.getEntityResolver(Hints).- Returns:
- DocumentBuilder configured using GeoTools Hints
- Throws:
ParserConfigurationException
-
newDocumentBuilder
public static DocumentBuilder newDocumentBuilder(DocumentBuilderFactory factory) throws ParserConfigurationException Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.This apporach allows document build factory to be configured to be namespace aware, validating, etc. while still applying GeoTools configuration including
GeoTools.getEntityResolver(Hints).DocumentBuilderFactory factory = XMLUtils.newDocumentBuilderFactory(); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = XMLUtils.newDocumentBuilder(factory); Document document = builder.parse(source);
- Parameters:
factory- Configured DocumentBuildFactory- Throws:
ParserConfigurationException
-
newDocumentBuilder
public static DocumentBuilder newDocumentBuilder(DocumentBuilderFactory factory, Hints hints) throws ParserConfigurationException Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.This approach allows document build factory to be configured to be namespace aware, validating, etc. while still applying GeoTools configuration including
GeoTools.getEntityResolver(Hints).Hints hints = GeoTools.getDefaultHints(); hints.put(Hints.ENTITY_RESOLVER, NullEntityResolver.INSTANCE); DocumentBuilderFactory factory = XMLUtils.newDocumentBuilderFactory(hints); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = XMLUtils.newDocumentBuilder(factory, hints); Document document = builder.parse(source);
The above example shows use of this method with NullEntityResolver.- Parameters:
factory- Configured DocumentBuildFactoryhints- Factory hints- Throws:
ParserConfigurationException
-
newDocumentBuilderFactory
Create a new DocumentBuilderFactory allowing GeoTools library configuration to be applied. -
newDocumentBuilderFactory
Create a new DocumentBuilder using a supplied Factory, allowing GeoTools library configuration to be applied.- Parameters:
hints- Factory hints
-
newSchemaFactory
Creates a new SchemaFactory allowing GeoTools configuration to be applied.- Parameters:
schemaLanguage- Schema language which the factory will understand- Returns:
- New instance of schema factory supporting
schemaLanguage
-
newSchemaFactory
Creates a new SchemaFactory allowing GeoTools configuration to be applied.- Parameters:
schemaLanguage- Schema language which the factory will understandhints- Factory hints- Returns:
- New instance of schema factory supporting
schemaLanguage
-
checkSupportForJAXP15Properties
public static void checkSupportForJAXP15Properties()Tests whether the TransformerFactory and SchemaFactory implementations support JAXP 1.5 properties to protect against XML external entity injection (XXE) attacks. The internal JDK XML processors starting with JDK 7u40 would support these properties but outdated versions of XML libraries (e.g., Xalan, Xerces) that do not support these properties may be included in GeoServer's classpath or provided by the web application server.GeoTools uses these properties internally.
- Throws:
IllegalStateException- if the JAXP 1.5 properties are not supported or if there was an error checking for JAXP 1.5 support
-
removeXMLInvalidChars
Checks the string for XML invalid chars, and in case any is found, create a copy with the invalid ones removed. -
qName
Creates a qualified name from a string by parsing out the colon as the prefix / local separator.- Parameters:
name- The possibly qualified name.namespaces- The namespace prefix uri mappings.
-