src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java

Print this page


   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.org.apache.xpath.internal.jaxp;
  27 
  28 import com.sun.org.apache.xalan.internal.res.XSLMessages;
  29 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
  30 import com.sun.org.apache.xalan.internal.utils.FeatureManager;
  31 import com.sun.org.apache.xml.internal.dtm.DTM;
  32 import com.sun.org.apache.xpath.internal.objects.XObject;
  33 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
  34 import java.io.IOException;
  35 import javax.xml.namespace.QName;
  36 import javax.xml.parsers.DocumentBuilderFactory;
  37 import javax.xml.parsers.ParserConfigurationException;
  38 import javax.xml.transform.TransformerException;
  39 import javax.xml.xpath.XPathConstants;
  40 import javax.xml.xpath.XPathEvaluationResult;
  41 import javax.xml.xpath.XPathExpressionException;
  42 import javax.xml.xpath.XPathFunctionResolver;
  43 import javax.xml.xpath.XPathNodes;
  44 import javax.xml.xpath.XPathVariableResolver;

  45 import org.w3c.dom.Document;
  46 import org.w3c.dom.Node;
  47 import org.w3c.dom.traversal.NodeIterator;
  48 import org.xml.sax.InputSource;
  49 import org.xml.sax.SAXException;
  50 
  51 /**
  52  * This class contains several utility methods used by XPathImpl and
  53  * XPathExpressionImpl
  54  */
  55 class XPathImplUtil {
  56     XPathFunctionResolver functionResolver;
  57     XPathVariableResolver variableResolver;
  58     JAXPPrefixResolver prefixResolver;
  59     boolean useServiceMechanism = true;
  60     // By default Extension Functions are allowed in XPath Expressions. If
  61     // Secure Processing Feature is set on XPathFactory then the invocation of
  62     // extensions function need to throw XPathFunctionException
  63     boolean featureSecureProcessing = false;
  64     FeatureManager featureManager;
  65 
  66     /**
  67      * Evaluate an XPath context using the internal XPath engine
  68      * @param contextItem The XPath context
  69      * @param xpath The internal XPath engine
  70      * @return an XObject
  71      * @throws javax.xml.transform.TransformerException If the expression cannot be evaluated.
  72      */
  73     XObject eval(Object contextItem, com.sun.org.apache.xpath.internal.XPath xpath)
  74             throws javax.xml.transform.TransformerException {
  75         com.sun.org.apache.xpath.internal.XPathContext xpathSupport;
  76         if (functionResolver != null) {
  77             JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
  78                     functionResolver, featureSecureProcessing, featureManager);
  79             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext(jep);
  80         } else {
  81             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext();
  82         }
  83 
  84         xpathSupport.setVarStack(new JAXPVariableStack(variableResolver));


   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.org.apache.xpath.internal.jaxp;
  27 
  28 import com.sun.org.apache.xalan.internal.res.XSLMessages;
  29 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;

  30 import com.sun.org.apache.xml.internal.dtm.DTM;
  31 import com.sun.org.apache.xpath.internal.objects.XObject;
  32 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
  33 import java.io.IOException;
  34 import javax.xml.namespace.QName;
  35 import javax.xml.parsers.DocumentBuilderFactory;
  36 import javax.xml.parsers.ParserConfigurationException;
  37 import javax.xml.transform.TransformerException;
  38 import javax.xml.xpath.XPathConstants;
  39 import javax.xml.xpath.XPathEvaluationResult;
  40 import javax.xml.xpath.XPathExpressionException;
  41 import javax.xml.xpath.XPathFunctionResolver;
  42 import javax.xml.xpath.XPathNodes;
  43 import javax.xml.xpath.XPathVariableResolver;
  44 import jdk.xml.internal.JdkXmlFeatures;
  45 import org.w3c.dom.Document;
  46 import org.w3c.dom.Node;
  47 import org.w3c.dom.traversal.NodeIterator;
  48 import org.xml.sax.InputSource;
  49 import org.xml.sax.SAXException;
  50 
  51 /**
  52  * This class contains several utility methods used by XPathImpl and
  53  * XPathExpressionImpl
  54  */
  55 class XPathImplUtil {
  56     XPathFunctionResolver functionResolver;
  57     XPathVariableResolver variableResolver;
  58     JAXPPrefixResolver prefixResolver;
  59     boolean useServiceMechanism = true;
  60     // By default Extension Functions are allowed in XPath Expressions. If
  61     // Secure Processing Feature is set on XPathFactory then the invocation of
  62     // extensions function need to throw XPathFunctionException
  63     boolean featureSecureProcessing = false;
  64     JdkXmlFeatures featureManager;
  65 
  66     /**
  67      * Evaluate an XPath context using the internal XPath engine
  68      * @param contextItem The XPath context
  69      * @param xpath The internal XPath engine
  70      * @return an XObject
  71      * @throws javax.xml.transform.TransformerException If the expression cannot be evaluated.
  72      */
  73     XObject eval(Object contextItem, com.sun.org.apache.xpath.internal.XPath xpath)
  74             throws javax.xml.transform.TransformerException {
  75         com.sun.org.apache.xpath.internal.XPathContext xpathSupport;
  76         if (functionResolver != null) {
  77             JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
  78                     functionResolver, featureSecureProcessing, featureManager);
  79             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext(jep);
  80         } else {
  81             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext();
  82         }
  83 
  84         xpathSupport.setVarStack(new JAXPVariableStack(variableResolver));