You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/10/10 13:00:27 UTC

svn commit: r1180873 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security: transforms/implementations/ utils/

Author: coheigea
Date: Mon Oct 10 11:00:26 2011
New Revision: 1180873

URL: http://svn.apache.org/viewvc?rev=1180873&view=rev
Log:
Simplified the Xalan dependencies for XPath as part of the refactor

Removed:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathAPIHolder.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XPathFuncHereAPI.java
Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java?rev=1180873&r1=1180872&r2=1180873&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java Mon Oct 10 11:00:26 2011
@@ -69,15 +69,6 @@ public class FuncHereContext extends XPa
      * Constructor FuncHereContext
      *
      * @param owner
-     */
-    public FuncHereContext(Node owner) {
-        super(owner);
-    }
-
-    /**
-     * Constructor FuncHereContext
-     *
-     * @param owner
      * @param xpathContext
      */
     public FuncHereContext(Node owner, XPathContext xpathContext) {
@@ -97,25 +88,6 @@ public class FuncHereContext extends XPa
      * Constructor FuncHereContext
      *
      * @param owner
-     * @param previouslyUsed
-     */
-    public FuncHereContext(Node owner, CachedXPathAPI previouslyUsed) {
-
-        super(owner);
-
-        try {
-            super.m_dtmManager = previouslyUsed.getXPathContext().getDTMManager();
-        } catch (IllegalAccessError iae) {
-            throw new IllegalAccessError(I18n.translate("endorsed.jdk1.4.0")
-                                         + " Original message was \""
-                                         + iae.getMessage() + "\"");
-        }
-    }
-
-    /**
-     * Constructor FuncHereContext
-     *
-     * @param owner
      * @param dtmManager
      */
     public FuncHereContext(Node owner, DTMManager dtmManager) {

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java?rev=1180873&r1=1180872&r2=1180873&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java Mon Oct 10 11:00:26 2011
@@ -29,7 +29,6 @@ import org.apache.xml.security.transform
 import org.apache.xml.security.transforms.TransformSpi;
 import org.apache.xml.security.transforms.TransformationException;
 import org.apache.xml.security.transforms.Transforms;
-import org.apache.xml.security.utils.CachedXPathAPIHolder;
 import org.apache.xml.security.utils.CachedXPathFuncHereAPI;
 import org.apache.xml.security.utils.Constants;
 import org.apache.xml.security.utils.XMLUtils;
@@ -86,10 +85,6 @@ public class TransformXPath extends Tran
              * The evaluation of this expression includes all of the document's nodes
              * (including comments) in the node-set representing the octet stream.
              */
-            CachedXPathAPIHolder.setDoc(transformObject.getElement().getOwnerDocument());
-
-
-
             Element xpathElement =
                 XMLUtils.selectDsNode(
                     transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);
@@ -126,16 +121,15 @@ public class TransformXPath extends Tran
 
     static class XPathNodeFilter implements NodeFilter {
         
-        PrefixResolverDefault prefixResolver;
-        CachedXPathFuncHereAPI xPathFuncHereAPI =
-            new CachedXPathFuncHereAPI(CachedXPathAPIHolder.getCachedXPathAPI());
+        CachedXPathFuncHereAPI xPathFuncHereAPI = new CachedXPathFuncHereAPI();
         Node xpathnode; 
+        Element xpathElement;
         String str;
         
         XPathNodeFilter(Element xpathElement, Node xpathnode, String str) {
             this.xpathnode = xpathnode;
             this.str = str;
-            prefixResolver = new PrefixResolverDefault(xpathElement);
+            this.xpathElement = xpathElement;
         }
 
         /**
@@ -144,8 +138,7 @@ public class TransformXPath extends Tran
         public int isNodeInclude(Node currentNode) {			
             XObject includeInResult;
             try {
-                includeInResult = 
-                    xPathFuncHereAPI.eval(currentNode, xpathnode, str, prefixResolver);
+                includeInResult = xPathFuncHereAPI.eval(currentNode, xpathnode, str, xpathElement);
                 if (includeInResult.bool()) {
                     return 1;
                 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java?rev=1180873&r1=1180872&r2=1180873&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java Mon Oct 10 11:00:26 2011
@@ -38,7 +38,6 @@ import org.apache.xml.security.transform
 import org.apache.xml.security.transforms.TransformationException;
 import org.apache.xml.security.transforms.Transforms;
 import org.apache.xml.security.transforms.params.XPath2FilterContainer;
-import org.apache.xml.security.utils.CachedXPathAPIHolder;
 import org.apache.xml.security.utils.CachedXPathFuncHereAPI;
 import org.apache.xml.security.utils.XMLUtils;
 import org.w3c.dom.DOMException;
@@ -80,14 +79,12 @@ public class TransformXPath2Filter exten
     protected XMLSignatureInput enginePerformTransform(
         XMLSignatureInput input, OutputStream os, Transform transformObject
     ) throws TransformationException {
-        CachedXPathAPIHolder.setDoc(transformObject.getElement().getOwnerDocument());
         try {
             List<NodeList> unionNodes = new ArrayList<NodeList>();
             List<NodeList> substractNodes = new ArrayList<NodeList>();
             List<NodeList> intersectNodes = new ArrayList<NodeList>();
 
-            CachedXPathFuncHereAPI xPathFuncHereAPI =
-                new CachedXPathFuncHereAPI(CachedXPathAPIHolder.getCachedXPathAPI());
+            CachedXPathFuncHereAPI xPathFuncHereAPI = new CachedXPathFuncHereAPI();
 
             Element[] xpathElements =
                 XMLUtils.selectNodes(

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java?rev=1180873&r1=1180872&r2=1180873&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java Mon Oct 10 11:00:26 2011
@@ -68,72 +68,11 @@ public class CachedXPathFuncHereAPI {
     }
 
     /**
-     * Method getFuncHereContext
-     * @return the context for this object
-     *
-     */
-    public FuncHereContext getFuncHereContext() {
-        return this.funcHereContext;
-    }
-
-    /**
-     * Constructor CachedXPathFuncHereAPI
-     *
-     * @param existingXPathContext
-     */
-    public CachedXPathFuncHereAPI(XPathContext existingXPathContext) {
-        this.dtmManager = existingXPathContext.getDTMManager();
-        this.context=existingXPathContext;
-    }
-
-    /**
      * Constructor CachedXPathFuncHereAPI
-     *
-     * @param previouslyUsed
-     */
-    public CachedXPathFuncHereAPI(CachedXPathAPI previouslyUsed) {
-        this.dtmManager = previouslyUsed.getXPathContext().getDTMManager();
-        this.context=previouslyUsed.getXPathContext();
-    }
-
-    /**
-     * Use an XPath string to select a single node. XPath namespace
-     * prefixes are resolved from the context node, which may not
-     * be what you want (see the next method).
-     *
-     * @param contextNode The node to start searching from.
-     * @param xpathnode A Node containing a valid XPath string.
-     * @return The first node found that matches the XPath, or null.
-     *
-     * @throws TransformerException
      */
-    public Node selectSingleNode(Node contextNode, Node xpathnode)
-    throws TransformerException {
-        return selectSingleNode(contextNode, xpathnode, contextNode);
-    }
-
-    /**
-     * Use an XPath string to select a single node.
-     * XPath namespace prefixes are resolved from the namespaceNode.
-     *
-     * @param contextNode The node to start searching from.
-     * @param xpathnode
-     * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
-     * @return The first node found that matches the XPath, or null.
-     *
-     * @throws TransformerException
-     */
-    public Node selectSingleNode(
-        Node contextNode, Node xpathnode, Node namespaceNode
-    ) throws TransformerException {
-        NodeList nl = 
-            selectNodeList(contextNode, xpathnode, getStrFromNode(xpathnode), namespaceNode);
-
-        // Return the first node, or null
-        if (nl == null) {
-            return null;
-        }
-        return nl.item(0);
+    public CachedXPathFuncHereAPI() {
+        this.context = new XPathContext();
+        this.dtmManager = context.getDTMManager();
     }
 
     /**
@@ -213,61 +152,6 @@ public class CachedXPathFuncHereAPI {
         return xpath.execute(this.funcHereContext, ctxtNode, prefixResolver);
     }
 
-    /**
-     *   Evaluate XPath string to an XObject.
-     *   XPath namespace prefixes are resolved from the namespaceNode.
-     *   The implementation of this is a little slow, since it creates
-     *   a number of objects each time it is called.  This could be optimized
-     *   to keep the same objects around, but then thread-safety issues would arise.
-     *
-     *   @param contextNode The node to start searching from.
-     *   @param xpathnode
-     *   @param str
-     *   @param prefixResolver Will be called if the parser encounters namespace
-     *                         prefixes, to resolve the prefixes to URLs.
-     *   @return An XObject, which can be used to obtain a string, number, nodelist, etc, 
-     *   should never be null.
-     *   @see org.apache.xpath.objects.XObject
-     *   @see org.apache.xpath.objects.XNull
-     *   @see org.apache.xpath.objects.XBoolean
-     *   @see org.apache.xpath.objects.XNumber
-     *   @see org.apache.xpath.objects.XString
-     *   @see org.apache.xpath.objects.XRTreeFrag
-     *
-     * @throws TransformerException
-     */
-    public XObject eval(
-        Node contextNode, Node xpathnode, String str, PrefixResolver prefixResolver)
-    throws TransformerException {
-        if (!str.equals(xpathStr)) {
-            if (str.indexOf("here()")>0) {
-                context.reset();
-                dtmManager=context.getDTMManager();
-            }
-            try {
-                xpath = createXPath(str, prefixResolver);
-            } catch (TransformerException ex) {
-                //Try to see if it is a problem with the classloader.
-                Throwable th= ex.getCause();
-                if (th instanceof ClassNotFoundException && th.getMessage().indexOf("FuncHere")>0) {
-                    throw new RuntimeException(I18n.translate("endorsed.jdk1.4.0")/*,*/+ex);
-                }
-                throw ex;
-            }
-            xpathStr=str;
-        }
-
-        // Execute the XPath, and have it return the result
-        if (this.funcHereContext == null) {
-            this.funcHereContext = new FuncHereContext(xpathnode,
-                                                        this.dtmManager);
-        }
-
-        int ctxtNode = this.funcHereContext.getDTMHandleFromNode(contextNode);
-
-        return xpath.execute(this.funcHereContext, ctxtNode, prefixResolver);
-    }
-
     private XPath createXPath(String str, PrefixResolver prefixResolver) throws TransformerException {
         XPath xpath = null;
         Class[] classes = new Class[]{String.class, SourceLocator.class, PrefixResolver.class, int.class,