igxmlscanner2.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,601 行 · 第 1/5 页

CPP
1,601
字号
                         fValidator->emitError(XMLValid::NoAttNormForStandalone, attName);                    }                    nextCh = chSpace;                }            }        }        else        {            if (curState == InWhitespace)            {                if (!fReaderMgr.getCurrentReader()->isWhitespace(nextCh))                {                    if (firstNonWS)                        toFill.append(chSpace);                    curState = InContent;                    firstNonWS = true;                }                else                {                    srcPtr++;                    continue;                }            }            else if (curState == InContent)            {                if (fReaderMgr.getCurrentReader()->isWhitespace(nextCh))                {                    curState = InWhitespace;                    srcPtr++;                    // Check Validity Constraint for Standalone document declaration                    // XML 1.0, Section 2.9                    if (fStandalone && fValidate && isAttExternal)                    {                        if (!firstNonWS || (nextCh != chSpace) || (!*srcPtr) || fReaderMgr.getCurrentReader()->isWhitespace(*srcPtr))                        {                            // Can't have a standalone document declaration of "yes" if  attribute                            // values are subject to normalisation                            fValidator->emitError(XMLValid::NoAttNormForStandalone, attName);                        }                    }                    continue;                }                firstNonWS = true;            }        }        // Add this char to the target buffer        toFill.append(nextCh);        // And move up to the next character in the source        srcPtr++;    }    return retVal;}//  This method will just normalize the input value as CDATA without//  any standalone checking.bool IGXMLScanner::normalizeAttRawValue( const   XMLCh* const        attrName                                      , const XMLCh* const        value                                      ,       XMLBuffer&          toFill){    // Assume its going to go fine, and empty the target buffer in preperation    bool retVal = true;    toFill.reset();    //  Loop through the chars of the source value and normalize it according    //  to the type.    bool escaped;    XMLCh nextCh;    const XMLCh* srcPtr = value;    while (*srcPtr)    {        //  Get the next character from the source. We have to watch for        //  escaped characters (which are indicated by a 0xFFFF value followed        //  by the char that was escaped.)        nextCh = *srcPtr;        escaped = (nextCh == 0xFFFF);        if (escaped)            nextCh = *++srcPtr;        //  If its not escaped, then make sure its not a < character, which is        //  not allowed in attribute values.        if (!escaped && (*srcPtr == chOpenAngle))        {            emitError(XMLErrs::BracketInAttrValue, attrName);            retVal = false;        }        if (!escaped)        {            //  NOTE: Yes this is a little redundant in that a 0x20 is            //  replaced with an 0x20. But its faster to do this (I think)            //  than checking for 9, A, and D separately.            if (fReaderMgr.getCurrentReader()->isWhitespace(nextCh))                nextCh = chSpace;        }        // Add this char to the target buffer        toFill.append(nextCh);        // And move up to the next character in the source        srcPtr++;    }    return retVal;}unsigned intIGXMLScanner::resolvePrefix(  const   XMLCh* const        prefix                              , const ElemStack::MapModes mode){    //  Watch for the special namespace prefixes. We always map these to    //  special URIs. 'xml' gets mapped to the official URI that its defined    //  to map to by the NS spec. xmlns gets mapped to a special place holder    //  URI that we define (so that it maps to something checkable.)    if (XMLString::equals(prefix, XMLUni::fgXMLNSString))        return fXMLNSNamespaceId;    else if (XMLString::equals(prefix, XMLUni::fgXMLString))        return fXMLNamespaceId;    //  Ask the element stack to search up itself for a mapping for the    //  passed prefix.    bool unknown;    unsigned int uriId = fElemStack.mapPrefixToURI(prefix, mode, unknown);    // If it was unknown, then the URI was faked in but we have to issue an error    if (unknown)        emitError(XMLErrs::UnknownPrefix, prefix);    return uriId;}unsigned intIGXMLScanner::resolvePrefix(  const   XMLCh* const        prefix                              ,       XMLBuffer&          bufToFill                              , const ElemStack::MapModes mode){    //  Watch for the special namespace prefixes. We always map these to    //  special URIs. 'xml' gets mapped to the official URI that its defined    //  to map to by the NS spec. xmlns gets mapped to a special place holder    //  URI that we define (so that it maps to something checkable.)    if (XMLString::equals(prefix, XMLUni::fgXMLNSString))        return fXMLNSNamespaceId;    else if (XMLString::equals(prefix, XMLUni::fgXMLString))        return fXMLNamespaceId;    //  Ask the element stack to search up itself for a mapping for the    //  passed prefix.    bool unknown;    unsigned int uriId = fElemStack.mapPrefixToURI(prefix, mode, unknown);    // If it was unknown, then the URI was faked in but we have to issue an error    if (unknown)        emitError(XMLErrs::UnknownPrefix, prefix);    getURIText(uriId,bufToFill);    return uriId;}//  This method will reset the scanner data structures, and related plugged//  in stuff, for a new scan session. We get the input source for the primary//  XML entity, create the reader for it, and push it on the stack so that//  upon successful return from here we are ready to go.void IGXMLScanner::scanReset(const InputSource& src){    //  This call implicitly tells us that we are going to reuse the scanner    //  if it was previously used. So tell the validator to reset itself.    //    //  But, if the fUseCacheGrammar flag is set, then don't reset it.    //    //  NOTE:   The ReaderMgr is flushed on the way out, because that is    //          required to insure that files are closed.    fGrammarResolver->cacheGrammarFromParse(fToCacheGrammar);    fGrammarResolver->useCachedGrammarInParse(fUseCachedGrammar);    // fModel may need updating, as fGrammarResolver could have cleaned it    if(fModel && getPSVIHandler())        fModel = fGrammarResolver->getXSModel();    {        XMLDTDDescriptionImpl   theDTDDescription(XMLUni::fgDTDEntityString, fMemoryManager);        fDTDGrammar = (DTDGrammar*) fGrammarResolver->getGrammar(&theDTDDescription);    }    if (!fDTDGrammar) {        fDTDGrammar = new (fGrammarPoolMemoryManager) DTDGrammar(fGrammarPoolMemoryManager);        fGrammarResolver->putGrammar(fDTDGrammar);    }    else        fDTDGrammar->reset();    fGrammar = fDTDGrammar;    fGrammarType = fGrammar->getGrammarType();    fRootGrammar = 0;    if (fValidatorFromUser) {        if (fValidator->handlesDTD())            fValidator->setGrammar(fGrammar);        else if (fValidator->handlesSchema()) {            ((SchemaValidator*) fValidator)->setErrorReporter(fErrorReporter);            ((SchemaValidator*) fValidator)->setGrammarResolver(fGrammarResolver);            ((SchemaValidator*) fValidator)->setExitOnFirstFatal(fExitOnFirstFatal);        }    }    else {        // set fValidator as fDTDValidator        fValidator = fDTDValidator;        fValidator->setGrammar(fGrammar);    }    // Reset validation    fValidate = (fValScheme == Val_Always) ? true : false;    //  And for all installed handlers, send reset events. This gives them    //  a chance to flush any cached data.    if (fDocHandler)        fDocHandler->resetDocument();    if (fEntityHandler)        fEntityHandler->resetEntities();    if (fErrorReporter)        fErrorReporter->resetErrors();    // Clear out the id reference list    resetValidationContext();    // Reset the Root Element Name    fMemoryManager->deallocate(fRootElemName);//delete [] fRootElemName;    fRootElemName = 0;    // Reset IdentityConstraints    if (fICHandler)        fICHandler->reset();    //  Reset the element stack, and give it the latest ids for the special    //  URIs it has to know about.    fElemStack.reset    (        fEmptyNamespaceId        , fUnknownNamespaceId        , fXMLNamespaceId        , fXMLNSNamespaceId    );    if (!fSchemaNamespaceId)        fSchemaNamespaceId  = fURIStringPool->addOrFind(SchemaSymbols::fgURI_XSI);    // Reset some status flags    fInException = false;    fStandalone = false;    fErrorCount = 0;    fHasNoDTD = true;    fSeeXsi = false;    // Reset PSVI context    // note that we always need this around for DOMTypeInfo    if (!fPSVIElement)        fPSVIElement = new (fMemoryManager) PSVIElement(fMemoryManager);    if (!fErrorStack)    {        fErrorStack = new (fMemoryManager) ValueStackOf<bool>(8, fMemoryManager);    }    else    {        fErrorStack->removeAllElements();    }    resetPSVIElemContext();    // Reset the validators    fDTDValidator->reset();    fDTDValidator->setErrorReporter(fErrorReporter);    fSchemaValidator->reset();    fSchemaValidator->setErrorReporter(fErrorReporter);    fSchemaValidator->setExitOnFirstFatal(fExitOnFirstFatal);    fSchemaValidator->setGrammarResolver(fGrammarResolver);    if (fValidatorFromUser)        fValidator->reset();    //  Handle the creation of the XML reader object for this input source.    //  This will provide us with transcoding and basic lexing services.    XMLReader* newReader = fReaderMgr.createReader    (        src        , true        , XMLReader::RefFrom_NonLiteral        , XMLReader::Type_General        , XMLReader::Source_External        , fCalculateSrcOfs    );    if (!newReader) {        if (src.getIssueFatalErrorIfNotFound())            ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Scan_CouldNotOpenSource, src.getSystemId(), fMemoryManager);        else            ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Scan_CouldNotOpenSource_Warning, src.getSystemId(), fMemoryManager);    }    // Push this read onto the reader manager    fReaderMgr.pushReader(newReader, 0);    // and reset security-related things if necessary:    if(fSecurityManager != 0)     {        fEntityExpansionLimit = fSecurityManager->getEntityExpansionLimit();        fEntityExpansionCount = 0;    }    fElemCount = 0;    if(fUIntPoolRowTotal >= 32)     { // 8 KB tied up with validating attributes...        fAttDefRegistry->removeAll();        fUndeclaredAttrRegistry->removeAll();        fUndeclaredAttrRegistryNS->removeAll();        recreateUIntPool();    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?