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/02/23 11:55:07 UTC

svn commit: r1073694 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations: Canonicalizer20010315.java Canonicalizer20010315Excl.java

Author: coheigea
Date: Wed Feb 23 10:55:07 2011
New Revision: 1073694

URL: http://svn.apache.org/viewvc?rev=1073694&view=rev
Log:
[SANTUARIO-259] - More c14n refactoring.

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java?rev=1073694&r1=1073693&r2=1073694&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java Wed Feb 23 10:55:07 2011
@@ -1,4 +1,3 @@
-
 /*
  * Copyright  1999-2004 The Apache Software Foundation.
  *
@@ -17,8 +16,6 @@
  */
 package org.apache.xml.security.c14n.implementations;
 
-
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -44,344 +41,351 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
-
 /**
  * Implements <A HREF="http://www.w3.org/TR/2001/REC-xml-c14n-20010315">Canonical
  * XML Version 1.0</A>, a W3C Recommendation from 15 March 2001.
  *
  * @author Christian Geuer-Pollmann <ge...@apache.org>
- * @version $Revision$
  */
 public abstract class Canonicalizer20010315 extends CanonicalizerBase {
-        boolean firstCall=true;
-        final SortedSet result= new TreeSet(COMPARE);
-    static final String XMLNS_URI=Constants.NamespaceSpecNS;
-    static final String XML_LANG_URI=Constants.XML_LANG_SPACE_SpecNS;
+    boolean firstCall = true;
+    final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
+    
+    static final String XMLNS_URI = Constants.NamespaceSpecNS;
+    static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
+    
     static class XmlAttrStack {
-        int currentLevel=0;
-        int lastlevel=0;
-        XmlsStackElement cur;
         static class XmlsStackElement {
-                int level;
-                boolean rendered=false;
-                List nodes=new ArrayList();
+            int level;
+            boolean rendered = false;
+            List<Attr> nodes = new ArrayList<Attr>();
         };
-        List levels=new ArrayList();    	
+        
+        int currentLevel = 0;
+        int lastlevel = 0;
+        XmlsStackElement cur;
+        List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
+        
         void push(int level) {
-                currentLevel=level;
-                if (currentLevel==-1)
-                        return;
-                cur=null;
-                while (lastlevel>=currentLevel) {
-                        levels.remove(levels.size()-1);
-                        if (levels.size()==0) {
-                                lastlevel=0;
-                                return;    				
-                        }
-                        lastlevel=((XmlsStackElement)levels.get(levels.size()-1)).level;
+            currentLevel = level;
+            if (currentLevel == -1) {
+                return;
+            }
+            cur = null;
+            while (lastlevel >= currentLevel) {
+                levels.remove(levels.size() - 1);
+                if (levels.size() == 0) {
+                    lastlevel = 0;
+                    return;    				
                 }
+                lastlevel = (levels.get(levels.size()-1)).level;
+            }
         }
+        
         void addXmlnsAttr(Attr n) {
-                if (cur==null) {
-                        cur=new XmlsStackElement();
-                        cur.level=currentLevel;
-                        levels.add(cur);
-                        lastlevel=currentLevel;
-                }
-                cur.nodes.add(n);
+            if (cur == null) {
+                cur = new XmlsStackElement();
+                cur.level = currentLevel;
+                levels.add(cur);
+                lastlevel = currentLevel;
+            }
+            cur.nodes.add(n);
         }
-        void getXmlnsAttr(Collection col) {
-                int size=levels.size()-1;
-                if (cur==null) {
-                        cur=new XmlsStackElement();
-                        cur.level=currentLevel;
-                        lastlevel=currentLevel;
-                        levels.add(cur);
+        
+        void getXmlnsAttr(Collection<Attr> col) {
+            int size = levels.size() - 1;
+            if (cur == null) {
+                cur = new XmlsStackElement();
+                cur.level = currentLevel;
+                lastlevel = currentLevel;
+                levels.add(cur);
+            }
+            boolean parentRendered = false;
+            XmlsStackElement e = null;
+            if (size == -1) {
+                parentRendered = true;
+            } else {
+                e = levels.get(size);
+                if (e.rendered && e.level + 1 == currentLevel) {
+                    parentRendered = true;
                 }
-                boolean parentRendered=false;
-                XmlsStackElement e=null;
-                if (size==-1) {
-                        parentRendered=true;
-                } else {
-                        e=(XmlsStackElement)levels.get(size);
-                        if (e.rendered && e.level+1==currentLevel)
-                                parentRendered=true;
-                        
+            }
+            if (parentRendered) {
+                col.addAll(cur.nodes);
+                cur.rendered = true;
+                return;
+            }
+
+            Map<String, Attr> loa = new HashMap<String, Attr>();    		
+            for (; size >= 0; size--) {
+                e = levels.get(size);
+                Iterator<Attr> it = e.nodes.iterator();
+                while (it.hasNext()) {
+                    Attr n = it.next();
+                    if (!loa.containsKey(n.getName())) {
+                        loa.put(n.getName(), n);
+                    }
                 }
-                if (parentRendered) {
-                                col.addAll(cur.nodes);
-                                cur.rendered=true;
-                                return;
-                        }
-                
-                        Map loa = new HashMap();    		
-                for (;size>=0;size--) {
-                        e=(XmlsStackElement)levels.get(size);
-                        Iterator it=e.nodes.iterator();
-                        while (it.hasNext()) {
-                                Attr n=(Attr)it.next();
-                                if (!loa.containsKey(n.getName()))
-                                        loa.put(n.getName(),n);
-                        }
-                        //if (e.rendered)
-                                //break;
-                        
-                };
-                //cur.nodes.clear();
-                //cur.nodes.addAll(loa.values());
-                        cur.rendered=true;
-                col.addAll(loa.values());
+                //if (e.rendered)
+                //break;
+
+            };
+            //cur.nodes.clear();
+            //cur.nodes.addAll(loa.values());
+            cur.rendered = true;
+            col.addAll(loa.values());
         }
-        
+
+    }
+
+    XmlAttrStack xmlattrStack = new XmlAttrStack();
+
+    /**
+     * Constructor Canonicalizer20010315
+     *
+     * @param includeComments
+     */
+    public Canonicalizer20010315(boolean includeComments) {
+        super(includeComments);
     }
-    XmlAttrStack xmlattrStack=new XmlAttrStack();
+
     /**
-    * Constructor Canonicalizer20010315
-    *
-    * @param includeComments
-    */
-   public Canonicalizer20010315(boolean includeComments) {
-      super(includeComments);
-   }
-
-   /**
-    * Returns the Attr[]s to be outputted for the given element.
-    * <br>
-    * The code of this method is a copy of {@link #handleAttributes(Element,
-    * NameSpaceSymbTable)},
-    * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
-    * So if the element in question isRoot of c14n, it's parent is not in the
-    * node set, as well as all other ancestors.
-    *
-    * @param E
-    * @param ns
-    * @return the Attr[]s to be outputted
-    * @throws CanonicalizationException
-    */
-   Iterator handleAttributesSubtree(Element E,  NameSpaceSymbTable ns )
-           throws CanonicalizationException {
-          if (!E.hasAttributes() && !firstCall) {
-         return null; 
-      }
-      // result will contain the attrs which have to be outputted   	  
-      final SortedSet result = this.result;       
-      result.clear();
-      NamedNodeMap attrs = E.getAttributes();
-      int attrsLength = attrs.getLength();      
-            
-      for (int i = 0; i < attrsLength; i++) {
-         Attr N = (Attr) attrs.item(i);
-         String NUri =N.getNamespaceURI();
+     * Returns the Attr[]s to be outputted for the given element.
+     * <br>
+     * The code of this method is a copy of {@link #handleAttributes(Element,
+     * NameSpaceSymbTable)},
+     * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
+     * So if the element in question isRoot of c14n, it's parent is not in the
+     * node set, as well as all other ancestors.
+     *
+     * @param E
+     * @param ns
+     * @return the Attr[]s to be output
+     * @throws CanonicalizationException
+     */
+    Iterator<Attr> handleAttributesSubtree(Element E,  NameSpaceSymbTable ns )
+        throws CanonicalizationException {
+        if (!E.hasAttributes() && !firstCall) {
+            return null; 
+        }
+        // result will contain the attrs which have to be outputted   	  
+        final SortedSet<Attr> result = this.result;       
+        result.clear();
+        NamedNodeMap attrs = E.getAttributes();
+        int attrsLength = attrs.getLength();      
+
+        for (int i = 0; i < attrsLength; i++) {
+            Attr N = (Attr) attrs.item(i);
+            String NUri = N.getNamespaceURI();
 
-         if (!XMLNS_URI.equals(NUri)) {
+            if (!XMLNS_URI.equals(NUri)) {
                 //It's not a namespace attr node. Add to the result and continue.
-            result.add(N);
-            continue;
-         }
-
-         String NName=N.getLocalName();
-         String NValue=N.getValue();        
-         if (XML.equals(NName)
-                 && XML_LANG_URI.equals(NValue)) {
+                result.add(N);
+                continue;
+            }
+
+            String NName = N.getLocalName();
+            String NValue = N.getValue();        
+            if (XML.equals(NName) && XML_LANG_URI.equals(NValue)) {
                 //The default mapping for xml must not be output.
                 continue;
-         }
-         
-         Node n=ns.addMappingAndRender(NName,NValue,N);          		 
-                         
-          if (n!=null) {
-                 //Render the ns definition
-             result.add(n);
-             if (C14nHelper.namespaceIsRelative(N)) {
-                Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
-                throw new CanonicalizationException(
-                   "c14n.Canonicalizer.RelativeNamespace", exArgs);
-             }
-          }        
-      }
-                   
-      if (firstCall) {
-        //It is the first node of the subtree
-        //Obtain all the namespaces defined in the parents, and added to the output.
-        ns.getUnrenderedNodes(result);          	      		            
-        //output the attributes in the xml namespace.
-        xmlattrStack.getXmlnsAttr(result);
-                firstCall=false;
-      } 
-      
-      return result.iterator();
-   }
-
-   /**
-    * Returns the Attr[]s to be outputted for the given element.
-    * <br>
-    * IMPORTANT: This method expects to work on a modified DOM tree, i.e. a DOM which has
-    * been prepared using {@link org.apache.xml.security.utils.XMLUtils#circumventBug2650(
-    * org.w3c.dom.Document)}.
-    * 
-    * @param E
-    * @param ns
-    * @return the Attr[]s to be outputted
-    * @throws CanonicalizationException
-    */
-   Iterator handleAttributes(Element E,  NameSpaceSymbTable ns ) throws CanonicalizationException {    
-    // result will contain the attrs which have to be outputted
-        xmlattrStack.push(ns.getLevel());
-    boolean isRealVisible=isVisibleDO(E,ns.getLevel())==1;    
-    NamedNodeMap attrs = null;
-    int attrsLength = 0;
-    if (E.hasAttributes()) {
-        attrs=E.getAttributes();
-       attrsLength= attrs.getLength();
+            }
+
+            Node n = ns.addMappingAndRender(NName, NValue, N);          		 
+
+            if (n != null) {
+                //Render the ns definition
+                result.add((Attr)n);
+                if (C14nHelper.namespaceIsRelative(N)) {
+                    Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
+                    throw new CanonicalizationException(
+                        "c14n.Canonicalizer.RelativeNamespace", exArgs
+                    );
+                }
+            }        
+        }
+
+        if (firstCall) {
+            //It is the first node of the subtree
+            //Obtain all the namespaces defined in the parents, and added to the output.
+            ns.getUnrenderedNodes(result);          	      		            
+            //output the attributes in the xml namespace.
+            xmlattrStack.getXmlnsAttr(result);
+            firstCall = false;
+        } 
+
+        return result.iterator();
     }
-    
-    
-    SortedSet result = this.result;       
-    result.clear();
-            
-    for (int i = 0; i < attrsLength; i++) {
-       Attr N = (Attr) attrs.item(i);
-       String NUri =N.getNamespaceURI();
-       
-       if (!XMLNS_URI.equals(NUri)) {
-          //A non namespace definition node.
-           if (XML_LANG_URI.equals(NUri)) {
-                          xmlattrStack.addXmlnsAttr(N);
-           } else if (isRealVisible){
-                //The node is visible add the attribute to the list of output attributes.
-                result.add(N);
-          } 
-          //keep working
-          continue;
-       }
-
-       String NName=N.getLocalName();
-       String NValue=N.getValue();              
-       if ("xml".equals(NName)
-               && XML_LANG_URI.equals(NValue)) {
-          /* except omit namespace node with local name xml, which defines
-           * the xml prefix, if its string value is http://www.w3.org/XML/1998/namespace.
-           */
-          continue;
-       }
-       //add the prefix binding to the ns symb table.
-       //ns.addInclusiveMapping(NName,NValue,N,isRealVisible);          
-            if  (isVisible(N))  {
+
+    /**
+     * Returns the Attr[]s to be outputted for the given element.
+     * <br>
+     * IMPORTANT: This method expects to work on a modified DOM tree, i.e. a DOM which has
+     * been prepared using {@link org.apache.xml.security.utils.XMLUtils#circumventBug2650(
+     * org.w3c.dom.Document)}.
+     * 
+     * @param E
+     * @param ns
+     * @return the Attr[]s to be outputted
+     * @throws CanonicalizationException
+     */
+    Iterator<Attr> handleAttributes(Element E,  NameSpaceSymbTable ns) 
+        throws CanonicalizationException {    
+        // result will contain the attrs which have to be outputted
+        xmlattrStack.push(ns.getLevel());
+        boolean isRealVisible = isVisibleDO(E, ns.getLevel()) == 1;    
+        NamedNodeMap attrs = null;
+        int attrsLength = 0;
+        if (E.hasAttributes()) {
+            attrs = E.getAttributes();
+            attrsLength = attrs.getLength();
+        }
+
+        SortedSet<Attr> result = this.result;       
+        result.clear();
+
+        for (int i = 0; i < attrsLength; i++) {
+            Attr N = (Attr) attrs.item(i);
+            String NUri = N.getNamespaceURI();
+
+            if (!XMLNS_URI.equals(NUri)) {
+                //A non namespace definition node.
+                if (XML_LANG_URI.equals(NUri)) {
+                    xmlattrStack.addXmlnsAttr(N);
+                } else if (isRealVisible){
+                    //The node is visible add the attribute to the list of output attributes.
+                    result.add(N);
+                } 
+                //keep working
+                continue;
+            }
+
+            String NName = N.getLocalName();
+            String NValue = N.getValue();              
+            if ("xml".equals(NName) && XML_LANG_URI.equals(NValue)) {
+                /* except omit namespace node with local name xml, which defines
+                 * the xml prefix, if its string value is http://www.w3.org/XML/1998/namespace.
+                 */
+                continue;
+            }
+            //add the prefix binding to the ns symb table.
+            //ns.addInclusiveMapping(NName,NValue,N,isRealVisible);          
+            if (isVisible(N))  {
                 if (!isRealVisible && ns.removeMappingIfRender(NName)) {
-                        continue;
+                    continue;
                 } 
-                        //The xpath select this node output it if needed.
+                //The xpath select this node output it if needed.
                 //Node n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible);
-                Node n=ns.addMappingAndRender(NName,NValue,N);
-                        if (n!=null) {
-                                        result.add(n);
+                Node n = ns.addMappingAndRender(NName, NValue, N);
+                if (n != null) {
+                    result.add((Attr)n);
                     if (C14nHelper.namespaceIsRelative(N)) {
-                       Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
-                       throw new CanonicalizationException(
-                          "c14n.Canonicalizer.RelativeNamespace", exArgs);
-                   }
-                         }
-        } else {
+                        Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
+                        throw new CanonicalizationException(
+                            "c14n.Canonicalizer.RelativeNamespace", exArgs
+                        );
+                    }
+                }
+            } else {
                 if (isRealVisible && !XMLNS.equals(NName)) {
-                        ns.removeMapping(NName);	
+                    ns.removeMapping(NName);	
                 } else {
-                        ns.addMapping(NName,NValue,N);
+                    ns.addMapping(NName,NValue,N);
                 }
+            }
         }
-    }
-    if (isRealVisible) {    	           
-        //The element is visible, handle the xmlns definition        
-        Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
-        Node n=null;
-        if (xmlns == null) {
+        if (isRealVisible) {    	           
+            //The element is visible, handle the xmlns definition        
+            Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
+            Node n = null;
+            if (xmlns == null) {
                 //No xmlns def just get the already defined.
-                n=ns.getMapping(XMLNS);        		
-        } else if ( !isVisible(xmlns)) {
+                n = ns.getMapping(XMLNS);        		
+            } else if (!isVisible(xmlns)) {
                 //There is a definition but the xmlns is not selected by the xpath.
                 //then xmlns=""
-                n=ns.addMappingAndRender(XMLNS,"",nullNode);        	    		      	
+                n = ns.addMappingAndRender(XMLNS, "", nullNode);        	    		      	
+            }
+            //output the xmlns def if needed.
+            if (n != null) {
+                result.add((Attr)n);
+            }
+            //Float all xml:* attributes of the unselected parent elements to this one. 
+            //addXmlAttributes(E,result);
+            xmlattrStack.getXmlnsAttr(result);
+            ns.getUnrenderedNodes(result);
         }
-        //output the xmlns def if needed.
-        if (n!=null) {
-                        result.add(n);
-        }
-        //Float all xml:* attributes of the unselected parent elements to this one. 
-        //addXmlAttributes(E,result);
-        xmlattrStack.getXmlnsAttr(result);
-        ns.getUnrenderedNodes(result);
-        
+
+        return result.iterator();
     }
     
-    return result.iterator();
-   }
-   /**
-    * Always throws a CanonicalizationException because this is inclusive c14n.
-    *
-    * @param xpathNodeSet
-    * @param inclusiveNamespaces
-    * @return none it always fails
-    * @throws CanonicalizationException always
-    */
-   public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet, String inclusiveNamespaces)
-           throws CanonicalizationException {
-
-      /** $todo$ well, should we throw UnsupportedOperationException ? */
-      throw new CanonicalizationException(
-         "c14n.Canonicalizer.UnsupportedOperation");
-   }
-
-   /**
-    * Always throws a CanonicalizationException because this is inclusive c14n.
-    *
-    * @param rootNode
-    * @param inclusiveNamespaces
-    * @return none it always fails
-    * @throws CanonicalizationException
-    */
-   public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
-           throws CanonicalizationException {
-
-      /** $todo$ well, should we throw UnsupportedOperationException ? */
-      throw new CanonicalizationException(
-         "c14n.Canonicalizer.UnsupportedOperation");
-   }
-   void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
-           if (!input.isNeedsToBeExpanded()) 
-                   return;
-           Document doc = null;
-       if (input.getSubNode() != null) {
-           doc=XMLUtils.getOwnerDocument(input.getSubNode());
-       } else {
-           doc=XMLUtils.getOwnerDocument(input.getNodeSet());
-       }
-           XMLUtils.circumventBug2650(doc);
-                
-   }
-   
-   void handleParent(Element e, NameSpaceSymbTable ns) {
-           if (!e.hasAttributes()) {
-                        return;
-           }
-           xmlattrStack.push(-1);
-           NamedNodeMap attrs = e.getAttributes();
-           int attrsLength = attrs.getLength();
-           for (int i = 0; i < attrsLength; i++) {
-                   Attr N = (Attr) attrs.item(i);
-                   if (!Constants.NamespaceSpecNS.equals(N.getNamespaceURI())) {
-                           //Not a namespace definition, ignore.
-                           if (XML_LANG_URI.equals(N.getNamespaceURI())) {
-                                   xmlattrStack.addXmlnsAttr(N);
-                           }
-                           continue;
-                   }
-
-                   String NName=N.getLocalName();
-                   String NValue=N.getNodeValue();
-                   if (XML.equals(NName)
-                                   && Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
-                                continue;
-                   }            
-                   ns.addMapping(NName,NValue,N);             
-           }
-   }
+    /**
+     * Always throws a CanonicalizationException because this is inclusive c14n.
+     *
+     * @param xpathNodeSet
+     * @param inclusiveNamespaces
+     * @return none it always fails
+     * @throws CanonicalizationException always
+     */
+    public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
+        throws CanonicalizationException {
+
+        /** $todo$ well, should we throw UnsupportedOperationException ? */
+        throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
+    }
+
+    /**
+     * Always throws a CanonicalizationException because this is inclusive c14n.
+     *
+     * @param rootNode
+     * @param inclusiveNamespaces
+     * @return none it always fails
+     * @throws CanonicalizationException
+     */
+    public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
+        throws CanonicalizationException {
+
+        /** $todo$ well, should we throw UnsupportedOperationException ? */
+        throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
+    }
+    
+    void circumventBugIfNeeded(XMLSignatureInput input) 
+        throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
+        if (!input.isNeedsToBeExpanded()) {
+            return;
+        }
+        Document doc = null;
+        if (input.getSubNode() != null) {
+            doc = XMLUtils.getOwnerDocument(input.getSubNode());
+        } else {
+            doc = XMLUtils.getOwnerDocument(input.getNodeSet());
+        }
+        XMLUtils.circumventBug2650(doc);
+    }
+
+    void handleParent(Element e, NameSpaceSymbTable ns) {
+        if (!e.hasAttributes()) {
+            return;
+        }
+        xmlattrStack.push(-1);
+        NamedNodeMap attrs = e.getAttributes();
+        int attrsLength = attrs.getLength();
+        for (int i = 0; i < attrsLength; i++) {
+            Attr N = (Attr) attrs.item(i);
+            if (!Constants.NamespaceSpecNS.equals(N.getNamespaceURI())) {
+                //Not a namespace definition, ignore.
+                if (XML_LANG_URI.equals(N.getNamespaceURI())) {
+                    xmlattrStack.addXmlnsAttr(N);
+                }
+                continue;
+            }
+
+            String NName = N.getLocalName();
+            String NValue = N.getNodeValue();
+            if (XML.equals(NName) && Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
+                continue;
+            }            
+            ns.addMapping(NName, NValue, N);             
+        }
+    }
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java?rev=1073694&r1=1073693&r2=1073694&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java Wed Feb 23 10:55:07 2011
@@ -60,9 +60,9 @@ public abstract class Canonicalizer20010
       * This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
       * the inclusive namespaces.
       */
-    TreeSet _inclusiveNSSet = new TreeSet();
-    static final String XMLNS_URI=Constants.NamespaceSpecNS;
-    final SortedSet result = new TreeSet(COMPARE);
+    TreeSet<String> inclusiveNSSet = new TreeSet<String>();
+    static final String XMLNS_URI = Constants.NamespaceSpecNS;
+    final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
 
     /**
      * Constructor Canonicalizer20010315Excl
@@ -93,8 +93,9 @@ public abstract class Canonicalizer20010
      * 
      * @throws CanonicalizationException
      */
-    public byte[] engineCanonicalizeSubTree(Node rootNode,
-        String inclusiveNamespaces) throws CanonicalizationException {
+    public byte[] engineCanonicalizeSubTree(
+        Node rootNode, String inclusiveNamespaces
+    ) throws CanonicalizationException {
         return engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, null);
     }
 
@@ -106,10 +107,11 @@ public abstract class Canonicalizer20010
      * @return the rootNode c14n.
      * @throws CanonicalizationException
      */
-    public byte[] engineCanonicalizeSubTree(Node rootNode,
-        String inclusiveNamespaces, Node excl) throws CanonicalizationException{
-        this._inclusiveNSSet = 
-            (TreeSet) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
+    public byte[] engineCanonicalizeSubTree(
+        Node rootNode, String inclusiveNamespaces, Node excl
+    ) throws CanonicalizationException{
+        this.inclusiveNSSet = 
+            (TreeSet<String>) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
         return super.engineCanonicalizeSubTree(rootNode, excl);
     }
 
@@ -120,10 +122,11 @@ public abstract class Canonicalizer20010
      * @return the rootNode c14n.
      * @throws CanonicalizationException
      */
-    public byte[] engineCanonicalize(XMLSignatureInput rootNode,
-        String inclusiveNamespaces) throws CanonicalizationException {
-        this._inclusiveNSSet = 
-            (TreeSet) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
+    public byte[] engineCanonicalize(
+        XMLSignatureInput rootNode, String inclusiveNamespaces
+    ) throws CanonicalizationException {
+        this.inclusiveNSSet = 
+            (TreeSet<String>) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
         return super.engineCanonicalize(rootNode);
     }
  
@@ -133,12 +136,11 @@ public abstract class Canonicalizer20010
      * @param E
      * @throws CanonicalizationException
      */
-    Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+    @SuppressWarnings("unchecked")
+    Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
         throws CanonicalizationException {
-        // System.out.println("During the traversal, I encountered " +
-        // XMLUtils.getXPath(E));
         // result will contain the attrs which have to be outputted
-        SortedSet result = this.result;       
+        SortedSet<Attr> result = this.result;       
         result.clear();
         NamedNodeMap attrs = null;
 
@@ -149,7 +151,7 @@ public abstract class Canonicalizer20010
         }
         // The prefix visibly utilized(in the attribute or in the name) in 
         // the element
-        SortedSet visiblyUtilized = (SortedSet) _inclusiveNSSet.clone();
+        SortedSet<String> visiblyUtilized = (SortedSet<String>) inclusiveNSSet.clone();
 
         for (int i = 0; i < attrsLength; i++) {
             Attr N = (Attr) attrs.item(i);
@@ -159,8 +161,7 @@ public abstract class Canonicalizer20010
                 // The Element is output element, add the prefix (if used) to 
                 // visibyUtilized
                 String prefix = N.getPrefix();
-                if (prefix != null && (!prefix.equals(XML) 
-                    && !prefix.equals(XMLNS))) {
+                if (prefix != null && (!prefix.equals(XML) && !prefix.equals(XMLNS))) {
                     visiblyUtilized.add(prefix);
                 }					
                 // Add to the result.
@@ -195,9 +196,9 @@ public abstract class Canonicalizer20010
         visiblyUtilized.add(prefix);
 
         // This can be optimezed by I don't have time
-        Iterator it = visiblyUtilized.iterator();
+        Iterator<String> it = visiblyUtilized.iterator();
         while (it.hasNext()) {
-            String s = (String) it.next();
+            String s = it.next();
             Attr key = ns.getMapping(s);
             if (key == null) {
                 continue;
@@ -215,11 +216,11 @@ public abstract class Canonicalizer20010
      * @param inclusiveNamespaces
      * @throws CanonicalizationException
      */
-    public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet,
-        String inclusiveNamespaces) throws CanonicalizationException {
-                
-        this._inclusiveNSSet = 
-            (TreeSet) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
+    public byte[] engineCanonicalizeXPathNodeSet(
+        Set<Node> xpathNodeSet, String inclusiveNamespaces
+    ) throws CanonicalizationException {
+        this.inclusiveNSSet = 
+            (TreeSet<String>) InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
         return super.engineCanonicalizeXPathNodeSet(xpathNodeSet);
     }
         
@@ -228,10 +229,11 @@ public abstract class Canonicalizer20010
      * @param E
      * @throws CanonicalizationException
      */
-    final Iterator handleAttributes(Element E, NameSpaceSymbTable ns)
+    @SuppressWarnings("unchecked")
+    final Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
         throws CanonicalizationException {
         // result will contain the attrs which have to be outputted
-        SortedSet result = this.result;       
+        SortedSet<Attr> result = this.result;       
         result.clear();
         NamedNodeMap attrs = null;
         int attrsLength = 0;
@@ -241,11 +243,11 @@ public abstract class Canonicalizer20010
         }
         // The prefix visibly utilized (in the attribute or in the name) in 
         // the element
-        Set visiblyUtilized = null;
+        Set<String> visiblyUtilized = null;
         // It's the output selected.
         boolean isOutputElement = isVisibleDO(E, ns.getLevel()) == 1;
         if (isOutputElement) {
-            visiblyUtilized = (Set) this._inclusiveNSSet.clone();
+            visiblyUtilized = (Set<String>) this.inclusiveNSSet.clone();
         }
 
         for (int i = 0; i < attrsLength; i++) {
@@ -261,8 +263,7 @@ public abstract class Canonicalizer20010
                     // The Element is output element, add the prefix (if used) 
                     // to visibyUtilized
                     String prefix = N.getPrefix();
-                    if (prefix != null && (!prefix.equals(XML) 
-                        && !prefix.equals(XMLNS))) {
+                    if (prefix != null && (!prefix.equals(XML) && !prefix.equals(XMLNS))) {
                         visiblyUtilized.add(prefix);
                     }					
                     // Add to the result.
@@ -278,11 +279,11 @@ public abstract class Canonicalizer20010
             String NNodeValue = N.getNodeValue();
 
             if (!isOutputElement && isVisible(N) 
-                && _inclusiveNSSet.contains(NName) 
+                && inclusiveNSSet.contains(NName) 
                 && !ns.removeMappingIfRender(NName)) {
                 Node n = ns.addMappingAndRender(NName, NNodeValue, N);
                 if (n != null) {
-                    result.add(n);
+                    result.add((Attr)n);
                     if (C14nHelper.namespaceIsRelative(N)) {
                         Object exArgs[] = 
                             { E.getTagName(), NName, N.getNodeValue() };
@@ -322,11 +323,11 @@ public abstract class Canonicalizer20010
             } else {
                 visiblyUtilized.add(XMLNS);
             }									
-            // This can be optimezed by I don't have time
-            // visiblyUtilized.addAll(this._inclusiveNSSet);
-            Iterator it = visiblyUtilized.iterator();
+            // This can be optimized by I don't have time
+            // visiblyUtilized.addAll(this.inclusiveNSSet);
+            Iterator<String> it = visiblyUtilized.iterator();
             while (it.hasNext()) {
-                String s = (String) it.next();
+                String s = it.next();
                 Attr key = ns.getMapping(s);
                 if (key == null) {
                     continue;
@@ -341,7 +342,7 @@ public abstract class Canonicalizer20010
     void circumventBugIfNeeded(XMLSignatureInput input) 
         throws CanonicalizationException, ParserConfigurationException, 
                IOException, SAXException {
-        if (!input.isNeedsToBeExpanded() || _inclusiveNSSet.isEmpty()) {
+        if (!input.isNeedsToBeExpanded() || inclusiveNSSet.isEmpty()) {
             return;
         }
         Document doc = null;