Class XmlFactoryUtils
The standard newInstance() lookup uses the classpath (ServiceLoader / system
properties), so an outdated XML parser leaking onto the classpath (e.g. Xerces 2.x pulled in
transitively by another library) would be picked up and break BOM parsing and validation with
errors like Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not
recognized, because such parsers pre-date the JAXP 1.5 secure-processing properties.
See cyclonedx-gradle-plugin#349.
An implementation explicitly requested via the JAXP system properties
(javax.xml.parsers.DocumentBuilderFactory /
javax.xml.validation.SchemaFactory:<schemaLanguage>) is still honored, as that is a
deliberate configuration choice rather than an accidental classpath leak.
The newDefaultInstance() factory methods only exist since Java 9 while this library
targets Java 8, so they are invoked reflectively, falling back to the standard lookup.
- Since:
- 13.1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilderFactoryCreates a newDocumentBuilderFactory, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.parsers.DocumentBuilderFactorysystem property.static SAXParserFactoryCreates a newSAXParserFactory, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.parsers.SAXParserFactorysystem property.static SchemaFactoryCreates a newSchemaFactoryfor W3C XML Schema, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchemasystem property.
-
Method Details
-
newDocumentBuilderFactory
Creates a newDocumentBuilderFactory, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.parsers.DocumentBuilderFactorysystem property.- Returns:
- a new
DocumentBuilderFactory
-
newSAXParserFactory
Creates a newSAXParserFactory, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.parsers.SAXParserFactorysystem property.- Returns:
- a new
SAXParserFactory
-
newSchemaFactory
Creates a newSchemaFactoryfor W3C XML Schema, preferring the JDK's built-in implementation unless one is explicitly requested via thejavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchemasystem property.- Returns:
- a new
SchemaFactory
-