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/03/16 04:47:15 UTC

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

edwingo     01/03/15 19:47:15

  Modified:    src/org/apache/crimson/tree XmlDocument.java
                        ElementNode2.java AttributeSet.java
  Log:
  Fix Imported element has attribute defined default in original document
  
  Revision  Changes    Path
  1.5       +4 -4      xml-crimson/src/org/apache/crimson/tree/XmlDocument.java
  
  Index: XmlDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/XmlDocument.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XmlDocument.java	2001/03/06 20:46:27	1.4
  +++ XmlDocument.java	2001/03/16 03:47:14	1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: XmlDocument.java,v 1.4 2001/03/06 20:46:27 edwingo Exp $
  + * $Id: XmlDocument.java,v 1.5 2001/03/16 03:47:14 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -129,7 +129,7 @@
    *
    * @author David Brownell
    * @author Rajiv Mordani
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class XmlDocument extends ParentNode implements DocumentEx
   {
  @@ -1254,8 +1254,8 @@
           case DOCUMENT_TYPE_NODE:
               throw new DomEx(DomEx.NOT_SUPPORTED_ERR);
           case ELEMENT_NODE:
  -            // XXX Fix copying of defaulted attributes
  -            node = importedNode.cloneNode(deep);
  +            node = ((ElementNode2) importedNode).createCopyForImportNode(
  +                deep, this);
               break;
           case ENTITY_NODE:
               node = importedNode.cloneNode(deep);
  
  
  
  1.6       +43 -4     xml-crimson/src/org/apache/crimson/tree/ElementNode2.java
  
  Index: ElementNode2.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/ElementNode2.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ElementNode2.java	2001/03/12 23:51:43	1.5
  +++ ElementNode2.java	2001/03/16 03:47:14	1.6
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ElementNode2.java,v 1.5 2001/03/12 23:51:43 edwingo Exp $
  + * $Id: ElementNode2.java,v 1.6 2001/03/16 03:47:14 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -70,7 +70,9 @@
   
   
   /**
  - * Modified version of ElementNode to support DOM Level 2 methods.
  + * Modified version of ElementNode to support DOM Level 2 methods.  This
  + * class is named ElementNode2 for backward compatibility since old DOM
  + * Level 1 apps may have subclassed ElementNode.
    * 
    * This class represents XML elements in a parse tree, and is often
    * subclassed to add custom behaviors.  When an XML Document object
  @@ -117,7 +119,9 @@
           super(namespaceURI, qName);
       }
   
  -    // Used for cloneNode()
  +    /**
  +     * Constructor used for cloneNode()
  +     */
       private ElementNode2(ElementNode2 original) {
           super(original.namespaceURI, original.qName);
           if (original.attributes != null) {
  @@ -129,6 +133,42 @@
           ownerDocument = original.ownerDocument;
       }
   
  +    /**
  +     * @return New ElementNode2 which is a copy of "this" but without
  +     * attributes that are defaulted in the original document.
  +     *
  +     * Used to implement Document.importNode().
  +     */
  +    ElementNode2 createCopyForImportNode(boolean deep,
  +                                         XmlDocument newOwnerDocument)
  +    {
  +        ElementNode2 retval = new ElementNode2(namespaceURI, qName);
  +        if (attributes != null) {
  +            // Copy only "specified" Attr-s
  +            retval.attributes = new AttributeSet(attributes);
  +            retval.attributes.setOwnerElement(retval);
  +        }
  +        retval.userObject = userObject;
  +        retval.ownerDocument = newOwnerDocument;
  +
  +        if (deep) {
  +            for (int i = 0; true; i++) {
  +                Node node = item(i);
  +                if (node == null) {
  +                    break;
  +                }
  +                if (node instanceof ElementNode2) {
  +                    retval.appendChild(
  +                        ((ElementNode2) node).createCopyForImportNode(
  +                            true, newOwnerDocument));
  +                } else {
  +                    retval.appendChild(node.cloneNode(true));
  +                }
  +            }
  +        }
  +        return retval;
  +    }
  +
       static void checkArguments(String namespaceURI, String qualifiedName)
           throws DomEx
       {
  @@ -529,7 +569,6 @@
   	return attr;
       }
   
  -    
       /**
        * Creates a new unparented node whose attributes are the same as
        * this node's attributes; if <em>deep</em> is true, the children
  
  
  
  1.11      +28 -2     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AttributeSet.java	2001/03/09 01:04:26	1.10
  +++ AttributeSet.java	2001/03/16 03:47:14	1.11
  @@ -1,5 +1,5 @@
   /*
  - * $Id: AttributeSet.java,v 1.10 2001/03/09 01:04:26 edwingo Exp $
  + * $Id: AttributeSet.java,v 1.11 2001/03/16 03:47:14 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -80,7 +80,7 @@
    * document or was instead defaulted by attribute processing.
    *
    * @author David Brownell
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   final
   class AttributeSet implements NamedNodeMap, XmlWritable
  @@ -122,6 +122,32 @@
               node = attr.cloneAttributeNode(deep);
               list.addElement (node);
           }
  +    }
  +
  +    /**
  +     * Constructor used to implement Document.importNode().  Only
  +     * "specified" Attr nodes are copied.  Copy is always deep.
  +     */
  +    AttributeSet(AttributeSet original) {
  +        int size = original.getLength();
  +        list = new Vector(size);
  +
  +        for (int i = 0; i < size; i++) {
  +            Node node = original.item(i);
  +
  +            if (!(node instanceof AttributeNode)) {
  +                throw new IllegalArgumentException(((NodeBase)node).
  +                                                   getMessage ("A-003"));
  +            }
  +
  +            AttributeNode attr = (AttributeNode) node;
  +            // Copy only specified attributes
  +            if (attr.getSpecified()) {
  +                node = attr.cloneAttributeNode(true);
  +                list.addElement(node);
  +            }
  +        }
  +        list.trimToSize();
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: crimson-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: crimson-cvs-help@xml.apache.org