You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/07/05 16:53:37 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/framework XMLAttrList.java

sandygao    01/07/05 07:53:37

  Modified:    java/src/org/apache/xerces/framework XMLAttrList.java
  Log:
  fixing bug [2250]: check duplicate attributes with namespace names
  
  Revision  Changes    Path
  1.9       +51 -10    xml-xerces/java/src/org/apache/xerces/framework/XMLAttrList.java
  
  Index: XMLAttrList.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLAttrList.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XMLAttrList.java	2001/06/21 14:35:42	1.8
  +++ XMLAttrList.java	2001/07/05 14:53:36	1.9
  @@ -94,7 +94,7 @@
    * may be used to access the attribute list through the SAX <code>AttributeList</code>
    * interface.
    *
  - * @version $Id: XMLAttrList.java,v 1.8 2001/06/21 14:35:42 sandygao Exp $
  + * @version $Id: XMLAttrList.java,v 1.9 2001/07/05 14:53:36 sandygao Exp $
    */
   public final class XMLAttrList
       implements AttributeList {
  @@ -112,8 +112,9 @@
   
       // Flags (bits)
   
  -    private static final int ATTFLAG_SPECIFIED = 1;
  -    private static final int ATTFLAG_LASTATTR  = 2;
  +    private static final int ATTFLAG_SPECIFIED  = 1;
  +    private static final int ATTFLAG_LASTATTR   = 2;
  +    private static final int ATTFLAG_NEEDSEARCH = 4;
   
       //
       // Data
  @@ -188,12 +189,9 @@
               chunk = fCurrentHandle >> CHUNK_SHIFT;
               index = fCurrentHandle & CHUNK_MASK;
               for (int attrIndex = fCurrentHandle; attrIndex < fAttrCount; attrIndex++) {
  -                // we only check on rawname, which results in bug 2250
  -                // we should check uri+localpart, but uri is not ready at this point
  -                // fix it later. ??? TO BE DONE
  +                // check on rawname, as required by XML1.0
  +                // we check qname later in endAttrList
                   if (fStringPool.equalNames(fAttName[chunk][index], attribute.rawname)) {
  -                //if (fStringPool.equalNames(fAttURI[chunk][index], attribute.uri) &&
  -                //    fStringPool.equalNames(fAttLocalpart[chunk][index], attribute.localpart)) {
                       return -1;
                   }
                   if (++index == CHUNK_SIZE) {
  @@ -205,6 +203,7 @@
               chunk = fAttrCount >> CHUNK_SHIFT;
               index = fAttrCount & CHUNK_MASK;
           }
  +
           ensureCapacity(chunk, index);
           fAttPrefix[chunk][index] = attribute.prefix;
           fAttLocalpart[chunk][index] = attribute.localpart;
  @@ -212,7 +211,7 @@
           fAttURI[chunk][index] = attribute.uri;
           fAttValue[chunk][index] = attValue;
           fAttType[chunk][index] = attType;
  -        fAttFlags[chunk][index] = (byte)(specified ? ATTFLAG_SPECIFIED : 0);
  +        fAttFlags[chunk][index] = (byte)((specified ? ATTFLAG_SPECIFIED : 0) | (search ? ATTFLAG_NEEDSEARCH : 0));
           return fAttrCount++;
   
       } // addAttr(QName,int,int,boolean,boolean):int
  @@ -230,12 +229,54 @@
       /**
        * Terminate the current set of attributes.
        */
  -    public void endAttrList() {
  +    public int[] endAttrList() {
  +        if (fCurrentHandle == -1)
  +            return null;
  +        int oldHandle = fCurrentHandle;
  +
           int attrIndex = fAttrCount - 1;
           int chunk = attrIndex >> CHUNK_SHIFT;
           int index = attrIndex & CHUNK_MASK;
           fAttFlags[chunk][index] |= ATTFLAG_LASTATTR;
           fCurrentHandle = -1;
  +
  +        int dupCount = 0;
  +        int dupNames[] = null;
  +
  +        int attrIndex1 = oldHandle + 1, attrIndex2;
  +        int chunk1 = attrIndex1 >> CHUNK_SHIFT;
  +        int index1 = attrIndex1 & CHUNK_MASK;
  +        int chunk2, index2;
  +        for (; attrIndex1 < fAttrCount; attrIndex1++) {
  +            if ((fAttFlags[chunk1][index1] & ATTFLAG_NEEDSEARCH) == 0)
  +                continue;
  +            chunk2 = chunk1;
  +            index2 = index1;
  +            for (attrIndex2 = oldHandle; attrIndex2 < attrIndex1; attrIndex2++) {
  +                if (--index2 == -1) {
  +                    chunk2--;
  +                    index2 = CHUNK_SIZE-1;
  +                }
  +                if (fStringPool.equalNames(fAttURI[chunk1][index1], fAttURI[chunk2][index2]) &&
  +                    fStringPool.equalNames(fAttLocalpart[chunk1][index1], fAttLocalpart[chunk2][index2])) {
  +                    if (dupCount == 0)
  +                        dupNames = new int[fAttrCount - oldHandle];
  +                    dupNames[dupCount++] = fAttName[chunk1][index1];
  +                }
  +            }
  +            if (++index1 == CHUNK_SIZE) {
  +                chunk1++;
  +                index1 = 0;
  +            }
  +        }
  +
  +        if (dupCount > 0) {
  +            int[] names = new int[dupCount];
  +            System.arraycopy(dupNames, 0, names, 0, dupCount);
  +            dupNames = names;
  +        }
  +
  +        return dupNames;
       }
   
       /**
  
  
  

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