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 2004/09/18 18:49:44 UTC

cvs commit: xml-security/src/org/apache/xml/security/c14n/implementations Canonicalizer20010315.java NameSpaceSymbTable.java CanonicalizerBase.java Canonicalizer20010315Excl.java

raul        2004/09/18 09:49:44

  Modified:    src/org/apache/xml/security/c14n/implementations
                        Canonicalizer20010315.java NameSpaceSymbTable.java
                        CanonicalizerBase.java
                        Canonicalizer20010315Excl.java
  Log:
  Little refactor & clean-up in order to prepare for using wrapped digester/signing streams
  
  Revision  Changes    Path
  1.33      +31 -34    xml-security/src/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java
  
  Index: Canonicalizer20010315.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Canonicalizer20010315.java	3 Aug 2004 18:01:23 -0000	1.32
  +++ Canonicalizer20010315.java	18 Sep 2004 16:49:44 -0000	1.33
  @@ -44,7 +44,7 @@
    * @version $Revision$
    */
   public abstract class Canonicalizer20010315 extends CanonicalizerBase {
  -
  +	boolean firstCall=true;
      /**
       * Constructor Canonicalizer20010315
       *
  @@ -70,11 +70,11 @@
       */
      Iterator handleAttributesSubtree(Element E,  NameSpaceSymbTable ns )
              throws CanonicalizationException {
  -
  -      boolean isRoot = E == this._rootNodeOfC14n;
  -
  +   	  if (!E.hasAttributes() && !firstCall) {
  +         return null; 
  +      }
         // result will contain the attrs which have to be outputted
  -      SortedSet result = new TreeSet(COMPARE);
  +      SortedSet result = new TreeSet(COMPARE);      
         NamedNodeMap attrs = E.getAttributes();
         int attrsLength = attrs.getLength();      
               
  @@ -109,13 +109,13 @@
             }        
         }
               	   
  -      if (isRoot) {
  +      if (firstCall) {
         	//It is the first node of the subtree
         	//Obtain all the namespaces defined in the parents, and added to the output.
  -      	List s1=ns.getUnrenderedNodes();    
  -      	result.addAll(s1);      		             
  +      	ns.getUnrenderedNodes(result);          	      		            
         	//output the attributes in the xml namespace.
   		addXmlAttributesSubtree(E, result);
  +        firstCall=false;
         } 
         
         return result.iterator();
  @@ -138,10 +138,12 @@
                       (ancestor != null)
                       && (ancestor.getNodeType() == Node.ELEMENT_NODE);
                       ancestor = ancestor.getParentNode()) {
  -
  +               Element el=((Element) ancestor);
  +               if (!el.hasAttributes()) {
  +                    continue;
  +               }
                  // for all ancestor elements
  -               NamedNodeMap ancestorAttrs =
  -                  ((Element) ancestor).getAttributes();
  +               NamedNodeMap ancestorAttrs = el.getAttributes();
   
                  for (int i = 0; i < ancestorAttrs.getLength(); i++) {
                     // for all attributes in the ancestor element
  @@ -166,11 +168,8 @@
               }
            }
   
  -         Iterator it = loa.values().iterator();
  -
  -         while (it.hasNext()) {
  -            result.add(it.next());
  -         }
  +         result.addAll( loa.values());
  +         
         }
   
      /**
  @@ -187,10 +186,14 @@
       */
      Iterator handleAttributes(Element E,  NameSpaceSymbTable ns ) throws CanonicalizationException {    
       // result will contain the attrs which have to be outputted
  +    boolean isRealVisible=this._xpathNodeSet.contains(E);    
  +    NamedNodeMap attrs = null;
  +    int attrsLength = 0;
  +    if (E.hasAttributes()) {
  +        attrs=E.getAttributes();
  +       attrsLength= attrs.getLength();
  +    }
       
  -    NamedNodeMap attrs = E.getAttributes();
  -    int attrsLength = attrs.getLength();
  -    boolean isRealVisible=this._xpathNodeSet.contains(E);
       
       SortedSet result = new TreeSet(COMPARE);
       
  @@ -223,10 +226,7 @@
          //ns.addInclusiveMapping(NName,NValue,N,isRealVisible);          
   	    if  (this._xpathNodeSet.contains(N))  {
   			    //The xpath select this node output it if needed.
  -	    		Node n=null;
  -	    		
  -	    		n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible); //getMappingInclusive(NName,!isRealVisible);
  -	    		
  +	    		Node n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible); 	    		
   		 	 	if (n!=null) {
   		 	 		result.add(n);
                       if (C14nHelper.namespaceIsRelative(N)) {
  @@ -291,10 +291,12 @@
                       (ancestor != null)
                       && (ancestor.getNodeType() == Node.ELEMENT_NODE);
                       ancestor = ancestor.getParentNode()) {
  -
  +            	Element el=((Element) ancestor);
  +                if (!el.hasAttributes()) {
  +                	continue;
  +                }
                  // for all ancestor elements
  -               NamedNodeMap ancestorAttrs =
  -                  ((Element) ancestor).getAttributes();
  +               NamedNodeMap ancestorAttrs =el.getAttributes();
   
                  for (int i = 0; i < ancestorAttrs.getLength(); i++) {
   
  @@ -319,13 +321,8 @@
                  }
               }
            }
  -
  -         Iterator it = loa.values().iterator();
  -
  -         while (it.hasNext()) {
  -            result.add(it.next());
  -         }
  -      
  +         result.addAll(loa.values());
  +               
   }
   
      /**
  
  
  
  1.4       +5 -5      xml-security/src/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java
  
  Index: NameSpaceSymbTable.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NameSpaceSymbTable.java	15 Sep 2004 20:26:52 -0000	1.3
  +++ NameSpaceSymbTable.java	18 Sep 2004 16:49:44 -0000	1.4
  @@ -17,6 +17,7 @@
   package org.apache.xml.security.c14n.implementations;
   
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  @@ -57,10 +58,10 @@
       /**
   	 * Get all the unrendered nodes in the name space.
   	 * For Inclusive rendering
  -     * @return the list of unrendered xmlns definitions.
  +     * @param result the list where to fill the unrendered xmlns definitions.
   	 **/       
  -	public  List getUnrenderedNodes() {		
  -	   List result=new ArrayList();
  +	public  void getUnrenderedNodes(Collection result) {		
  +	   //List result=new ArrayList();
   	   Iterator it=symb.entrySet().iterator();
   	   while (it.hasNext()) {	   	   
   	   		NameSpaceSymbEntry n=(NameSpaceSymbEntry)((Map.Entry)it.next()).getValue();
  @@ -69,8 +70,7 @@
   	   			result.add(n.n);
   	   			n.rendered=true;
   	   		}
  -	   }
  -	   return result;
  +	   }	   
   	}
   	
   	/**
  
  
  
  1.8       +78 -191   xml-security/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
  
  Index: CanonicalizerBase.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CanonicalizerBase.java	3 Aug 2004 18:01:23 -0000	1.7
  +++ CanonicalizerBase.java	18 Sep 2004 16:49:44 -0000	1.8
  @@ -22,6 +22,7 @@
   import java.io.IOException;
   import java.io.OutputStream;
   import java.io.UnsupportedEncodingException;
  +import java.nio.ByteOrder;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  @@ -29,6 +30,11 @@
   import java.util.Set;
   import java.util.TreeSet;
   
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.FactoryConfigurationError;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.apache.xml.security.c14n.CanonicalizationException;
   import org.apache.xml.security.c14n.CanonicalizerSpi;
   import org.apache.xml.security.c14n.helper.AttrCompare;
  @@ -36,6 +42,7 @@
   import org.apache.xml.security.utils.XMLUtils;
   import org.w3c.dom.Attr;
   import org.w3c.dom.Comment;
  +import org.w3c.dom.DOMException;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.NamedNodeMap;
  @@ -64,30 +71,33 @@
      private static final byte[] _LT_ = {'&','l','t',';'};
      private static final byte[] _END_TAG = {'<','/'};
      private static final byte[] _AMP_ = {'&','a','m','p',';'};
  +   final static AttrCompare COMPARE=new AttrCompare();
  +   final static String XML="xml";
  +   final static String XMLNS="xmlns";
  +   final static byte[] equalsStr= {'=','\"'};
  +   static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
  +   static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
  +   static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
  +   //The null xmlns definiton.
  +   protected static final Attr nullNode;
  +   static {
  +    try {
  +        nullNode=DocumentBuilderFactory.newInstance().
  +            newDocumentBuilder().newDocument().createAttributeNS(Constants.NamespaceSpecNS,XMLNS);
  +        nullNode.setValue("");
  +    } catch (Exception e) {
  +        throw new RuntimeException("Unable to create nullNode",e);
  +    }
  +   }
      
  -   boolean _includeComments = false;
  +   boolean _includeComments;
      Set _xpathNodeSet = null;
  -   Document _doc = null;
  -   Element _documentElement = null;
  -   Node _rootNodeOfC14n = null;
      /**
       * The node to be skiped/excluded from the DOM tree 
       * in subtree canonicalizations.
       */
      Node _excludeNode =null;
  -   OutputStream _writer = null;
  -
  -   /**
  -    * This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
  -    * the inclusive namespaces.
  -    */
  -   TreeSet _inclusiveNSSet = null;
  -
  -   final static AttrCompare COMPARE=new AttrCompare();
  -   final static String XML="xml";
  -   final static String XMLNS="xmlns";
  -   final static byte[] equalsStr= {'=','\"'};
  -   //J+
  +   final ByteArrayOutputStream _writer = new ByteArrayOutputStream();//null;
   
      /**
       * Constructor CanonicalizerBase
  @@ -118,36 +128,20 @@
       public byte[] engineCanonicalizeSubTree(Node rootNode,Node excludeNode)
       throws CanonicalizationException {
       	this._excludeNode = excludeNode;
  -      this._rootNodeOfC14n = rootNode;
  -      this._doc = XMLUtils.getOwnerDocument(this._rootNodeOfC14n);
  -      this._documentElement = this._doc.getDocumentElement();
  -     
  -      try {
  -         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -         this._writer =// new BufferedWriter(new OutputStreamWriter(baos, Canonicalizer.ENCODING));
  -         	baos;
  +        try {
            NameSpaceSymbTable ns=new NameSpaceSymbTable();
  -         if (this._rootNodeOfC14n instanceof Element) {
  +         if (rootNode instanceof Element) {
            	//Fills the nssymbtable with the definitions of the parent of the root subnode
  -         	getParentNameSpaces((Element)this._rootNodeOfC14n,ns);
  +         	getParentNameSpaces((Element)rootNode,ns);
            }
  -         this.canonicalizeSubTree(this._rootNodeOfC14n,ns);
  +         this.canonicalizeSubTree(rootNode,ns);
            this._writer.close();
  -
  -         return baos.toByteArray();
  +         return this._writer.toByteArray();
         } catch (UnsupportedEncodingException ex) {
            throw new CanonicalizationException("empty", ex);
         } catch (IOException ex) {
            throw new CanonicalizationException("empty", ex);
  -      } finally {
  -
  -         // mark contents for garbage collector
  -         this._rootNodeOfC14n = null;
  -         this._excludeNode=null;
  -         this._doc = null;
  -         this._documentElement = null;
  -         this._writer = null;
  -      }
  +      } 
      }
   
      
  @@ -162,9 +156,7 @@
      final void canonicalizeSubTree(Node currentNode, NameSpaceSymbTable ns)
              throws CanonicalizationException, IOException {
   
  -      int currentNodeType = currentNode.getNodeType();
  -
  -      switch (currentNodeType) {
  +      switch (currentNode.getNodeType()) {
   
         case Node.DOCUMENT_TYPE_NODE :
         default :
  @@ -208,17 +200,17 @@
            //Add a level to the nssymbtable. So latter can be pop-back.
         	 ns.outputNodePush();
            writer.write('<');
  -         writeStringToUtf8(currentElement.getTagName(),writer);
  -         //this._writer.write(currentElement.getTagName().getBytes("UTF8"));
  +         String tagName=currentElement.getTagName();
  +         writeStringToUtf8(tagName,writer);
            
            Iterator attrs = this.handleAttributesSubtree(currentElement,ns);
  -         
  -         // we output all Attrs which are available
  -         //for (int i = 0; i < attrs.length; i++) {
  -         while (attrs.hasNext()) {
  -         	Attr attr = (Attr) attrs.next();
  -            outputAttrToWriter(attr.getNodeName(),
  +         if (attrs!=null) {
  +         	//we output all Attrs which are available
  +         	while (attrs.hasNext()) {
  +         		Attr attr = (Attr) attrs.next();
  +         		outputAttrToWriter(attr.getNodeName(),
                                       attr.getNodeValue(), writer);
  +         	}
            }
   
            writer.write('>');
  @@ -231,8 +223,7 @@
            }
   
            writer.write(_END_TAG);
  -         writeStringToUtf8(currentElement.getTagName(),writer);
  -         //this._writer.write(currentElement.getTagName().getBytes("UTF8"));
  +         writeStringToUtf8(tagName,writer);        
            writer.write('>');
            //We fineshed with this level, pop to the previous definitions.
            ns.outputNodePop();
  @@ -240,12 +231,6 @@
         }
      }
   
  -   //J-
  -   static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
  -   static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
  -   static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
  -   //J+
  -
      /**
       * Checks whether a Comment or ProcessingInstruction is before or after the
       * document element. This is needed for prepending or appending "\n"s.
  @@ -257,27 +242,16 @@
       * @see #NODE_AFTER_DOCUMENT_ELEMENT
       */
      final static int getPositionRelativeToDocumentElement(Node currentNode) {
  -
  -      if (currentNode == null) {
  -         return CanonicalizerBase.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
  -      }
  -
  -      Document doc = currentNode.getOwnerDocument();
  -
  -      if (currentNode.getParentNode() != doc) {
  +            
  +      if ((currentNode == null) || 
  +            (currentNode.getParentNode().getNodeType() != Node.DOCUMENT_NODE) ) {
            return CanonicalizerBase.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
         }
  -
  -      Element documentElement = doc.getDocumentElement();
  -
  -      if (documentElement == null) {
  +      Element documentElement = currentNode.getOwnerDocument().getDocumentElement();
  +      if ( (documentElement == null)  || (documentElement == currentNode) ){
            return CanonicalizerBase.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
         }
  -
  -      if (documentElement == currentNode) {
  -         return CanonicalizerBase.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
  -      }
  -
  +      
         for (Node x = currentNode; x != null; x = x.getNextSibling()) {
            if (x == documentElement) {
               return CanonicalizerBase.NODE_BEFORE_DOCUMENT_ELEMENT;
  @@ -286,57 +260,6 @@
   
         return CanonicalizerBase.NODE_AFTER_DOCUMENT_ELEMENT;
      }
  -
  -   /**
  -    * Method engineCanonicalizeXPathNodeSet
  -    * @inheritDoc
  -    * @param xpathNodeSet
  -    * @param inclusiveNamespaces
  -    * @throws CanonicalizationException
  -    */
  -   public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet, String inclusiveNamespaces)
  -           throws CanonicalizationException {       
  -      this._xpathNodeSet = xpathNodeSet;
  -
  -      if (this._xpathNodeSet.size() == 0) {
  -         return new byte[0];
  -      }
  -
  -      {
  -
  -         // get only a single node as anchor to fetch the owner document
  -         Node n = (Node) this._xpathNodeSet.iterator().next();
  -
  -         this._doc = XMLUtils.getOwnerDocument(n);
  -         this._documentElement = this._doc.getDocumentElement();
  -         if (nullNode==null) {
  -         	nullNode=
  -         		_doc.createAttributeNS(Constants.NamespaceSpecNS,XMLNS);
  -         	nullNode.setValue("");
  -         }
  -      }
  -
  -      try {
  -         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -
  -         this._writer = //new BufferedWriter(new OutputStreamWriter(baos, Canonicalizer.ENCODING));
  -            baos;
  -         this.canonicalizeXPathNodeSet(this._doc, new  NameSpaceSymbTable());
  -         this._writer.close();
  -
  -         return baos.toByteArray();
  -      } catch (UnsupportedEncodingException ex) {
  -         throw new CanonicalizationException("empty", ex);
  -      } catch (IOException ex) {
  -         throw new CanonicalizationException("empty", ex);
  -      } finally {
  -         this._xpathNodeSet = null;
  -         this._rootNodeOfC14n = null;
  -         this._doc = null;
  -         this._documentElement = null;
  -         this._writer = null;
  -      }
  -   }
        
      /**
       * Method engineCanonicalizeXPathNodeSet
  @@ -345,42 +268,21 @@
       * @throws CanonicalizationException
       */
      public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet)
  -           throws CanonicalizationException {          	
  -      this._xpathNodeSet = xpathNodeSet;
  -
  -      if (this._xpathNodeSet.size() == 0) {
  -         return new byte[0];
  -      }
  -
  -      if (this._doc == null) {
  -         this._doc = XMLUtils.getOwnerDocument(this._xpathNodeSet);
  -         this._documentElement = this._doc.getDocumentElement();
  -         this._rootNodeOfC14n = this._doc;
  -         nullNode=
  -			_doc.createAttributeNS(Constants.NamespaceSpecNS,XMLNS);
  -		nullNode.setValue("");
  +           throws CanonicalizationException {
  +      if (xpathNodeSet.size() == 0) {
  +        return new byte[0];
         }
  -
  -      try {
  -         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -
  -         this._writer = // new BufferedWriter(new OutputStreamWriter(baos, Canonicalizer.ENCODING));
  -            baos;
  -         this.canonicalizeXPathNodeSet(this._rootNodeOfC14n,new  NameSpaceSymbTable());
  +      this._xpathNodeSet = xpathNodeSet;
  +      try { 
  +         Node rootNodeOfC14n = XMLUtils.getOwnerDocument(this._xpathNodeSet);
  +         this.canonicalizeXPathNodeSet(rootNodeOfC14n,new  NameSpaceSymbTable());
            this._writer.close();
  -
  -         return baos.toByteArray();
  +         return this._writer.toByteArray();
         } catch (UnsupportedEncodingException ex) {
            throw new CanonicalizationException("empty", ex);
         } catch (IOException ex) {
            throw new CanonicalizationException("empty", ex);
  -      } finally {
  -         this._xpathNodeSet = null;
  -         this._rootNodeOfC14n = null;
  -         this._doc = null;
  -         this._documentElement = null;
  -         this._writer = null;
  -      }
  +      } 
      }
   
      /**
  @@ -394,11 +296,9 @@
       */
      final void canonicalizeXPathNodeSet(Node currentNode, NameSpaceSymbTable ns )
              throws CanonicalizationException, IOException {
  - 
  -      int currentNodeType = currentNode.getNodeType();
         boolean currentNodeIsVisible = this._xpathNodeSet.contains(currentNode);
   
  -      switch (currentNodeType) {
  +      switch (currentNode.getNodeType()) {
   
         case Node.DOCUMENT_TYPE_NODE :
         default :
  @@ -418,21 +318,20 @@
            break;
   
         case Node.COMMENT_NODE :
  -         if (this._includeComments
  -                 && this._xpathNodeSet.contains(currentNode)) {           
  +         if (currentNodeIsVisible && this._includeComments) {           
               outputCommentToWriter((Comment) currentNode, this._writer);           
            }
            break;
   
         case Node.PROCESSING_INSTRUCTION_NODE :
  -         if (this._xpathNodeSet.contains(currentNode)) {            
  +         if (currentNodeIsVisible) {            
               outputPItoWriter((ProcessingInstruction) currentNode, this._writer);            
            }
            break;
   
         case Node.TEXT_NODE :
         case Node.CDATA_SECTION_NODE :
  -         if (this._xpathNodeSet.contains(currentNode)) {
  +         if (currentNodeIsVisible) {
               outputTextToWriter(currentNode.getNodeValue(), this._writer);
   
               for (Node nextSibling = currentNode.getNextSibling();
  @@ -441,7 +340,6 @@
                           || (nextSibling.getNodeType()
                               == Node.CDATA_SECTION_NODE));
                       nextSibling = nextSibling.getNextSibling()) {
  -
                  /* The XPath data model allows to select only the first of a
                   * sequence of mixed text and CDATA nodes. But we must output
                   * them all, so we must search:
  @@ -456,12 +354,12 @@
         case Node.ELEMENT_NODE :
            Element currentElement = (Element) currentNode;
         	 OutputStream writer=this._writer;
  +         String tagName=currentElement.getTagName();
            if (currentNodeIsVisible) {
               //This is an outputNode.
            	ns.outputNodePush();
               writer.write('<');
  -            writeStringToUtf8(currentElement.getTagName(),writer);
  -            //this._writer.write(currentElement.getTagName().getBytes("UTF8"));
  +            writeStringToUtf8(tagName,writer);
            } else {
              //Not an outputNode.
            	ns.push(); 	
  @@ -469,11 +367,9 @@
   
            // we output all Attrs which are available
            Iterator attrs = handleAttributes(currentElement,ns);
  -
  -         //for (int i = 0; i < attrs.length; i++) {
            while (attrs.hasNext()) {
               Attr attr = (Attr) attrs.next();
  -            outputAttrToWriter(attr.getNodeName(), attr.getNodeValue(), this._writer);
  +            outputAttrToWriter(attr.getNodeName(), attr.getNodeValue(), writer);
            }
   
            if (currentNodeIsVisible) {
  @@ -489,7 +385,7 @@
   
            if (currentNodeIsVisible) {
               writer.write(_END_TAG);
  -            writeStringToUtf8(currentElement.getTagName(),writer);
  +            writeStringToUtf8(tagName,writer);
               //this._writer.write(currentElement.getTagName().getBytes("UTF8"));
               writer.write('>');
               ns.outputNodePop();
  @@ -525,6 +421,9 @@
      		ListIterator it=parents.listIterator(parents.size());
      		while (it.hasPrevious()) {
      		Element ele=(Element)it.previous();
  +        if (!ele.hasAttributes()) {
  +        	continue;
  +        }
   		NamedNodeMap attrs = ele.getAttributes();
      		int attrsLength = attrs.getLength();
      		 for (int i = 0; i < attrsLength; i++) {
  @@ -545,10 +444,8 @@
      		}
           Attr nsprefix;
           if (((nsprefix=ns.getMappingWithoutRendered("xmlns"))!=null) 
  -                &&
  -                "".equals(nsprefix.getValue())) {
  -                
  -        	ns.addMappingAndRender("xmlns","",nullNode);
  +                && "".equals(nsprefix.getValue())) {
  +             ns.addMappingAndRender("xmlns","",nullNode);
           }
      	}
      /**
  @@ -667,11 +564,9 @@
         writer.write(_BEGIN_PI);
   
         String target = currentPI.getTarget();
  -      //char []c= target.toCharArray();
         int length = target.length();
   
  -      for (int i = 0; i < length; i++) {
  -         //char c = target.charAt(i);
  +      for (int i = 0; i < length; i++) {         
         	 char c=target.charAt(i);
            switch (c) {
   
  @@ -680,8 +575,7 @@
               break;
   
            default :
  -            writeCharToUtf8(c,writer);
  -            //this._writer.write(c[i]);
  +            writeCharToUtf8(c,writer);            
               break;
            }
         }
  @@ -703,7 +597,6 @@
   
               default :
                   writeCharToUtf8(c,writer);
  -               //this._writer.write(c[i]);
                  break;
               }
            }
  @@ -730,8 +623,7 @@
         writer.write(_BEGIN_COMM);
   
         String data = currentComment.getData();
  -      int length = data.length();
  -      //char c[]=data.toCharArray();
  +      int length = data.length();      
   
         for (int i = 0; i < length; i++) {
            char c = data.charAt(i);
  @@ -743,8 +635,7 @@
               break;
   
            default :
  -            writeCharToUtf8(c,writer);
  -            //this._writer.write(c[i]);
  +            writeCharToUtf8(c,writer);            
               break;
            }       
         }
  @@ -764,8 +655,6 @@
       */
      static final void outputTextToWriter(String text, OutputStream writer) throws IOException {
         int length = text.length();
  -   	  //char c[]=text.toCharArray();
  -
         for (int i = 0; i < length; i++) {
            char c = text.charAt(i);
   
  @@ -788,8 +677,7 @@
               break;
   
            default :
  -            writeCharToUtf8(c,writer);
  -            //this._writer.write(c[i]);
  +            writeCharToUtf8(c,writer);;
               break;
            }
         }
  @@ -817,8 +705,7 @@
      abstract Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
      throws CanonicalizationException;
   
  -   //The null xmlns definiton.
  -   protected static Attr nullNode;
  +
      /**
       * @return Returns the _includeComments.
       */
  
  
  
  1.16      +21 -40    xml-security/src/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java
  
  Index: Canonicalizer20010315Excl.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Canonicalizer20010315Excl.java	3 Aug 2004 18:01:23 -0000	1.15
  +++ Canonicalizer20010315Excl.java	18 Sep 2004 16:49:44 -0000	1.16
  @@ -52,6 +52,11 @@
    *          XML Canonicalization, Version 1.0" </a>
    */
   public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
  +    /**
  +      * This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
  +      * the inclusive namespaces.
  +      */
  +    TreeSet _inclusiveNSSet = null;
   	/**
   	 * Constructor Canonicalizer20010315Excl
   	 * 
  @@ -94,41 +99,10 @@
   	 */
   	public byte[] engineCanonicalizeSubTree(Node rootNode,
   			String inclusiveNamespaces,Node excl) throws CanonicalizationException {
  -		this._excludeNode=excl;
  -		this._rootNodeOfC14n = rootNode;
  -		this._doc = XMLUtils.getOwnerDocument(this._rootNodeOfC14n);
  -		this._documentElement = this._doc.getDocumentElement();
  -        if (nullNode==null) {
  -        	nullNode=
  -        		_doc.createAttributeNS(Constants.NamespaceSpecNS,"xmlns");
  -        	nullNode.setValue("");
  -        }
  -		try {
  -			ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -			this._writer = //new BufferedWriter(new OutputStreamWriter(baos, Canonicalizer.ENCODING));
  -                baos;
  +
   			this._inclusiveNSSet = (TreeSet)InclusiveNamespaces
   					.prefixStr2Set(inclusiveNamespaces);			
  -			NameSpaceSymbTable ns= new NameSpaceSymbTable();
  -			if (rootNode instanceof Element) {
  -				CanonicalizerBase.getParentNameSpaces((Element)rootNode,ns);
  -			}
  -			canonicalizeSubTree(rootNode,ns);
  -			//this._writer.flush();
  -			this._writer.close();
  -			return baos.toByteArray();
  -		} catch (UnsupportedEncodingException ex) {
  -			throw new CanonicalizationException("empty", ex);
  -		} catch (IOException ex) {
  -			throw new CanonicalizationException("empty", ex);
  -		} finally {
  -			this._xpathNodeSet = null;
  -			this._inclusiveNSSet = null;
  -			this._rootNodeOfC14n = null;
  -			this._doc = null;
  -			this._documentElement = null;
  -			this._writer = null;
  -		}
  +			return super.engineCanonicalizeSubTree(rootNode,excl);
   	}
    
   	/**
  @@ -143,8 +117,13 @@
   		// XMLUtils.getXPath(E));
   		// result will contain the attrs which have to be outputted
   		SortedSet result = new TreeSet(COMPARE);
  -		NamedNodeMap attrs = E.getAttributes();
  -		int attrsLength = attrs.getLength();
  +		NamedNodeMap attrs=null;
  +        
  +		int attrsLength = 0;
  +        if (E.hasAttributes()) {
  +            attrs = E.getAttributes();
  +        	attrsLength = attrs.getLength();
  +        }
   		//The prefix visibly utilized(in the attribute or in the name) in the element
   		SortedSet visiblyUtilized =(SortedSet) _inclusiveNSSet.clone();
   					
  @@ -233,12 +212,14 @@
   	 */
   	final Iterator handleAttributes(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 = new TreeSet(COMPARE);
  -		NamedNodeMap attrs = E.getAttributes();
  -		int attrsLength = attrs.getLength();
  +		NamedNodeMap attrs = null;
  +		int attrsLength = 0;
  +        if (E.hasAttributes()) {
  +            attrs = E.getAttributes();           
  +        	attrsLength = attrs.getLength();
  +        }
   		//The prefix visibly utilized(in the attribute or in the name) in the element
   		Set visiblyUtilized =null;
   		//It's the output selected.