You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/05/13 09:38:04 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers AbstractSAXParser.java

neeraj      2003/05/13 00:38:04

  Modified:    java/src/org/apache/xerces/dom Tag: jaxp_1_2_3_branch
                        AttributeMap.java DocumentFragmentImpl.java
               java/src/org/apache/xerces/parsers Tag: jaxp_1_2_3_branch
                        AbstractSAXParser.java
  Log:
  Applying some fixes from main trunk. Thanks to Neil and Elena.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.23.4.1  +19 -14    xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java
  
  Index: AttributeMap.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java,v
  retrieving revision 1.23
  retrieving revision 1.23.4.1
  diff -u -r1.23 -r1.23.4.1
  --- AttributeMap.java	29 Aug 2002 18:34:58 -0000	1.23
  +++ AttributeMap.java	13 May 2003 07:38:03 -0000	1.23.4.1
  @@ -334,23 +334,30 @@
   
           if (hasDefaults() && addDefault) {
               // If there's a default, add it instead
  -
               NamedNodeMapImpl defaults =
                   ((ElementImpl) ownerNode).getDefaultAttributes();
  +
               Node d;
               if (defaults != null &&
                   (d = defaults.getNamedItem(name)) != null &&
                   findNamePoint(name, index+1) < 0) {
  -
  -                NodeImpl clone = (NodeImpl)d.cloneNode(true);
  -                clone.ownerNode = ownerNode;
  -                clone.isOwned(true);
  -                clone.isSpecified(false);
  -                nodes.setElementAt(clone, index);
  -                if (attr.isIdAttribute()) {
  -                    ownerDocument.putIdentifier(clone.getNodeValue(),
  +                    NodeImpl clone = (NodeImpl)d.cloneNode(true);
  +                    if (d.getLocalName() !=null){
  +                            // we must rely on the name to find a default attribute
  +                            // ("test:attr"), but while copying it from the DOCTYPE
  +                            // we should not loose namespace URI that was assigned
  +                            // to the attribute in the instance document.
  +                            ((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
  +                    } 
  +                    clone.ownerNode = ownerNode;
  +                    clone.isOwned(true);
  +                    clone.isSpecified(false);
  +                
  +                    nodes.setElementAt(clone, index);
  +                    if (attr.isIdAttribute()) {
  +                        ownerDocument.putIdentifier(clone.getNodeValue(),
                                                   (ElementImpl)ownerNode);
  -                }
  +                    }
               } else {
                   nodes.removeElementAt(index);
               }
  @@ -444,9 +451,7 @@
                       if (j>=0 && findNamePoint(nodeName, j+1) < 0) {
                           NodeImpl clone = (NodeImpl)d.cloneNode(true);
                           clone.ownerNode = ownerNode;
  -                        // REVISIT: can we assume that if we reach here it is 
  -                        // always attrNSImpl
  -                        if (clone instanceof AttrNSImpl) {
  +                        if (d.getLocalName() != null) {
                               // we must rely on the name to find a default attribute
                               // ("test:attr"), but while copying it from the DOCTYPE
                               // we should not loose namespace URI that was assigned
  
  
  
  1.10.6.1  +49 -2     xml-xerces/java/src/org/apache/xerces/dom/DocumentFragmentImpl.java
  
  Index: DocumentFragmentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DocumentFragmentImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.10.6.1
  diff -u -r1.10 -r1.10.6.1
  --- DocumentFragmentImpl.java	29 Jan 2002 01:15:07 -0000	1.10
  +++ DocumentFragmentImpl.java	13 May 2003 07:38:03 -0000	1.10.6.1
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,6 +59,7 @@
   
   import org.w3c.dom.DocumentFragment;
   import org.w3c.dom.Node;
  +import org.w3c.dom.Text;
   
   /**
    * DocumentFragment is a "lightweight" or "minimal" Document
  @@ -140,4 +141,50 @@
           return "#document-fragment";
       }
       
  +    /**
  +     * Override default behavior to call normalize() on this Node's
  +     * children. It is up to implementors or Node to override normalize()
  +     * to take action.
  +     */
  +    public void normalize() {
  +        // No need to normalize if already normalized.
  +        if (isNormalized()) {
  +            return;
  +        }
  +        if (needsSyncChildren()) {
  +            synchronizeChildren();
  +        }
  +        ChildNode kid, next;
  +
  +        for (kid = firstChild; kid != null; kid = next) {
  +            next = kid.nextSibling;
  +
  +            // If kid is a text node, we need to check for one of two
  +            // conditions:
  +            //   1) There is an adjacent text node
  +            //   2) There is no adjacent text node, but kid is
  +            //      an empty text node.
  +            if ( kid.getNodeType() == Node.TEXT_NODE )
  +            {
  +                // If an adjacent text node, merge it with kid
  +                if ( next!=null && next.getNodeType() == Node.TEXT_NODE )
  +                {
  +                    ((Text)kid).appendData(next.getNodeValue());
  +                    removeChild( next );
  +                    next = kid; // Don't advance; there might be another.
  +                }
  +                else
  +                {
  +                    // If kid is empty, remove it
  +                    if ( kid.getNodeValue().length()==0 )
  +                        removeChild( kid );
  +                }
  +            }
  +
  +            kid.normalize();
  +        }
  +
  +        isNormalized(true);
  +    }
  +
   } // class DocumentFragmentImpl
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.38.2.1  +16 -2     xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java
  
  Index: AbstractSAXParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v
  retrieving revision 1.38
  retrieving revision 1.38.2.1
  diff -u -r1.38 -r1.38.2.1
  --- AbstractSAXParser.java	21 Jan 2003 23:43:36 -0000	1.38
  +++ AbstractSAXParser.java	13 May 2003 07:38:03 -0000	1.38.2.1
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001, 2002 The Apache Software Foundation.
  + * Copyright (c) 2001-2003 The Apache Software Foundation.
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -1172,6 +1172,10 @@
        */
       public void setEntityResolver(EntityResolver resolver) {
   
  +        // not per SAX 1, but per SAX 2.0 and JAXP 1.1 expectations
  +        if(resolver == null) {
  +            throw new NullPointerException();
  +        }
           try {
               fConfiguration.setProperty(ENTITY_RESOLVER,
                                          new EntityResolverWrapper(resolver));
  @@ -1227,6 +1231,10 @@
        */
       public void setErrorHandler(ErrorHandler errorHandler) {
   
  +        // not per SAX 1, but per SAX 2.0 and JAXP 1.1 expectations
  +        if(errorHandler == null) {
  +            throw new NullPointerException();
  +        }
           try {
               fConfiguration.setProperty(ERROR_HANDLER,
                                          new ErrorHandlerWrapper(errorHandler));
  @@ -1301,6 +1309,8 @@
           //          to be thrown but SAX2 does. [Q] How do we
           //          resolve this? Currently I'm erring on the side
           //          of SAX2. -Ac
  +        // This is what the JCK requires; 2.0 is assumed to supersede the
  +        // SAX 1 behaviour - neilg
           if (dtdHandler == null) {
               throw new NullPointerException();
           }
  @@ -1352,6 +1362,10 @@
        * @see #getContentHandler
        */
       public void setContentHandler(ContentHandler contentHandler) {
  +        // not per SAX 1, but per SAX 2.0 and JAXP 1.1 expectations
  +        if(contentHandler == null) {
  +            throw new NullPointerException();
  +        }
           fContentHandler = contentHandler;
       } // setContentHandler(ContentHandler)
   
  
  
  

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