You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2006/07/02 01:16:27 UTC

svn commit: r418518 - in /xml/security/trunk/src/org: apache/xml/security/c14n/implementations/ apache/xml/security/signature/ apache/xml/security/transforms/implementations/ jcp/xml/dsig/internal/dom/

Author: raul
Date: Sat Jul  1 16:16:27 2006
New Revision: 418518

URL: http://svn.apache.org/viewvc?rev=418518&view=rev
Log:
Support for pruning whole branches in xpath c14n.

Modified:
    xml/security/trunk/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
    xml/security/trunk/src/org/apache/xml/security/signature/NodeFilter.java
    xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java
    xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath.java
    xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
    xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java

Modified: xml/security/trunk/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java Sat Jul  1 16:16:27 2006
@@ -443,7 +443,12 @@
 			Element currentElement = (Element) currentNode;
 			//Add a level to the nssymbtable. So latter can be pop-back.
 			String name=null;
-			currentNodeIsVisible=isVisible(currentNode);
+			int i=isVisibleElement(currentNode);
+			if (i==-1) {
+				sibling= currentNode.getNextSibling();
+				break;
+			}
+			currentNodeIsVisible=(i==1);
 			if (currentNodeIsVisible) {
 				ns.outputNodePush();
 				writer.write('<');
@@ -481,7 +486,7 @@
 				}
 			} else {
 				parentNode=currentElement;
-			}
+			}			
 			break;
 		}
 		while (sibling==null  && parentNode!=null) {    
@@ -510,12 +515,24 @@
 		sibling=currentNode.getNextSibling();  
 	} while(true);
    }
-
+   int isVisibleElement(Node currentNode) {
+	   if (nodeFilter!=null) {
+	   		Iterator it=nodeFilter.iterator();
+	   		while (it.hasNext()) {   	
+	   			int i=((NodeFilter)it.next()).isNodeInclude(currentNode);
+	   			if (i!=1)
+	   				return i;
+	   		}
+		   }
+	   if ((this._xpathNodeSet!=null) && !this._xpathNodeSet.contains(currentNode))
+  			return 0;
+	   return 1;
+   }
    boolean isVisible(Node currentNode) {
 	   if (nodeFilter!=null) {
    		Iterator it=nodeFilter.iterator();
-   		while (it.hasNext()) {
-   			if (!((NodeFilter)it.next()).isNodeInclude(currentNode))
+   		while (it.hasNext()) {   			
+   			if (((NodeFilter)it.next()).isNodeInclude(currentNode)!=1)
    				return false;
    		}
 	   }

Modified: xml/security/trunk/src/org/apache/xml/security/signature/NodeFilter.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/signature/NodeFilter.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/signature/NodeFilter.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/signature/NodeFilter.java Sat Jul  1 16:16:27 2006
@@ -27,8 +27,11 @@
 	/**
 	 * Tells if a node must be outputed in c14n.
 	 * @param n
-	 * @return true if node must be outputed, false otherwise.
+	 * @return 1 if the node should be outputed.
+	 * 		   0 if node must not be outputed, 
+	 * 		  -1 if the node and all it's child must not be output.
+	 * 			
 	 */
-	public boolean isNodeInclude(Node n);
+	public int isNodeInclude(Node n);
 
 }

Modified: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java Sat Jul  1 16:16:27 2006
@@ -120,9 +120,13 @@
 	/**
 	 * @see org.apache.xml.security.signature.NodeFilter#isNodeInclude(org.w3c.dom.Node)
 	 */
-	public boolean isNodeInclude(Node n) {
-	    // TODO Optimize me.
-	    return !XMLUtils.isDescendantOrSelf(exclude,n);
+	public int isNodeInclude(Node n) {
+		if ((n==exclude))
+			return -1;
+		if ((n==exclude) || XMLUtils.isDescendantOrSelf(exclude,n)) 
+			return -1;
+		return 1;
+	    //return !XMLUtils.isDescendantOrSelf(exclude,n);
 	}
     }
 }

Modified: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath.java Sat Jul  1 16:16:27 2006
@@ -138,12 +138,14 @@
 	/**
 	 * @see org.apache.xml.security.signature.NodeFilter#isNodeInclude(org.w3c.dom.Node)
 	 */
-	public boolean isNodeInclude(Node currentNode) {			
+	public int isNodeInclude(Node currentNode) {			
 	    XObject includeInResult;
 	    try {
 		includeInResult = xPathFuncHereAPI.eval(currentNode,
 			        xpathnode, str,prefixResolver);
-		return includeInResult.bool();
+		if (includeInResult.bool())
+			return 1;
+		return 0;
 	    } catch (TransformerException e) {
                 Object[] eArgs = {currentNode};
 	        throw new XMLSecurityRuntimeException

Modified: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java Sat Jul  1 16:16:27 2006
@@ -180,18 +180,25 @@
    /**
     * @see org.apache.xml.security.signature.NodeFilter#isNodeInclude(org.w3c.dom.Node)
     */
-   public boolean isNodeInclude(Node currentNode) {	 
+   public int isNodeInclude(Node currentNode) {	 
 	   boolean notIncluded=false;
 	   if (!substractNodes.isEmpty() && rooted(currentNode, substractNodes)) {
 		      notIncluded = true;
 	   } else if (!intersectNodes.isEmpty() && !rooted(currentNode, intersectNodes)) {
 		   notIncluded = true;
 	   }
-	   if (!unionNodes.isEmpty() && notIncluded && rooted(currentNode, unionNodes)) {
-		   notIncluded = false;
+	   	   
+	  //TODO OPTIMIZE
+      if (!notIncluded)     	        
+    	  return 1;
+      boolean hasUnionNodes=!unionNodes.isEmpty();
+      if (hasUnionNodes && rooted(currentNode, unionNodes)) {
+		   return 1;
 	   }
-
-      return !notIncluded;
+      if (!hasUnionNodes) {
+    	  return -1; //Not union nodes to safe a node that has been exclude.
+      }
+      return 0;
 
    }
 

Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java?rev=418518&r1=418517&r2=418518&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java Sat Jul  1 16:16:27 2006
@@ -78,7 +78,7 @@
             boolean skipNode = false;
             while (it.hasNext() && !skipNode) {
                 NodeFilter nf = (NodeFilter) it.next();
-                if (!nf.isNodeInclude(currentNode)) {
+                if (nf.isNodeInclude(currentNode)!=1) {
                     skipNode = true;
                 }
             }