Class SecureXPathFactory
XPathFactory instances.
Beyond the three universal guarantees on org.apache.commons.xml.secure, URI-fetching XPath 3.1+ functions (doc(), collection(),
unparsed-text()) are not resolved.
The guarantees also cover the document parse behind XPath.evaluate(String, InputSource) and XPathExpression.evaluate(InputSource): the
input document is built through a secure, namespace-aware DocumentBuilder instead of the engine's internal parser.
Not a XPathFactory itself, so none of the JAXP static factory methods is inherited: a caller cannot reach a non-secured factory through this class
by calling an inherited method such as newDefaultInstance(). The secure factories are instances of a nested, non-public wrapper class.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic XPathFactoryReturns a new, secureXPathFactoryof the system-default implementation, supporting the default XPath object model.static XPathFactoryReturns a new, secureXPathFactoryfor the default XPath object model.static XPathFactorynewInstance(String uri) Returns a new, secureXPathFactoryfor the given object model.static XPathFactorynewInstance(String uri, String factoryClassName, ClassLoader classLoader) Returns a new, secureXPathFactoryof the given implementation class.
-
Method Details
-
newDefaultInstance
Returns a new, secureXPathFactoryof the system-default implementation, supporting the default XPath object model.Obtained as by
XPathFactory.newDefaultInstance()where the platform provides it (Java 9 or later), and by instantiating the JDK's built-in implementation directly on Java 8.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.RuntimeException- Thrown if the running platform provides neithernewDefaultInstance()nor the JDK's built-in implementation (for example Android).
-
newInstance
Returns a new, secureXPathFactoryfor the default XPath object model.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.RuntimeException- Thrown if there is a failure in creating anXPathFactoryfor the default object model.
-
newInstance
Returns a new, secureXPathFactoryfor the given object model.- Parameters:
uri- The underlying object model identifier, as accepted byXPathFactory.newInstance(String).- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.XPathFactoryConfigurationException- Thrown if no implementation of the object model is available.NullPointerException- Thrown ifuriisnull.IllegalArgumentException- Thrown ifuriis empty.
-
newInstance
public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException Returns a new, secureXPathFactoryof the given implementation class.- Parameters:
uri- The underlying object model identifier, as accepted byXPathFactory.newInstance(String).factoryClassName- The fully qualified class name of theXPathFactoryimplementation.classLoader- The class loader used to load the factory class;nullmeans the current thread's context class loader.- Returns:
- A secure factory.
- Throws:
IllegalStateException- Thrown if a required secure setting cannot be applied to the underlying implementation.XPathFactoryConfigurationException- Thrown iffactoryClassNameisnull, or if the factory class cannot be loaded or instantiated, or does not supporturi.NullPointerException- Thrown ifuriisnull.IllegalArgumentException- Thrown ifuriis empty.
-