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/01/22 00:43:36 UTC

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

neilg       2003/01/21 15:43:36

  Modified:    java/src/org/apache/xerces/parsers AbstractSAXParser.java
  Log:
  The SAX DeclHandler#attrDecl method requires no callback to be made
  for the second and subsequent declarations of attributes.  This patch
  fixes the parser so that it correctly implements that behaviour.
  
  Revision  Changes    Path
  1.38      +25 -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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- AbstractSAXParser.java	7 Jan 2003 22:23:47 -0000	1.37
  +++ AbstractSAXParser.java	21 Jan 2003 23:43:36 -0000	1.38
  @@ -68,6 +68,7 @@
   import org.apache.xerces.impl.xs.psvi.PSVIProvider;
   import org.apache.xerces.util.EntityResolverWrapper;
   import org.apache.xerces.util.ErrorHandlerWrapper;
  +import org.apache.xerces.util.SymbolHash;
   
   import org.apache.xerces.xni.NamespaceContext;
   import org.apache.xerces.xni.Augmentations;
  @@ -220,6 +221,11 @@
       private static final int BUFFER_SIZE = 20;
       private char[] fCharBuffer =  new char[BUFFER_SIZE];
   
  +    // allows us to keep track of whether an attribute has
  +    // been declared twice, so that we can avoid exposing the
  +    // second declaration to any registered DeclHandler
  +    protected SymbolHash fDeclaredAttrs = null;
  +
       //
       // Constructors
       //
  @@ -318,6 +324,11 @@
               throw new XNIException(e);
           }
   
  +        // is there a DeclHandler?
  +        if(fDeclHandler != null) {
  +            fDeclaredAttrs = new SymbolHash();
  +        }
  +
       } // doctypeDecl(String,String,String)
   
           /**
  @@ -804,7 +815,7 @@
               throw new XNIException(e);
           }
   
  -    } // elementDecl(String,String)
  +    } // elementDecl(String,String, Augmentations)
   
       /**
        * An attribute declaration.
  @@ -840,6 +851,13 @@
           try {
               // SAX2 extension
               if (fDeclHandler != null) {
  +                // used as a key to detect duplicate attribute definitions.
  +                String elemAttr = new StringBuffer(elementName).append("<").append(attributeName).toString();
  +                if(fDeclaredAttrs.get(elemAttr) != null) {
  +                    // we aren't permitted to return duplicate attribute definitions
  +                    return;
  +                }
  +                fDeclaredAttrs.put(elemAttr, Boolean.TRUE);
                   if (type.equals("NOTATION") || 
                       type.equals("ENUMERATION")) {
   
  @@ -1014,6 +1032,10 @@
           catch (SAXException e) {
               throw new XNIException(e);
           }
  +        if(fDeclaredAttrs != null) {
  +            // help out the GC
  +            fDeclaredAttrs.clear();
  +        }
   
       } // endDTD()
   
  @@ -1863,6 +1885,7 @@
           fNamespaces = fConfiguration.getFeature(NAMESPACES);           
           fNamespacePrefixes = fConfiguration.getFeature(NAMESPACE_PREFIXES);
           fAugmentations = null;
  +        fDeclaredAttrs = null;
           
       } // reset()
   
  
  
  

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