sax2xmlreaderimpl.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,817 行 · 第 1/4 页
CPP
1,817 行
// // Search the array until we find this handler. If we find a null entry // first, we can stop there before the list is kept contiguous. // unsigned int index; for (index = 0; index < fAdvDHCount; index++) { // // We found it. We have to keep the list contiguous, so we have to // copy down any used elements after this one. // if (fAdvDHList[index] == toRemove) { // // Optimize if only one entry (pretty common). Otherwise, we // have to copy them down to compact them. // if (fAdvDHCount > 1) { index++; while (index < fAdvDHCount) fAdvDHList[index - 1] = fAdvDHList[index]; } // Bump down the count and zero out the last one fAdvDHCount--; fAdvDHList[fAdvDHCount] = 0; // // If this leaves us with no advanced handlers and there is // no SAX doc handler installed on us, then remove us from the // scanner as the document handler. // if (!fAdvDHCount && !fDocHandler) fScanner->setDocHandler(0); return true; } } // Never found it return false;}// ---------------------------------------------------------------------------// SAX2XMLReaderImpl Validator functions// ---------------------------------------------------------------------------void SAX2XMLReaderImpl::setValidator(XMLValidator* valueToAdopt){ fValidator = valueToAdopt; fScanner->setValidator(valueToAdopt);}XMLValidator* SAX2XMLReaderImpl::getValidator() const{ return fScanner->getValidator();}// ---------------------------------------------------------------------------// SAX2XMLReader Interface// ---------------------------------------------------------------------------int SAX2XMLReaderImpl::getErrorCount() const{ return fScanner->getErrorCount();}void SAX2XMLReaderImpl::setContentHandler(ContentHandler* const handler){ fDocHandler = handler; if (fDocHandler) { // // Make sure we are set as the document handler with the scanner. // We may already be (if advanced handlers are installed), but its // not worthing checking, just do it. // fScanner->setDocHandler(this); } else { // // If we don't have any advanced handlers either, then deinstall us // from the scanner because we don't need document events anymore. // if (!fAdvDHCount) fScanner->setDocHandler(0); }}void SAX2XMLReaderImpl::setDTDHandler(DTDHandler* const handler){ fDTDHandler = handler; if (fDTDHandler) fScanner->setDocTypeHandler(this); else fScanner->setDocTypeHandler(0);}void SAX2XMLReaderImpl::setErrorHandler(ErrorHandler* const handler){ // // Store the handler. Then either install or deinstall us as the // error reporter on the scanner. // fErrorHandler = handler; if (fErrorHandler) { fScanner->setErrorReporter(this); fScanner->setErrorHandler(fErrorHandler); } else { fScanner->setErrorReporter(0); fScanner->setErrorHandler(0); }}void SAX2XMLReaderImpl::setPSVIHandler(PSVIHandler* const handler){ fPSVIHandler = handler; if (fPSVIHandler) { fScanner->setPSVIHandler(fPSVIHandler); } else { fScanner->setPSVIHandler(0); }}void SAX2XMLReaderImpl::setLexicalHandler(LexicalHandler* const handler){ fLexicalHandler = handler; if (fLexicalHandler) fScanner->setDocTypeHandler(this); else fScanner->setDocTypeHandler(0);}void SAX2XMLReaderImpl::setDeclarationHandler(DeclHandler* const handler){ fDeclHandler = handler; if (fDeclHandler) fScanner->setDocTypeHandler(this); else fScanner->setDocTypeHandler(0);}void SAX2XMLReaderImpl::setEntityResolver(EntityResolver* const resolver){ fEntityResolver = resolver; if (fEntityResolver) { fScanner->setEntityHandler(this); fXMLEntityResolver = 0; } else { fScanner->setEntityHandler(0); }}void SAX2XMLReaderImpl::setXMLEntityResolver(XMLEntityResolver* const resolver){ fXMLEntityResolver = resolver; if (fXMLEntityResolver) { fScanner->setEntityHandler(this); fEntityResolver = 0; } else { fScanner->setEntityHandler(0); }}void SAX2XMLReaderImpl::setExitOnFirstFatalError(const bool newState){ fScanner->setExitOnFirstFatal(newState);}void SAX2XMLReaderImpl::setValidationConstraintFatal(const bool newState){ fScanner->setValidationConstraintFatal(newState);}void SAX2XMLReaderImpl::parse (const InputSource& source){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); try { fParseInProgress = true; fScanner->scanDocument(source); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch (...) { fParseInProgress = false; throw; }}void SAX2XMLReaderImpl::parse (const XMLCh* const systemId){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); try { fParseInProgress = true; fScanner->scanDocument(systemId); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch (...) { fParseInProgress = false; throw; }}void SAX2XMLReaderImpl::parse (const char* const systemId){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); try { fParseInProgress = true; fScanner->scanDocument(systemId); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch (...) { fParseInProgress = false; throw; }}// ---------------------------------------------------------------------------// SAX2XMLReaderImpl: Progressive parse methods// ---------------------------------------------------------------------------bool SAX2XMLReaderImpl::parseFirst( const XMLCh* const systemId , XMLPScanToken& toFill){ // // Avoid multiple entrance. We cannot enter here while a regular parse // is in progress. // if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); return fScanner->scanFirst(systemId, toFill);}bool SAX2XMLReaderImpl::parseFirst( const char* const systemId , XMLPScanToken& toFill){ // // Avoid multiple entrance. We cannot enter here while a regular parse // is in progress. // if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); return fScanner->scanFirst(systemId, toFill);}bool SAX2XMLReaderImpl::parseFirst( const InputSource& source , XMLPScanToken& toFill){ // // Avoid multiple entrance. We cannot enter here while a regular parse // is in progress. // if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); return fScanner->scanFirst(source, toFill);}bool SAX2XMLReaderImpl::parseNext(XMLPScanToken& token){ return fScanner->scanNext(token);}void SAX2XMLReaderImpl::parseReset(XMLPScanToken& token){ // Reset the scanner fScanner->scanReset(token);}// ---------------------------------------------------------------------------// SAX2XMLReaderImpl: Overrides of the XMLDocumentHandler interface// ---------------------------------------------------------------------------void SAX2XMLReaderImpl::docCharacters( const XMLCh* const chars , const unsigned int length , const bool cdataSection){ // Suppress the chars before the root element. if (!fElemDepth) return; // Call the installed LexicalHandler. if (cdataSection && fLexicalHandler) fLexicalHandler->startCDATA(); // Just map to the SAX document handler if (fDocHandler) fDocHandler->characters(chars, length); // Call the installed LexicalHandler. if (cdataSection && fLexicalHandler) fLexicalHandler->endCDATA(); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->docCharacters(chars, length, cdataSection);}void SAX2XMLReaderImpl::docComment(const XMLCh* const commentText){ // Call the installed LexicalHandler. if (fLexicalHandler) { // SAX2 reports comment text like characters -- as an // array with a length. fLexicalHandler->comment(commentText, XMLString::stringLen(commentText)); } // // OK, if there are any installed advanced handlers, // then let's call them with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->docComment(commentText);}void SAX2XMLReaderImpl::XMLDecl( const XMLCh* const versionStr , const XMLCh* const encodingStr , const XMLCh* const standaloneStr , const XMLCh* const actualEncodingStr ){ // SAX has no way to report this event. But, if there are any installed // advanced handlers, then lets call them with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->XMLDecl( versionStr, encodingStr, standaloneStr, actualEncodingStr );}void SAX2XMLReaderImpl::docPI( const XMLCh* const target , const XMLCh* const data){ // Just map to the SAX document handler if (fDocHandler) fDocHandler->processingInstruction(target, data); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->docPI(target, data);}void SAX2XMLReaderImpl::endDocument(){ if (fDocHandler) fDocHandler->endDocument(); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->endDocument();}void SAX2XMLReaderImpl::endEntityReference(const XMLEntityDecl& entityDecl){ // Call the installed LexicalHandler. if (fLexicalHandler) fLexicalHandler->endEntity(entityDecl.getName()); // // SAX has no way to report this event. But, if there are any installed // advanced handlers, then lets call them with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->endEntityReference(entityDecl);}void SAX2XMLReaderImpl::ignorableWhitespace(const XMLCh* const chars , const unsigned int length , const bool cdataSection){ // Do not report the whitespace before the root element. if (!fElemDepth) return; // Just map to the SAX document handler if (fDocHandler) fDocHandler->ignorableWhitespace(chars, length); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->ignorableWhitespace(chars, length, cdataSection);}void SAX2XMLReaderImpl::resetDocument(){ // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->resetDocument(); // Make sure our element depth flag gets set back to zero fElemDepth = 0; // Pop any prefix buffers left over from previous uses while (!fPrefixCounts->empty()) { unsigned int numPrefix = fPrefixCounts->pop(); for (unsigned int i = 0; i < numPrefix; i++)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?