//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2018 Saxonica Limited. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// package net.sf.saxon.xpath; import net.sf.saxon.Configuration; import net.sf.saxon.Version; import net.sf.saxon.lib.Feature; import net.sf.saxon.lib.FeatureKeys; import net.sf.saxon.lib.NamespaceConstant; import net.sf.saxon.lib.Validation; import javax.xml.XMLConstants; import javax.xml.xpath.*; /** * Saxon implementation of the JAXP 1.3 XPathFactory */ public class XPathFactoryImpl extends XPathFactory implements Configuration.ApiProvider { private Configuration config; private XPathVariableResolver variableResolver; private XPathFunctionResolver functionResolver; /** * Default constructor: this creates a Configuration as well as creating the XPathFactory. Any documents * accessed using this XPathFactory must be built using this same Configuration. */ public XPathFactoryImpl() { config = Configuration.newConfiguration(); setConfiguration(config); Version.platform.registerAllBuiltInObjectModels(config); } /** * Constructor using a user-supplied Configuration. * This constructor is useful if the document to be queried already exists, as it allows the configuration * associated with the document to be used with this XPathFactory. * * @param config the Saxon configuration */ public XPathFactoryImpl(Configuration config) { this.config = config; config.setProcessor(this); } /** * Set the Configuration for the factory * * @param config the Saxon Configuration to be used */ public void setConfiguration(Configuration config) { this.config = config; config.setProcessor(this); } /** * Get the Configuration object used by this XPathFactory * * @return the Saxon configuration */ public Configuration getConfiguration() { return config; } /** * Test whether a given object model is supported. Returns true if the object model * is the Saxon object model, DOM, JDOM, DOM4J, or XOM * * @param model The URI identifying the object model. * @return true if the object model is one of the following (provided that the supporting * JAR file is available on the classpath) * {@link net.sf.saxon.lib.NamespaceConstant#OBJECT_MODEL_SAXON}, * {@link XPathConstants#DOM_OBJECT_MODEL}, * {@link net.sf.saxon.lib.NamespaceConstant#OBJECT_MODEL_JDOM}, or * {@link NamespaceConstant#OBJECT_MODEL_XOM}, or * {@link net.sf.saxon.lib.NamespaceConstant#OBJECT_MODEL_DOM4J}. * Saxon also allows user-defined external object models to be registered with the Configuration, and * this method will return true in respect of any such model. */ public boolean isObjectModelSupported(String model) { boolean debug = System.getProperty("jaxp.debug") != null; boolean result = silentIsObjectModelSupported(model); if (debug) { System.err.println("JAXP: Calling " + getClass().getName() + ".isObjectModelSupported(\"" + model + "\")"); System.err.println("JAXP: -- returning " + (result ? "true" : "false (check all required libraries are on the class path")); } return result; } private boolean silentIsObjectModelSupported(String model) { return model.equals(NamespaceConstant.OBJECT_MODEL_SAXON) || config.getExternalObjectModel(model) != null; } /** * Set a feature of this XPath implementation. The features currently * recognized are: *
In addition, any Saxon configuration feature (listed in {@link FeatureKeys} can be used
* provided the value is a boolean. (For non-boolean configuration properties, drop down to the underlying
* Saxon {@link Configuration} object and call setConfigurationProperty())
In addition, any Saxon configuration feature (listed in {@link FeatureKeys} can be used
* provided the value is a boolean. (For non-boolean configuration properties, drop down to the underlying
* Saxon {@link Configuration} object and call getConfigurationProperty())