neilg       2003/11/27 21:13:29

  Modified:    c/src/xercesc/internal IGXMLScanner.cpp IGXMLScanner.hpp
                        IGXMLScanner2.cpp SGXMLScanner.cpp
  Log:
  Fix state-ful duplicate attribute detection when the integrated
  scanner is in use and namespaces are off.  Also, implement
  change to PSVIHandler interface to remove prefix passing.
  
  Revision  Changes    Path
  1.37      +50 -54    xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
  
  Index: IGXMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- IGXMLScanner.cpp  27 Nov 2003 22:52:37 -0000      1.36
  +++ IGXMLScanner.cpp  28 Nov 2003 05:13:29 -0000      1.37
  @@ -1653,6 +1653,9 @@
       //  pairs until we get there.
       unsigned int    attCount = 0;
       unsigned int    curAttListSize = fAttrList->size();
  +    wasAdded = false;
  +    fElemCount++;
  +
       while (true)
       {
           // And get the next non-space character
  @@ -1737,27 +1740,14 @@
               //  See if this attribute is declared for this element. If we are
               //  not validating of course it will not be at first, but we will
               //  fault it into the pool (to avoid lots of redundant errors.)
  -            wasAdded = false;
  -            XMLAttDef* attDef = elemDecl->findAttr
  -            (
  -                fAttNameBuf.getRawBuffer()
  -                , 0
  -                , 0
  -                , 0
  -                , XMLElementDecl::AddIfNotFound
  -                , wasAdded
  -            );
  -
  -            if (wasAdded)
  +            XMLCh * namePtr = fAttNameBuf.getRawBuffer();
  +            XMLAttDef* attDef = ((DTDElementDecl *)elemDecl)->getAttDef(namePtr);
  +            if (!attDef)
               {
                   //  If there is a validation handler, then we are validating
                   //  so emit an error.
                   if (fValidate)
  -                {
  -                    // This is to tell the Validator that this attribute was
  -                    // faulted-in, was not an attribute in the attdef originally
  -                    attDef->setCreateReason(XMLAttDef::JustFaultIn);
  -
  +                { 
                       fValidator->emitError
                       (
                           XMLValid::AttNotDefinedForElement
  @@ -1765,45 +1755,52 @@
                           , elemDecl->getFullName()
                       );
                   }
  +                unsigned int *curCountPtr = fUndeclaredAttrRegistry->get(namePtr);
  +                if(!curCountPtr)
  +                {
  +                    curCountPtr = getNewUIntPtr();
  +                     *curCountPtr = fElemCount;
  +                    fUndeclaredAttrRegistry->put((void *)namePtr, curCountPtr);
  +                }
  +                else if(*curCountPtr < fElemCount)
  +                    *curCountPtr = fElemCount;
  +                else
  +                {
  +                    emitError
  +                    ( 
  +                        XMLErrs::AttrAlreadyUsedInSTag
  +                        , namePtr
  +                        , elemDecl->getFullName()
  +                     );
  +                }
               }
               else
               {
  -                // If this attribute was faulted-in and first occurence,
  -                // then emit an error
  -                if (fValidate && attDef->getCreateReason() == XMLAttDef::JustFaultIn
  -                    && !attDef->getProvided())
  +                // prepare for duplicate detection
  +                unsigned int *curCountPtr = fAttDefRegistry->get(attDef);
  +                if(!curCountPtr)
  +                {
  +                    curCountPtr = getNewUIntPtr();
  +                    *curCountPtr = fElemCount;
  +                    fAttDefRegistry->put(attDef, curCountPtr);
  +                }
  +                else if(*curCountPtr < fElemCount)
  +                    *curCountPtr = fElemCount;
  +                else
                   {
  -                    fValidator->emitError
  -                    (
  -                        XMLValid::AttNotDefinedForElement
  -                        , fAttNameBuf.getRawBuffer()
  +                    emitError
  +                    ( 
  +                        XMLErrs::AttrAlreadyUsedInSTag
  +                        , attDef->getFullName()
                           , elemDecl->getFullName()
                       );
                   }
               }
  -
  -            //  If its already provided, then there are more than one of
  -            //  this attribute in this start tag, so emit an error.
  -            if (attDef->getProvided())
  -            {
  -                emitError
  -                (
  -                    XMLErrs::AttrAlreadyUsedInSTag
  -                    , attDef->getFullName()
  -                    , elemDecl->getFullName()
  -                );
  -            }
  -            else
  -            {
  -                // Mark this one as already seen
  -                attDef->setProvided(true);
  -            }
  -
               //  Skip any whitespace before the value and then scan the att
               //  value. This will come back normalized with entity refs and
               //  char refs expanded.
               fReaderMgr.skipPastSpaces();
  -            if (!scanAttValue(attDef, fAttValueBuf))
  +            if (!scanAttValue(attDef, namePtr, fAttValueBuf))
               {
                   static const XMLCh tmpList[] =
                   {
  @@ -1841,7 +1838,7 @@
               //  determine if it has a valid value. It will output any needed
               //  errors, but we just keep going. We only need to do this if
               //  we are validating.
  -            if (!wasAdded && attDef->getCreateReason() != XMLAttDef::JustFaultIn)
  +            if (attDef)
               {
                   // Let the validator pass judgement on the attribute value
                   if (fValidate)
  @@ -1865,10 +1862,10 @@
                   curAtt = new (fMemoryManager) XMLAttr
                   (
                       -1
  -                    , fAttNameBuf.getRawBuffer()
  +                    , namePtr
                       , XMLUni::fgZeroLenString
                       , fAttValueBuf.getRawBuffer()
  -                    , attDef->getType()
  +                    , (attDef)?attDef->getType():XMLAttDef::CData
                       , true
                       , fMemoryManager
                   );
  @@ -1880,10 +1877,10 @@
                   curAtt->set
                   (
                       -1
  -                    , fAttNameBuf.getRawBuffer()
  +                    , namePtr
                       , XMLUni::fgZeroLenString
                       , fAttValueBuf.getRawBuffer()
  -                    , attDef->getType()
  +                    , (attDef)?attDef->getType():XMLAttDef::CData
                   );
                   curAtt->setSpecified(true);
               }
  @@ -1948,8 +1945,9 @@
               const XMLAttDef& curDef = attDefList.getAttDef(i);
               const XMLAttDef::DefAttTypes defType = curDef.getDefaultType();
   
  -            if (!curDef.getProvided())
  -            {
  +            unsigned int *attCountPtr = fAttDefRegistry->get(&curDef);
  +            if (!attCountPtr || *attCountPtr < fElemCount)
  +            { // did not occur
                   if (fValidate)
                   {
                       // If we are validating and its required, then an error
  @@ -2777,7 +2775,6 @@
           (
               eName->getLocalPart()
               , fURIStringPool->getValueForId(eName->getURI())
  -            , eName->getPrefix()
               , fPSVIAttrList
           );
       }
  @@ -3348,7 +3345,6 @@
       (
           elemDecl->getBaseName()
           , fURIStringPool->getValueForId(elemDecl->getURI())
  -        , elemDecl->getElementName()->getPrefix()
           , fPSVIElement
       );
   
  
  
  
  1.16      +5 -1      xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp
  
  Index: IGXMLScanner.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- IGXMLScanner.hpp  27 Nov 2003 22:52:37 -0000      1.15
  +++ IGXMLScanner.hpp  28 Nov 2003 05:13:29 -0000      1.16
  @@ -56,6 +56,11 @@
   
   /*
    * $Log$
  + * Revision 1.16  2003/11/28 05:13:29  neilg
  + * Fix state-ful duplicate attribute detection when the integrated
  + * scanner is in use and namespaces are off.  Also, implement
  + * change to PSVIHandler interface to remove prefix passing.
  + *
    * Revision 1.15  2003/11/27 22:52:37  knoaman
    * PSVIElement implementation
    *
  @@ -285,6 +290,7 @@
       bool scanAttValue
       (
           const   XMLAttDef* const    attDef
  +        , const   XMLCh* const      attrName
           ,       XMLBuffer&          toFill
       );
       bool scanContent(const bool extEntity);
  
  
  
  1.46      +8 -4      xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp
  
  Index: IGXMLScanner2.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- IGXMLScanner2.cpp 27 Nov 2003 22:52:37 -0000      1.45
  +++ IGXMLScanner2.cpp 28 Nov 2003 05:13:29 -0000      1.46
  @@ -2152,6 +2152,7 @@
   
   
   bool IGXMLScanner::scanAttValue(  const   XMLAttDef* const    attDef
  +                                  , const XMLCh* const        attrName
                                     ,       XMLBuffer&          toFill)
   {
       enum States
  @@ -2161,8 +2162,9 @@
       };
   
       // Get the type and name
  -    const XMLAttDef::AttTypes type = attDef->getType();
  -    const XMLCh* const attrName = attDef->getFullName();
  +    const XMLAttDef::AttTypes type = (attDef)
  +                ?attDef->getType()
  +                :XMLAttDef::CData;
   
       // Reset the target buffer
       toFill.reset();
  @@ -2177,7 +2179,9 @@
       const unsigned int curReader = fReaderMgr.getCurrentReaderNum();
   
       // Get attribute def - to check to see if it's declared externally or not
  -    bool  isAttExternal = attDef->isExternal();
  +    bool  isAttExternal = (attDef)
  +                ?attDef->isExternal()
  +                :false;
   
       //  Loop until we get the attribute value. Note that we use a double
       //  loop here to avoid the setup/teardown overhead of the exception
  
  
  
  1.55      +1 -3      xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp
  
  Index: SGXMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- SGXMLScanner.cpp  27 Nov 2003 22:52:37 -0000      1.54
  +++ SGXMLScanner.cpp  28 Nov 2003 05:13:29 -0000      1.55
  @@ -1730,7 +1730,6 @@
           (
               eName->getLocalPart()
               , fURIStringPool->getValueForId(eName->getURI())
  -            , eName->getPrefix()
               , fPSVIAttrList
           );
       }
  @@ -4773,7 +4772,6 @@
       (
           elemDecl->getBaseName()
           , fURIStringPool->getValueForId(elemDecl->getURI())
  -        , elemDecl->getElementName()->getPrefix()
           , fPSVIElement
       );
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to