You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/01/25 20:43:00 UTC

cvs commit: xml-crimson/src/org/apache/crimson/tree AttributeSet.java ElementNode.java

edwingo     01/01/25 11:42:57

  Modified:    src/org/apache/crimson/tree AttributeSet.java
                        ElementNode.java
  Log:
  Element.setAttributeNodeNS() should not allow adding an attribute which
  belongs to another Element
  
  Revision  Changes    Path
  1.6       +10 -3     xml-crimson/src/org/apache/crimson/tree/AttributeSet.java
  
  Index: AttributeSet.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/AttributeSet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AttributeSet.java	2001/01/24 01:58:01	1.5
  +++ AttributeSet.java	2001/01/25 19:42:46	1.6
  @@ -1,5 +1,5 @@
   /*
  - * $Id: AttributeSet.java,v 1.5 2001/01/24 01:58:01 edwingo Exp $
  + * $Id: AttributeSet.java,v 1.6 2001/01/25 19:42:46 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -79,7 +79,7 @@
    * document or was instead defaulted by attribute processing.
    *
    * @author David Brownell
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   final
   class AttributeSet implements NamedNodeMap, XmlWritable
  @@ -369,19 +369,26 @@
               throw new DomEx(DomEx.INUSE_ATTRIBUTE_ERR);
           }
   
  -        for (int i = 0; i < list.size(); i++) {
  +        int length = list.size();
  +        for (int i = 0; i < length; i++) {
               AttributeNode oldNode = (AttributeNode) item(i);
               String localName = oldNode.getLocalName();
               String namespaceURI = oldNode.getNamespaceURI();
               if (attr.getLocalName().equals(localName)
                   && attr.getNamespaceURI().equals(namespaceURI)) {
                   // Found a matching node so replace it
  +                if (oldNode.isReadonly()) {
  +                    throw new DomEx(DomEx.NO_MODIFICATION_ALLOWED_ERR);
  +                }
  +                attr.setOwnerElement(ownerElement);
                   list.setElementAt(attr, i);
  +		oldNode.setOwnerElement(null);
                   return oldNode;
               }
           }
   
           // Append instead of replace
  +        attr.setOwnerElement(ownerElement);
           list.addElement(attr);
           return null;
       }
  
  
  
  1.3       +3 -3      xml-crimson/src/org/apache/crimson/tree/ElementNode.java
  
  Index: ElementNode.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/ElementNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementNode.java	2001/01/24 03:37:16	1.2
  +++ ElementNode.java	2001/01/25 19:42:50	1.3
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ElementNode.java,v 1.2 2001/01/24 03:37:16 edwingo Exp $
  + * $Id: ElementNode.java,v 1.3 2001/01/25 19:42:50 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -98,7 +98,7 @@
    * @see XmlDocumentBuilder
    *
    * @author David Brownell
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class ElementNode extends NamespacedNode implements ElementEx
   {
  @@ -486,7 +486,7 @@
           }
   
           // Note: ownerElement of newAttr is both checked and set in the
  -        // following call to AttributeSet.setNamedItem(Node)
  +        // following call to AttributeSet.setNamedItemNS(Node)
   	return (Attr)attributes.setNamedItemNS(newAttr);
       }