GME  13
SAX2XMLReaderImpl.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: SAX2XMLReaderImpl.cpp 882548 2009-11-20 13:44:14Z borisk $
00020  */
00021 
00022 #include <xercesc/util/IOException.hpp>
00023 #include <xercesc/util/RefStackOf.hpp>
00024 #include <xercesc/util/XMLUniDefs.hpp>
00025 #include <xercesc/util/Janitor.hpp>
00026 #include <xercesc/sax2/ContentHandler.hpp>
00027 #include <xercesc/sax2/LexicalHandler.hpp>
00028 #include <xercesc/sax2/DeclHandler.hpp>
00029 #include <xercesc/sax2/XMLReaderFactory.hpp>
00030 #include <xercesc/sax/DTDHandler.hpp>
00031 #include <xercesc/sax/ErrorHandler.hpp>
00032 #include <xercesc/sax/EntityResolver.hpp>
00033 #include <xercesc/sax/SAXParseException.hpp>
00034 #include <xercesc/sax/SAXException.hpp>
00035 #include <xercesc/internal/XMLScannerResolver.hpp>
00036 #include <xercesc/parsers/SAX2XMLReaderImpl.hpp>
00037 #include <xercesc/validators/common/GrammarResolver.hpp>
00038 #include <xercesc/framework/XMLGrammarPool.hpp>
00039 #include <xercesc/framework/XMLSchemaDescription.hpp>
00040 #include <xercesc/util/OutOfMemoryException.hpp>
00041 #include <xercesc/util/XMLEntityResolver.hpp>
00042 #include <string.h>
00043 
00044 XERCES_CPP_NAMESPACE_BEGIN
00045 
00046 
00047 SAX2XMLReader * XMLReaderFactory::createXMLReader(  MemoryManager* const  manager
00048                                                   , XMLGrammarPool* const gramPool)
00049 {
00050     SAX2XMLReaderImpl* pImpl=new (manager) SAX2XMLReaderImpl(manager, gramPool);
00051     return pImpl;
00052 }
00053 
00054 
00055 const XMLCh gDTDEntityStr[] =
00056 {
00057     chOpenSquare, chLatin_d, chLatin_t, chLatin_d, chCloseSquare, chNull
00058 };
00059 
00060 
00061 
00062 typedef JanitorMemFunCall<SAX2XMLReaderImpl>    CleanupType;
00063 typedef JanitorMemFunCall<SAX2XMLReaderImpl>    ResetInProgressType;
00064 
00065 
00066 SAX2XMLReaderImpl::SAX2XMLReaderImpl(MemoryManager* const  manager
00067                                    , XMLGrammarPool* const gramPool):
00068 
00069     fNamespacePrefix(false)
00070     , fAutoValidation(false)
00071     , fValidation(false)
00072     , fParseInProgress(false)
00073     , fHasExternalSubset(false)
00074     , fElemDepth(0)
00075     , fAdvDHCount(0)
00076     , fAdvDHListSize(32)
00077     , fDocHandler(0)
00078     , fTempAttrVec(0)
00079     , fPrefixesStorage(0)
00080     , fPrefixes(0)
00081     , fPrefixCounts(0)
00082     , fTempQName(0)
00083     , fDTDHandler(0)
00084     , fEntityResolver(0)
00085     , fXMLEntityResolver(0)
00086     , fErrorHandler(0)
00087     , fPSVIHandler(0)
00088     , fLexicalHandler(0)
00089     , fDeclHandler(0)
00090     , fAdvDHList(0)
00091     , fScanner(0)
00092     , fGrammarResolver(0)
00093     , fURIStringPool(0)
00094     , fValidator(0)
00095     , fMemoryManager(manager)
00096     , fGrammarPool(gramPool)
00097 {
00098     CleanupType cleanup(this, &SAX2XMLReaderImpl::cleanUp);
00099 
00100     try
00101     {
00102         initialize();
00103     }
00104     catch(const OutOfMemoryException&)
00105     {
00106         // Don't cleanup when out of memory, since executing the
00107         // code can cause problems.
00108         cleanup.release();
00109 
00110         throw;
00111     }
00112 
00113     cleanup.release();
00114 }
00115 
00116 SAX2XMLReaderImpl::~SAX2XMLReaderImpl()
00117 {
00118     cleanUp();
00119 }
00120 
00121 // ---------------------------------------------------------------------------
00122 //  SAX2XMLReaderImpl: Initialize/Cleanup methods
00123 // ---------------------------------------------------------------------------
00124 void SAX2XMLReaderImpl::initialize()
00125 {
00126     // Create grammar resolver and string pool that we pass to the scanner
00127     fGrammarResolver = new (fMemoryManager) GrammarResolver(fGrammarPool, fMemoryManager);
00128     fURIStringPool = fGrammarResolver->getStringPool();
00129 
00130     //  Create a scanner and tell it what validator to use. Then set us
00131     //  as the document event handler so we can fill the DOM document.
00132     fScanner = XMLScannerResolver::getDefaultScanner(0, fGrammarResolver, fMemoryManager);
00133     fScanner->setURIStringPool(fURIStringPool);
00134 
00135     // Create the initial advanced handler list array and zero it out
00136     fAdvDHList = (XMLDocumentHandler**) fMemoryManager->allocate
00137     (
00138         fAdvDHListSize * sizeof(XMLDocumentHandler*)
00139     );//new XMLDocumentHandler*[fAdvDHListSize];
00140     memset(fAdvDHList, 0, sizeof(void*) * fAdvDHListSize);
00141 
00142     // SAX2 default is for namespaces (feature http://xml.org/sax/features/namespaces) to be on
00143     setDoNamespaces(true) ;
00144 
00145     // default: schema is on
00146     setDoSchema(true);
00147 
00148     fPrefixesStorage = new (fMemoryManager) XMLStringPool(109, fMemoryManager) ;
00149     fPrefixes        = new (fMemoryManager) ValueStackOf<unsigned int> (30, fMemoryManager) ;
00150     fTempAttrVec     = new (fMemoryManager) RefVectorOf<XMLAttr>  (10, false, fMemoryManager) ;
00151     fPrefixCounts    = new (fMemoryManager) ValueStackOf<XMLSize_t>(10, fMemoryManager) ;
00152     fTempQName       = new (fMemoryManager) XMLBuffer(32, fMemoryManager);
00153 }
00154 
00155 
00156 void SAX2XMLReaderImpl::cleanUp()
00157 {
00158     fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList;
00159     delete fScanner;
00160     delete fPrefixesStorage;
00161     delete fPrefixes;
00162     delete fTempAttrVec;
00163     delete fPrefixCounts;
00164     delete fGrammarResolver;
00165     delete fTempQName;
00166     // grammar pool must do this
00167     //delete fURIStringPool;
00168 }
00169 
00170 // ---------------------------------------------------------------------------
00171 //  SAX2XMLReaderImpl: Advanced document handler list maintenance methods
00172 // ---------------------------------------------------------------------------
00173 void SAX2XMLReaderImpl::installAdvDocHandler(XMLDocumentHandler* const toInstall)
00174 {
00175     // See if we need to expand and do so now if needed
00176     if (fAdvDHCount == fAdvDHListSize)
00177     {
00178         // Calc a new size and allocate the new temp buffer
00179         const XMLSize_t newSize = (XMLSize_t)(fAdvDHListSize * 1.5);
00180         XMLDocumentHandler** newList = (XMLDocumentHandler**) fMemoryManager->allocate
00181         (
00182             newSize * sizeof(XMLDocumentHandler*)
00183         );//new XMLDocumentHandler*[newSize];
00184 
00185         // Copy over the old data to the new list and zero out the rest
00186         memcpy(newList, fAdvDHList, sizeof(void*) * fAdvDHListSize);
00187         memset
00188         (
00189             &newList[fAdvDHListSize]
00190             , 0
00191             , sizeof(void*) * (newSize - fAdvDHListSize)
00192         );
00193 
00194         // And now clean up the old array and store the new stuff
00195         fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList;
00196         fAdvDHList = newList;
00197         fAdvDHListSize = newSize;
00198     }
00199 
00200     // Add this new guy into the empty slot
00201     fAdvDHList[fAdvDHCount++] = toInstall;
00202 
00203     //
00204     //  Install ourself as the document handler with the scanner. We might
00205     //  already be, but its not worth checking, just do it.
00206     //
00207     fScanner->setDocHandler(this);
00208 }
00209 
00210 
00211 bool SAX2XMLReaderImpl::removeAdvDocHandler(XMLDocumentHandler* const toRemove)
00212 {
00213     // If our count is zero, can't be any installed
00214     if (!fAdvDHCount)
00215         return false;
00216 
00217     //
00218     //  Search the array until we find this handler. If we find a null entry
00219     //  first, we can stop there before the list is kept contiguous.
00220     //
00221     XMLSize_t index;
00222     for (index = 0; index < fAdvDHCount; index++)
00223     {
00224         //
00225         //  We found it. We have to keep the list contiguous, so we have to
00226         //  copy down any used elements after this one.
00227         //
00228         if (fAdvDHList[index] == toRemove)
00229         {
00230             //
00231             //  Optimize if only one entry (pretty common). Otherwise, we
00232             //  have to copy them down to compact them.
00233             //
00234             if (fAdvDHCount > 1)
00235             {
00236                 index++;
00237                 while (index < fAdvDHCount)
00238                     fAdvDHList[index - 1] = fAdvDHList[index];
00239             }
00240 
00241             // Bump down the count and zero out the last one
00242             fAdvDHCount--;
00243             fAdvDHList[fAdvDHCount] = 0;
00244 
00245             //
00246             //  If this leaves us with no advanced handlers and there is
00247             //  no SAX doc handler installed on us, then remove us from the
00248             //  scanner as the document handler.
00249             //
00250             if (!fAdvDHCount && !fDocHandler)
00251                 fScanner->setDocHandler(0);
00252 
00253             return true;
00254         }
00255     }
00256 
00257     // Never found it
00258     return false;
00259 }
00260 
00261 // ---------------------------------------------------------------------------
00262 //  SAX2XMLReaderImpl Validator functions
00263 // ---------------------------------------------------------------------------
00264 void SAX2XMLReaderImpl::setValidator(XMLValidator* valueToAdopt)
00265 {
00266     fValidator = valueToAdopt;
00267     fScanner->setValidator(valueToAdopt);
00268 }
00269 
00270 XMLValidator* SAX2XMLReaderImpl::getValidator() const
00271 {
00272     return fScanner->getValidator();
00273 }
00274 
00275 // ---------------------------------------------------------------------------
00276 //  SAX2XMLReader Interface
00277 // ---------------------------------------------------------------------------
00278 XMLSize_t SAX2XMLReaderImpl::getErrorCount() const
00279 {
00280     return fScanner->getErrorCount();
00281 }
00282 
00283 void SAX2XMLReaderImpl::setContentHandler(ContentHandler* const handler)
00284 {
00285     fDocHandler = handler;
00286     if (fDocHandler)
00287     {
00288         //
00289         //  Make sure we are set as the document handler with the scanner.
00290         //  We may already be (if advanced handlers are installed), but its
00291         //  not worthing checking, just do it.
00292         //
00293         fScanner->setDocHandler(this);
00294     }
00295      else
00296     {
00297         //
00298         //  If we don't have any advanced handlers either, then deinstall us
00299         //  from the scanner because we don't need document events anymore.
00300         //
00301         if (!fAdvDHCount)
00302             fScanner->setDocHandler(0);
00303     }
00304 
00305 }
00306 
00307 void SAX2XMLReaderImpl::setDTDHandler(DTDHandler* const handler)
00308 {
00309     fDTDHandler = handler;
00310     if (fDTDHandler)
00311         fScanner->setDocTypeHandler(this);
00312     else
00313         fScanner->setDocTypeHandler(0);
00314 }
00315 
00316 
00317 void SAX2XMLReaderImpl::setErrorHandler(ErrorHandler* const handler)
00318 {
00319     //
00320     //  Store the handler. Then either install or deinstall us as the
00321     //  error reporter on the scanner.
00322     //
00323     fErrorHandler = handler;
00324     if (fErrorHandler) {
00325         fScanner->setErrorReporter(this);
00326         fScanner->setErrorHandler(fErrorHandler);
00327     }
00328     else {
00329         fScanner->setErrorReporter(0);
00330         fScanner->setErrorHandler(0);
00331     }
00332 }
00333 
00334 void SAX2XMLReaderImpl::setPSVIHandler(PSVIHandler* const handler)
00335 {
00336     fPSVIHandler = handler;
00337     if (fPSVIHandler) {
00338         fScanner->setPSVIHandler(fPSVIHandler);
00339     }
00340     else {
00341         fScanner->setPSVIHandler(0);
00342     }
00343 }
00344 
00345 void SAX2XMLReaderImpl::setLexicalHandler(LexicalHandler* const handler)
00346 {
00347     fLexicalHandler = handler;
00348     if (fLexicalHandler)
00349         fScanner->setDocTypeHandler(this);
00350     else
00351         fScanner->setDocTypeHandler(0);
00352 }
00353 
00354 void SAX2XMLReaderImpl::setDeclarationHandler(DeclHandler* const handler)
00355 {
00356     fDeclHandler = handler;
00357     if (fDeclHandler)
00358         fScanner->setDocTypeHandler(this);
00359     else
00360         fScanner->setDocTypeHandler(0);
00361 }
00362 
00363 
00364 void SAX2XMLReaderImpl::setEntityResolver(EntityResolver* const resolver)
00365 {
00366     fEntityResolver = resolver;
00367     if (fEntityResolver) {
00368         fScanner->setEntityHandler(this);
00369         fXMLEntityResolver = 0;
00370     }
00371     else {
00372         fScanner->setEntityHandler(0);
00373     }
00374 }
00375 
00376 void SAX2XMLReaderImpl::setXMLEntityResolver(XMLEntityResolver* const resolver)
00377 {
00378     fXMLEntityResolver = resolver;
00379     if (fXMLEntityResolver) {
00380         fScanner->setEntityHandler(this);
00381         fEntityResolver = 0;
00382     }
00383     else {
00384         fScanner->setEntityHandler(0);
00385     }
00386 }
00387 
00388 void SAX2XMLReaderImpl::setExitOnFirstFatalError(const bool newState)
00389 {
00390     fScanner->setExitOnFirstFatal(newState);
00391 }
00392 
00393 void SAX2XMLReaderImpl::setValidationConstraintFatal(const bool newState)
00394 {
00395     fScanner->setValidationConstraintFatal(newState);
00396 }
00397 
00398 void SAX2XMLReaderImpl::parse (const   InputSource&    source)
00399 {
00400     // Avoid multiple entrance
00401     if (fParseInProgress)
00402         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00403 
00404     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
00405 
00406     try
00407     {
00408         fParseInProgress = true;
00409         fScanner->scanDocument(source);
00410     }
00411     catch(const OutOfMemoryException&)
00412     {
00413         resetInProgress.release();
00414 
00415         throw;
00416     }
00417 }
00418 
00419 void SAX2XMLReaderImpl::parse (const   XMLCh* const    systemId)
00420 {
00421     // Avoid multiple entrance
00422     if (fParseInProgress)
00423         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00424 
00425     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
00426 
00427     try
00428     {
00429         fParseInProgress = true;
00430         fScanner->scanDocument(systemId);
00431     }
00432     catch(const OutOfMemoryException&)
00433     {
00434         resetInProgress.release();
00435 
00436         throw;
00437     }
00438 }
00439 
00440 void SAX2XMLReaderImpl::parse (const   char* const     systemId)
00441 {
00442     // Avoid multiple entrance
00443     if (fParseInProgress)
00444         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00445 
00446     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
00447 
00448     try
00449     {
00450         fParseInProgress = true;
00451         fScanner->scanDocument(systemId);
00452     }
00453     catch(const OutOfMemoryException&)
00454     {
00455         resetInProgress.release();
00456 
00457         throw;
00458     }
00459 }
00460 
00461 // ---------------------------------------------------------------------------
00462 //  SAX2XMLReaderImpl: Progressive parse methods
00463 // ---------------------------------------------------------------------------
00464 bool SAX2XMLReaderImpl::parseFirst( const   XMLCh* const    systemId
00465                             ,       XMLPScanToken&  toFill)
00466 {
00467     //
00468     //  Avoid multiple entrance. We cannot enter here while a regular parse
00469     //  is in progress.
00470     //
00471     if (fParseInProgress)
00472         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00473 
00474     return fScanner->scanFirst(systemId, toFill);
00475 }
00476 
00477 bool SAX2XMLReaderImpl::parseFirst( const   char* const     systemId
00478                             ,       XMLPScanToken&  toFill)
00479 {
00480     //
00481     //  Avoid multiple entrance. We cannot enter here while a regular parse
00482     //  is in progress.
00483     //
00484     if (fParseInProgress)
00485         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00486 
00487     return fScanner->scanFirst(systemId, toFill);
00488 }
00489 
00490 bool SAX2XMLReaderImpl::parseFirst( const   InputSource&    source
00491                             ,       XMLPScanToken&  toFill)
00492 {
00493     //
00494     //  Avoid multiple entrance. We cannot enter here while a regular parse
00495     //  is in progress.
00496     //
00497     if (fParseInProgress)
00498         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
00499 
00500     return fScanner->scanFirst(source, toFill);
00501 }
00502 
00503 bool SAX2XMLReaderImpl::parseNext(XMLPScanToken& token)
00504 {
00505     return fScanner->scanNext(token);
00506 }
00507 
00508 void SAX2XMLReaderImpl::parseReset(XMLPScanToken& token)
00509 {
00510     // Reset the scanner
00511     fScanner->scanReset(token);
00512 }
00513 
00514 // ---------------------------------------------------------------------------
00515 //  SAX2XMLReaderImpl: Overrides of the XMLDocumentHandler interface
00516 // ---------------------------------------------------------------------------
00517 void SAX2XMLReaderImpl::docCharacters(  const   XMLCh* const    chars
00518                                 , const XMLSize_t       length
00519                                 , const bool            cdataSection)
00520 {
00521     // Suppress the chars before the root element.
00522     if (fElemDepth)
00523     {
00524         // Call the installed LexicalHandler.
00525         if (cdataSection && fLexicalHandler)
00526             fLexicalHandler->startCDATA();
00527 
00528         // Just map to the SAX document handler
00529         if (fDocHandler)
00530             fDocHandler->characters(chars, length);
00531 
00532         // Call the installed LexicalHandler.
00533         if (cdataSection && fLexicalHandler)
00534             fLexicalHandler->endCDATA();
00535     }
00536 
00537     //
00538     //  If there are any installed advanced handlers, then lets call them
00539     //  with this info.
00540     //
00541     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00542         fAdvDHList[index]->docCharacters(chars, length, cdataSection);
00543 }
00544 
00545 
00546 void SAX2XMLReaderImpl::docComment(const XMLCh* const commentText)
00547 {
00548     // Call the installed LexicalHandler.
00549     if (fLexicalHandler)
00550     {
00551         // SAX2 reports comment text like characters -- as an
00552         // array with a length.
00553         fLexicalHandler->comment(commentText, XMLString::stringLen(commentText));
00554     }
00555 
00556     //
00557     //  OK, if there are any installed advanced handlers,
00558     // then let's call them with this info.
00559     //
00560     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00561         fAdvDHList[index]->docComment(commentText);
00562 }
00563 
00564 
00565 void SAX2XMLReaderImpl::XMLDecl( const  XMLCh* const    versionStr
00566                         , const XMLCh* const    encodingStr
00567                         , const XMLCh* const    standaloneStr
00568                         , const XMLCh* const    actualEncodingStr
00569                         )
00570 {
00571     // SAX has no way to report this event. But, if there are any installed
00572     //  advanced handlers, then lets call them with this info.
00573     //
00574     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00575         fAdvDHList[index]->XMLDecl( versionStr,
00576                                     encodingStr,
00577                                     standaloneStr,
00578                                     actualEncodingStr );
00579 }
00580 
00581 
00582 void SAX2XMLReaderImpl::docPI(  const   XMLCh* const    target
00583                         , const XMLCh* const    data)
00584 {
00585     // Just map to the SAX document handler
00586     if (fDocHandler)
00587         fDocHandler->processingInstruction(target, data);
00588 
00589     //
00590     //  If there are any installed advanced handlers, then lets call them
00591     //  with this info.
00592     //
00593     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00594         fAdvDHList[index]->docPI(target, data);
00595 }
00596 
00597 
00598 void SAX2XMLReaderImpl::endDocument()
00599 {
00600     if (fDocHandler)
00601         fDocHandler->endDocument();
00602 
00603     //
00604     //  If there are any installed advanced handlers, then lets call them
00605     //  with this info.
00606     //
00607     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00608         fAdvDHList[index]->endDocument();
00609 }
00610 
00611 
00612 void SAX2XMLReaderImpl::endEntityReference(const XMLEntityDecl& entityDecl)
00613 {
00614    // Call the installed LexicalHandler.
00615    if (fLexicalHandler)
00616         fLexicalHandler->endEntity(entityDecl.getName());
00617 
00618     //
00619     //  SAX has no way to report this event. But, if there are any installed
00620     //  advanced handlers, then lets call them with this info.
00621     //
00622     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00623         fAdvDHList[index]->endEntityReference(entityDecl);
00624 }
00625 
00626 
00627 void SAX2XMLReaderImpl::ignorableWhitespace(const   XMLCh* const    chars
00628                                     , const XMLSize_t       length
00629                                     , const bool            cdataSection)
00630 {
00631     // Do not report the whitespace before the root element.
00632     if (!fElemDepth)
00633         return;
00634 
00635     // Just map to the SAX document handler
00636     if (fDocHandler)
00637         fDocHandler->ignorableWhitespace(chars, length);
00638 
00639     //
00640     //  If there are any installed advanced handlers, then lets call them
00641     //  with this info.
00642     //
00643     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00644         fAdvDHList[index]->ignorableWhitespace(chars, length, cdataSection);
00645 }
00646 
00647 
00648 void SAX2XMLReaderImpl::resetDocument()
00649 {
00650     //
00651     //  If there are any installed advanced handlers, then lets call them
00652     //  with this info.
00653     //
00654     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00655         fAdvDHList[index]->resetDocument();
00656 
00657     // Make sure our element depth flag gets set back to zero
00658     fElemDepth = 0;
00659 
00660     // reset prefix counters and prefix map
00661     fPrefixCounts->removeAllElements();
00662     fPrefixes->removeAllElements();
00663     fPrefixesStorage->flushAll();
00664 }
00665 
00666 
00667 void SAX2XMLReaderImpl::startDocument()
00668 {
00669     // Just map to the SAX document handler
00670     if (fDocHandler)
00671         fDocHandler->setDocumentLocator(fScanner->getLocator());
00672     if(fDocHandler)
00673         fDocHandler->startDocument();
00674 
00675     //
00676     //  If there are any installed advanced handlers, then lets call them
00677     //  with this info.
00678     //
00679     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00680         fAdvDHList[index]->startDocument();
00681 }
00682 
00683 
00684 void SAX2XMLReaderImpl::
00685 startElement(   const   XMLElementDecl&         elemDecl
00686                 , const unsigned int            elemURLId
00687                 , const XMLCh* const            elemPrefix
00688                 , const RefVectorOf<XMLAttr>&   attrList
00689                 , const XMLSize_t               attrCount
00690                 , const bool                    isEmpty
00691                 , const bool                    isRoot)
00692 {
00693     // Bump the element depth counter if not empty
00694     if (!isEmpty)
00695         fElemDepth++;
00696 
00697     if (fDocHandler)
00698     {
00699         const QName* qName=elemDecl.getElementName();
00700         const XMLCh* baseName=qName->getLocalPart();
00701         const XMLCh* elemQName = 0;
00702         if(elemPrefix==0 || *elemPrefix==0)
00703             elemQName=baseName;
00704         else if(XMLString::equals(elemPrefix, qName->getPrefix()))
00705             elemQName=qName->getRawName();
00706         else
00707         {
00708             fTempQName->set(elemPrefix);
00709             fTempQName->append(chColon);
00710             fTempQName->append(baseName);
00711             elemQName=fTempQName->getRawBuffer();
00712         }
00713 
00714         if (getDoNamespaces())
00715         {
00716             XMLSize_t numPrefix = 0;
00717 
00718             if (!fNamespacePrefix)
00719                 fTempAttrVec->removeAllElements();
00720 
00721             for (XMLSize_t i = 0; i < attrCount; i++)
00722             {
00723                 const XMLCh*   nsPrefix = 0;
00724                 const XMLCh*   nsURI    = 0;
00725 
00726                 const XMLAttr* tempAttr = attrList.elementAt(i);
00727                 const XMLCh* prefix = tempAttr->getPrefix();
00728                 if(prefix && *prefix)
00729                 {
00730                     if(XMLString::equals(prefix, XMLUni::fgXMLNSString))
00731                     {
00732                         nsPrefix = tempAttr->getName();
00733                         nsURI = tempAttr->getValue();
00734                     }
00735                 }
00736                 else if (XMLString::equals(tempAttr->getName(), XMLUni::fgXMLNSString))
00737                 {
00738                     nsPrefix = XMLUni::fgZeroLenString;
00739                     nsURI = tempAttr->getValue();
00740                 }
00741                 if (!fNamespacePrefix)
00742                 {
00743                     if (nsURI == 0)
00744                         fTempAttrVec->addElement((XMLAttr*)tempAttr);
00745                 }
00746                 if (nsURI != 0)
00747                 {
00748                     if(fDocHandler)
00749                         fDocHandler->startPrefixMapping(nsPrefix, nsURI);
00750                     unsigned int nPrefixId=fPrefixesStorage->addOrFind(nsPrefix);
00751                     fPrefixes->push(nPrefixId) ;
00752                     numPrefix++;
00753                 }
00754             }
00755             fPrefixCounts->push(numPrefix) ;
00756             if (!fNamespacePrefix)
00757                 fAttrList.setVector(fTempAttrVec, fTempAttrVec->size(), fScanner);
00758             else
00759                 fAttrList.setVector(&attrList, attrCount, fScanner);
00760 
00761             // call startElement() with namespace declarations
00762             if(fDocHandler)
00763             {
00764                 fDocHandler->startElement
00765                 (
00766                     fScanner->getURIText(elemURLId)
00767                     , baseName
00768                     , elemQName
00769                     , fAttrList
00770                 );
00771             }
00772         }
00773         else // no namespace
00774         {
00775             fAttrList.setVector(&attrList, attrCount, fScanner);
00776             if(fDocHandler)
00777             {
00778                 fDocHandler->startElement(XMLUni::fgZeroLenString,
00779                                           XMLUni::fgZeroLenString,
00780                                           qName->getRawName(),
00781                                           fAttrList);
00782             }
00783         }
00784 
00785 
00786         // If its empty, send the end tag event now
00787         if (isEmpty)
00788         {
00789             // call endPrefixMapping appropriately.
00790             if (getDoNamespaces())
00791             {
00792                 if(fDocHandler)
00793                 {
00794                     fDocHandler->endElement
00795                     (
00796                         fScanner->getURIText(elemURLId)
00797                         , baseName
00798                         , elemQName
00799                     );
00800                 }
00801 
00802                 XMLSize_t numPrefix = fPrefixCounts->pop();
00803                 for (XMLSize_t i = 0; i < numPrefix; ++i)
00804                 {
00805                     unsigned int nPrefixId = fPrefixes->pop() ;
00806                     if(fDocHandler)
00807                         fDocHandler->endPrefixMapping( fPrefixesStorage->getValueForId(nPrefixId) );
00808                 }
00809             }
00810             else
00811             {
00812                 if(fDocHandler)
00813                 {
00814                     fDocHandler->endElement(XMLUni::fgZeroLenString,
00815                                     XMLUni::fgZeroLenString,
00816                                     qName->getRawName());
00817                 }
00818             }
00819         }
00820     }
00821 
00822     //
00823     //  If there are any installed advanced handlers, then lets call them
00824     //  with this info.
00825     //
00826     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00827     {
00828         fAdvDHList[index]->startElement
00829         (
00830             elemDecl
00831             , elemURLId
00832             , elemPrefix
00833             , attrList
00834             , attrCount
00835             , isEmpty
00836             , isRoot
00837         );
00838     }
00839 }
00840 
00841 void SAX2XMLReaderImpl::endElement( const   XMLElementDecl& elemDecl
00842                             , const unsigned int    uriId
00843                             , const bool            isRoot
00844                             , const XMLCh* const    elemPrefix)
00845 {
00846     // Just map to the SAX document handler
00847     if (fDocHandler)
00848     {
00849         const QName* qName=elemDecl.getElementName();
00850         const XMLCh* baseName=qName->getLocalPart();
00851         const XMLCh* elemQName = 0;
00852         if(elemPrefix==0 || *elemPrefix==0)
00853             elemQName=baseName;
00854         else if(XMLString::equals(elemPrefix, qName->getPrefix()))
00855             elemQName=qName->getRawName();
00856         else
00857         {
00858             fTempQName->set(elemPrefix);
00859             fTempQName->append(chColon);
00860             fTempQName->append(baseName);
00861             elemQName=fTempQName->getRawBuffer();
00862         }
00863 
00864         if (getDoNamespaces())
00865         {
00866             if(fDocHandler)
00867             {
00868                 fDocHandler->endElement
00869                 (
00870                     fScanner->getURIText(uriId)
00871                     , baseName
00872                     , elemQName
00873                 );
00874             }
00875 
00876             // get the prefixes back so that we can call endPrefixMapping()
00877             XMLSize_t numPrefix = fPrefixCounts->pop();
00878             for (XMLSize_t i = 0; i < numPrefix; i++)
00879             {
00880                 unsigned int nPrefixId = fPrefixes->pop() ;
00881                 if(fDocHandler)
00882                     fDocHandler->endPrefixMapping( fPrefixesStorage->getValueForId(nPrefixId) );
00883             }
00884         }
00885         else
00886         {
00887             if(fDocHandler)
00888             {
00889               fDocHandler->endElement(XMLUni::fgZeroLenString,
00890                                       XMLUni::fgZeroLenString,
00891                                       qName->getRawName());
00892             }
00893         }
00894     }
00895 
00896     //
00897     //  If there are any installed advanced handlers, then lets call them
00898     //  with this info.
00899     //
00900     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00901         fAdvDHList[index]->endElement(elemDecl, uriId, isRoot, elemPrefix);
00902 
00903     //
00904     //  Dump the element depth down again. Don't let it underflow in case
00905     //  of malformed XML.
00906     //
00907     if (fElemDepth)
00908         fElemDepth--;
00909 }
00910 
00911 void SAX2XMLReaderImpl::startEntityReference(const XMLEntityDecl& entityDecl)
00912 {
00913    // Call the installed LexicalHandler.
00914    if (fLexicalHandler)
00915         fLexicalHandler->startEntity(entityDecl.getName());
00916     //
00917     //  SAX has no way to report this. But, If there are any installed
00918     //  advanced handlers, then lets call them with this info.
00919     //
00920     for (XMLSize_t index = 0; index < fAdvDHCount; index++)
00921         fAdvDHList[index]->startEntityReference(entityDecl);
00922 }
00923 
00924 // ---------------------------------------------------------------------------
00925 //  SAX2XMLReaderImpl: Overrides of the DocTypeHandler interface
00926 // ---------------------------------------------------------------------------
00927 void SAX2XMLReaderImpl::attDef( const   DTDElementDecl& elemDecl
00928                         , const DTDAttDef&      attDef
00929                         , const bool            ignoring)
00930 {
00931     if (fDeclHandler && !ignoring) {
00932 
00933         XMLAttDef::AttTypes attType = attDef.getType();
00934         XMLAttDef::DefAttTypes defAttType = attDef.getDefaultType();
00935         const XMLCh* defAttTypeStr = XMLUni::fgNullString;
00936         bool isEnumeration = (attType == XMLAttDef::Notation || attType == XMLAttDef::Enumeration);
00937         XMLBuffer enumBuf(128, fMemoryManager);
00938 
00939         if (defAttType == XMLAttDef::Fixed ||
00940             defAttType == XMLAttDef::Implied ||
00941             defAttType == XMLAttDef::Required) {
00942             defAttTypeStr = attDef.getDefAttTypeString(defAttType, fMemoryManager);
00943         }
00944 
00945         if (isEnumeration) {
00946 
00947             const XMLCh* enumString = attDef.getEnumeration();
00948             XMLSize_t enumLen = XMLString::stringLen(enumString);
00949 
00950             if (attType == XMLAttDef::Notation) {
00951 
00952                 enumBuf.set(XMLUni::fgNotationString);
00953                 enumBuf.append(chSpace);
00954             }
00955 
00956             enumBuf.append(chOpenParen);
00957 
00958             for (XMLSize_t i=0; i<enumLen; i++) {
00959                 if (enumString[i] == chSpace)
00960                     enumBuf.append(chPipe);
00961                 else
00962                     enumBuf.append(enumString[i]);
00963             }
00964 
00965             enumBuf.append(chCloseParen);
00966         }
00967 
00968         fDeclHandler->attributeDecl(elemDecl.getFullName(),
00969                                     attDef.getFullName(),
00970                                     (isEnumeration) ? enumBuf.getRawBuffer()
00971                                                     : attDef.getAttTypeString(attDef.getType(), fMemoryManager),
00972                                     defAttTypeStr,
00973                                     attDef.getValue());
00974     }
00975 }
00976 
00977 
00978 void SAX2XMLReaderImpl::doctypeComment(const XMLCh* const commentText)
00979 {
00980    if (fLexicalHandler)
00981    {
00982         // SAX2 reports comment text like characters -- as an
00983         // array with a length.
00984         fLexicalHandler->comment(commentText, XMLString::stringLen(commentText));
00985    }
00986 }
00987 
00988 
00989 void SAX2XMLReaderImpl::doctypeDecl(const   DTDElementDecl& elemDecl
00990                             , const XMLCh* const    publicId
00991                             , const XMLCh* const    systemId
00992                             , const bool            hasIntSubset
00993                             , const bool            hasExtSubset)
00994 {
00995     // Call the installed LexicalHandler.
00996     if (fLexicalHandler && (hasIntSubset || hasExtSubset))
00997         fLexicalHandler->startDTD(elemDecl.getFullName(), publicId, systemId);
00998 
00999     fHasExternalSubset = hasExtSubset;
01000 
01001     // Unused by SAX DTDHandler interface at this time
01002 }
01003 
01004 
01005 void SAX2XMLReaderImpl::doctypePI(  const   XMLCh* const
01006                             , const XMLCh* const)
01007 {
01008     // Unused by SAX DTDHandler interface at this time
01009 }
01010 
01011 
01012 void SAX2XMLReaderImpl::doctypeWhitespace(  const   XMLCh* const
01013                                     , const XMLSize_t)
01014 {
01015     // Unused by SAX DTDHandler interface at this time
01016 }
01017 
01018 
01019 void SAX2XMLReaderImpl::elementDecl(const DTDElementDecl& elemDecl,
01020                                     const bool isIgnored)
01021 {
01022     if (fDeclHandler && !isIgnored)
01023         fDeclHandler->elementDecl(elemDecl.getFullName(),
01024                                   elemDecl.getFormattedContentModel());
01025 }
01026 
01027 
01028 void SAX2XMLReaderImpl::endAttList(const DTDElementDecl&)
01029 {
01030     // Unused by SAX DTDHandler interface at this time
01031 }
01032 
01033 
01034 void SAX2XMLReaderImpl::endIntSubset()
01035 {
01036    // Call the installed LexicalHandler.
01037    if (!fHasExternalSubset && fLexicalHandler)
01038         fLexicalHandler->endDTD();
01039 
01040     // Unused by SAX DTDHandler interface at this time
01041 }
01042 
01043 
01044 void SAX2XMLReaderImpl::endExtSubset()
01045 {
01046     // Call the installed LexicalHandler.
01047     if (fLexicalHandler)
01048         fLexicalHandler->endEntity(gDTDEntityStr);
01049     if (fLexicalHandler)
01050         fLexicalHandler->endDTD();
01051 
01052     // Unused by SAX DTDHandler interface at this time
01053 }
01054 
01055 
01056 void SAX2XMLReaderImpl::entityDecl( const   DTDEntityDecl&  entityDecl
01057                             , const bool            isPEDecl
01058                             , const bool            isIgnored)
01059 {
01060     //
01061     //  If we have a DTD handler, and this entity is not ignored, and
01062     //  its an unparsed entity, then send this one, else if we have a Decl
01063     //  handler then send this one.
01064     //
01065     if (!isIgnored) {
01066 
01067         if (entityDecl.isUnparsed()) {
01068 
01069             if (fDTDHandler) {
01070                 fDTDHandler->unparsedEntityDecl
01071                 (
01072                     entityDecl.getName()
01073                     , entityDecl.getPublicId()
01074                     , entityDecl.getSystemId()
01075                     , entityDecl.getNotationName()
01076                 );
01077             }
01078         }
01079         else if (fDeclHandler) {
01080 
01081             const XMLCh* entityName = entityDecl.getName();
01082             ArrayJanitor<XMLCh> tmpNameJan(0);
01083 
01084             if (isPEDecl) {
01085 
01086                 XMLSize_t nameLen = XMLString::stringLen(entityName);
01087                 XMLCh* tmpName = (XMLCh*) fMemoryManager->allocate
01088                 (
01089                     (nameLen + 2) * sizeof(XMLCh)
01090                 );//new XMLCh[nameLen + 2];
01091 
01092                 tmpNameJan.reset(tmpName, fMemoryManager);
01093                 tmpName[0] = chPercent;
01094                 XMLString::copyString(tmpName + 1, entityName);
01095                 entityName = tmpName;
01096             }
01097 
01098             if (entityDecl.isExternal()) {
01099                 fDeclHandler->externalEntityDecl
01100                 (
01101                     entityName
01102                     , entityDecl.getPublicId()
01103                     , entityDecl.getSystemId()
01104                 );
01105             }
01106             else {
01107                 fDeclHandler->internalEntityDecl
01108                 (
01109                     entityName
01110                     , entityDecl.getValue()
01111                 );
01112             }
01113         }
01114     }
01115 }
01116 
01117 
01118 void SAX2XMLReaderImpl::resetDocType()
01119 {
01120     fHasExternalSubset = false;
01121     // Just map to the DTD handler
01122     if (fDTDHandler)
01123         fDTDHandler->resetDocType();
01124 }
01125 
01126 
01127 void SAX2XMLReaderImpl::notationDecl(   const   XMLNotationDecl&    notDecl
01128                                 , const bool                isIgnored)
01129 {
01130     if (fDTDHandler && !isIgnored)
01131     {
01132         fDTDHandler->notationDecl
01133         (
01134             notDecl.getName()
01135             , notDecl.getPublicId()
01136             , notDecl.getSystemId()
01137         );
01138     }
01139 }
01140 
01141 
01142 void SAX2XMLReaderImpl::startAttList(const DTDElementDecl&)
01143 {
01144     // Unused by SAX DTDHandler interface at this time
01145 }
01146 
01147 
01148 void SAX2XMLReaderImpl::startIntSubset()
01149 {
01150     // Unused by SAX DTDHandler interface at this time
01151 }
01152 
01153 
01154 void SAX2XMLReaderImpl::startExtSubset()
01155 {
01156     if (fLexicalHandler)
01157         fLexicalHandler->startEntity(gDTDEntityStr);
01158 }
01159 
01160 
01161 void SAX2XMLReaderImpl::TextDecl(   const  XMLCh* const
01162                             , const XMLCh* const)
01163 {
01164     // Unused by SAX DTDHandler interface at this time
01165 }
01166 
01167 
01168 // ---------------------------------------------------------------------------
01169 //  SAX2XMLReaderImpl: Handlers for the XMLEntityHandler interface
01170 // ---------------------------------------------------------------------------
01171 void SAX2XMLReaderImpl::endInputSource(const InputSource&)
01172 {
01173 }
01174 
01175 bool SAX2XMLReaderImpl::expandSystemId(const XMLCh* const, XMLBuffer&)
01176 {
01177     return false;
01178 }
01179 
01180 
01181 void SAX2XMLReaderImpl::resetEntities()
01182 {
01183     // Nothing to do for this one
01184 }
01185 
01186 InputSource* SAX2XMLReaderImpl::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
01187 {
01188     //
01189     //  Just map it to the SAX entity resolver. If there is not one installed,
01190     //  return a null pointer to cause the default resolution.
01191     //
01192     if (fEntityResolver)
01193         return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
01194                                                 resourceIdentifier->getSystemId());
01195     if (fXMLEntityResolver)
01196         return fXMLEntityResolver->resolveEntity(resourceIdentifier);
01197 
01198     return 0;
01199 }
01200 
01201 void SAX2XMLReaderImpl::startInputSource(const InputSource&)
01202 {
01203     // Nothing to do for this one
01204 }
01205 
01206 // ---------------------------------------------------------------------------
01207 //  SAX2XMLReaderImpl: Overrides of the XMLErrorReporter interface
01208 // ---------------------------------------------------------------------------
01209 void SAX2XMLReaderImpl::resetErrors()
01210 {
01211     if (fErrorHandler)
01212         fErrorHandler->resetErrors();
01213 }
01214 
01215 
01216 void SAX2XMLReaderImpl::error(  const   unsigned int
01217                         , const XMLCh* const
01218                         , const XMLErrorReporter::ErrTypes  errType
01219                         , const XMLCh* const                errorText
01220                         , const XMLCh* const                systemId
01221                         , const XMLCh* const                publicId
01222                         , const XMLFileLoc                  lineNum
01223                         , const XMLFileLoc                  colNum)
01224 {
01225     SAXParseException toThrow = SAXParseException
01226     (
01227         errorText
01228         , publicId
01229         , systemId
01230         , lineNum
01231         , colNum
01232         , fMemoryManager
01233     );
01234 
01235     if (!fErrorHandler)
01236     {
01237         if (errType == XMLErrorReporter::ErrType_Fatal)
01238             throw toThrow;
01239         else
01240             return;
01241     }
01242 
01243     if (errType == XMLErrorReporter::ErrType_Warning)
01244         fErrorHandler->warning(toThrow);
01245     else if (errType == XMLErrorReporter::ErrType_Fatal)
01246         fErrorHandler->fatalError(toThrow);
01247     else
01248         fErrorHandler->error(toThrow);
01249 }
01250 
01251 
01252 // ---------------------------------------------------------------------------
01253 //  SAX2XMLReaderImpl: Features and Properties
01254 // ---------------------------------------------------------------------------
01255 
01256 void SAX2XMLReaderImpl::setFeature(const XMLCh* const name, const bool value)
01257 {
01258 
01259     if (fParseInProgress)
01260         throw SAXNotSupportedException("Feature modification is not supported during parse.", fMemoryManager);
01261 
01262     if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreNameSpaces) == 0)
01263     {
01264         setDoNamespaces(value);
01265     }
01266     else if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreValidation) == 0)
01267     {
01268         fValidation = value;
01269         if (fValidation)
01270             if (fAutoValidation)
01271                 setValidationScheme(Val_Auto);
01272             else
01273                 setValidationScheme(Val_Always);
01274         else
01275             setValidationScheme(Val_Never);
01276     }
01277     else if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreNameSpacePrefixes) == 0)
01278     {
01279         fNamespacePrefix = value;
01280     }
01281     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDynamic) == 0)
01282     {
01283         fAutoValidation = value;
01284         // for auto validation, the sax2 core validation feature must also be enabled.
01285         if (fValidation)
01286             if (fAutoValidation)
01287                 setValidationScheme(Val_Auto);
01288             else
01289                 setValidationScheme(Val_Always);
01290         else
01291             setValidationScheme(Val_Never);
01292     }
01293     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchema) == 0)
01294     {
01295         setDoSchema(value);
01296     }
01297     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaFullChecking) == 0)
01298     {
01299         fScanner->setValidationSchemaFullChecking(value);
01300     }
01301     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0)
01302     {
01303         fScanner->setIdentityConstraintChecking(value);
01304     }
01305     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
01306     {
01307         fScanner->setLoadExternalDTD(value);
01308     }
01309     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0)
01310     {
01311         fScanner->setLoadSchema(value);
01312     }
01313     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesContinueAfterFatalError) == 0)
01314     {
01315         fScanner->setExitOnFirstFatal(!value);
01316     }
01317     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidationErrorAsFatal) == 0)
01318     {
01319         fScanner->setValidationConstraintFatal(value);
01320     }
01321     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCacheGrammarFromParse) == 0)
01322     {
01323         fScanner->cacheGrammarFromParse(value);
01324 
01325         if (value)
01326             fScanner->useCachedGrammarInParse(value);
01327     }
01328     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0)
01329     {
01330         if (value || !fScanner->isCachingGrammarFromParse())
01331             fScanner->useCachedGrammarInParse(value);
01332     }
01333     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCalculateSrcOfs) == 0)
01334     {
01335         fScanner->setCalculateSrcOfs(value);
01336     }
01337     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesStandardUriConformant) == 0)
01338     {
01339         fScanner->setStandardUriConformant(value);
01340     }
01341     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0)
01342     {
01343         fScanner->setGenerateSyntheticAnnotations(value);
01344     }
01345     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidateAnnotations) == 0)
01346     {
01347         fScanner->setValidateAnnotations(value);
01348     }
01349     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreCachedDTD) == 0)
01350     {
01351         fScanner->setIgnoredCachedDTD(value);
01352     }
01353     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreAnnotations) == 0)
01354     {
01355         fScanner->setIgnoreAnnotations(value);
01356     }
01357     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisableDefaultEntityResolution) == 0)
01358     {
01359         fScanner->setDisableDefaultEntityResolution(value);
01360     }
01361     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSkipDTDValidation) == 0)
01362     {
01363         fScanner->setSkipDTDValidation(value);
01364     }
01365     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesHandleMultipleImports) == 0)
01366     {
01367         fScanner->setHandleMultipleImports(value);
01368     }
01369     else
01370        throw SAXNotRecognizedException("Unknown Feature", fMemoryManager);
01371 }
01372 
01373 bool SAX2XMLReaderImpl::getFeature(const XMLCh* const name) const
01374 {
01375     if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreNameSpaces) == 0)
01376         return getDoNamespaces();
01377     else if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreValidation) == 0)
01378         return fValidation;
01379     else if (XMLString::compareIStringASCII(name, XMLUni::fgSAX2CoreNameSpacePrefixes) == 0)
01380         return fNamespacePrefix;
01381     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDynamic) == 0)
01382         return fAutoValidation;
01383     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchema) == 0)
01384         return getDoSchema();
01385     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaFullChecking) == 0)
01386         return fScanner->getValidationSchemaFullChecking();
01387     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0)
01388         return fScanner->getIdentityConstraintChecking();
01389     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0)
01390         return fScanner->getLoadExternalDTD();
01391     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0)
01392         return fScanner->getLoadSchema();
01393     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesContinueAfterFatalError) == 0)
01394         return !fScanner->getExitOnFirstFatal();
01395     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidationErrorAsFatal) == 0)
01396         return fScanner->getValidationConstraintFatal();
01397     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCacheGrammarFromParse) == 0)
01398         return fScanner->isCachingGrammarFromParse();
01399     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0)
01400         return fScanner->isUsingCachedGrammarInParse();
01401     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCalculateSrcOfs) == 0)
01402         return fScanner->getCalculateSrcOfs();
01403     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesStandardUriConformant) == 0)
01404         return fScanner->getStandardUriConformant();
01405     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0)
01406         return fScanner->getGenerateSyntheticAnnotations();
01407     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidateAnnotations) == 0)
01408         return fScanner->getValidateAnnotations();
01409     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreCachedDTD) == 0)
01410         return fScanner->getIgnoreCachedDTD();
01411     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreAnnotations) == 0)
01412         return fScanner->getIgnoreAnnotations();
01413     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisableDefaultEntityResolution) == 0)
01414         return fScanner->getDisableDefaultEntityResolution();
01415     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSkipDTDValidation) == 0)
01416         return fScanner->getSkipDTDValidation();
01417     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesHandleMultipleImports) == 0)
01418         return fScanner->getHandleMultipleImports();
01419     else
01420        throw SAXNotRecognizedException("Unknown Feature", fMemoryManager);
01421 
01422     return false;
01423 }
01424 
01425 void SAX2XMLReaderImpl::setProperty(const XMLCh* const name, void* value)
01426 {
01427     if (fParseInProgress)
01428         throw SAXNotSupportedException("Property modification is not supported during parse.", fMemoryManager);
01429 
01430     if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0)
01431     {
01432         fScanner->setExternalSchemaLocation((XMLCh*)value);
01433     }
01434     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0)
01435     {
01436         fScanner->setExternalNoNamespaceSchemaLocation((XMLCh*)value);
01437     }
01438     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSecurityManager) == 0)
01439     {
01440         fScanner->setSecurityManager((SecurityManager*)value);
01441     }
01442     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLowWaterMark) == 0)
01443     {
01444         fScanner->setLowWaterMark(*(const XMLSize_t*)value);
01445     }
01446     else if (XMLString::equals(name, XMLUni::fgXercesScannerName))
01447     {
01448         XMLScanner* tempScanner = XMLScannerResolver::resolveScanner
01449         (
01450             (const XMLCh*) value
01451             , fValidator
01452             , fGrammarResolver
01453             , fMemoryManager
01454         );
01455 
01456         if (tempScanner) {
01457 
01458             tempScanner->setParseSettings(fScanner);
01459             tempScanner->setURIStringPool(fURIStringPool);
01460             delete fScanner;
01461             fScanner = tempScanner;
01462         }
01463     }
01464     else
01465        throw SAXNotRecognizedException("Unknown Property", fMemoryManager);
01466 }
01467 
01468 
01469 void* SAX2XMLReaderImpl::getProperty(const XMLCh* const name) const
01470 {
01471     if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0)
01472         return (void*)fScanner->getExternalSchemaLocation();
01473     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0)
01474         return (void*)fScanner->getExternalNoNamespaceSchemaLocation();
01475     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSecurityManager) == 0)
01476         return (void*)fScanner->getSecurityManager();
01477     else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLowWaterMark) == 0)
01478         return (void*)&fScanner->getLowWaterMark();
01479     else if (XMLString::equals(name, XMLUni::fgXercesScannerName))
01480         return (void*)fScanner->getName();
01481     else
01482         throw SAXNotRecognizedException("Unknown Property", fMemoryManager);
01483     return 0;
01484 }
01485 
01486 
01487 // ---------------------------------------------------------------------------
01488 //  SAX2XMLReaderImpl: Private getters and setters for conveniences
01489 // ---------------------------------------------------------------------------
01490 
01491 void SAX2XMLReaderImpl::setValidationScheme(const ValSchemes newScheme)
01492 {
01493     if (newScheme == Val_Never)
01494         fScanner->setValidationScheme(XMLScanner::Val_Never);
01495     else if (newScheme == Val_Always)
01496         fScanner->setValidationScheme(XMLScanner::Val_Always);
01497     else
01498         fScanner->setValidationScheme(XMLScanner::Val_Auto);
01499 }
01500 
01501 void SAX2XMLReaderImpl::setDoNamespaces(const bool newState)
01502 {
01503     fScanner->setDoNamespaces(newState);
01504 }
01505 
01506 bool SAX2XMLReaderImpl::getDoNamespaces() const
01507 {
01508     return fScanner->getDoNamespaces();
01509 }
01510 
01511 void SAX2XMLReaderImpl::setDoSchema(const bool newState)
01512 {
01513     fScanner->setDoSchema(newState);
01514 }
01515 
01516 bool SAX2XMLReaderImpl::getDoSchema() const
01517 {
01518     return fScanner->getDoSchema();
01519 }
01520 
01521 
01522 // ---------------------------------------------------------------------------
01523 //  SAX2XMLReaderImpl: Grammar preparsing
01524 // ---------------------------------------------------------------------------
01525 Grammar* SAX2XMLReaderImpl::loadGrammar(const char* const systemId,
01526                                         const Grammar::GrammarType grammarType,
01527                                         const bool toCache)
01528 {
01529     // Avoid multiple entrance
01530     if (fParseInProgress)
01531         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
01532 
01533     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
01534 
01535     Grammar* grammar = 0;
01536     try
01537     {
01538         fParseInProgress = true;
01539         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
01540     }
01541     catch(const OutOfMemoryException&)
01542     {
01543         resetInProgress.release();
01544 
01545         throw;
01546     }
01547 
01548     return grammar;
01549 }
01550 
01551 Grammar* SAX2XMLReaderImpl::loadGrammar(const XMLCh* const systemId,
01552                                         const Grammar::GrammarType grammarType,
01553                                         const bool toCache)
01554 {
01555     // Avoid multiple entrance
01556     if (fParseInProgress)
01557         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
01558 
01559     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
01560 
01561     Grammar* grammar = 0;
01562     try
01563     {
01564         fParseInProgress = true;
01565         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
01566     }
01567     catch(const OutOfMemoryException&)
01568     {
01569         resetInProgress.release();
01570 
01571         throw;
01572     }
01573 
01574     return grammar;
01575 }
01576 
01577 Grammar* SAX2XMLReaderImpl::loadGrammar(const InputSource& source,
01578                                         const Grammar::GrammarType grammarType,
01579                                         const bool toCache)
01580 {
01581     // Avoid multiple entrance
01582     if (fParseInProgress)
01583         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
01584 
01585     ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
01586 
01587     Grammar* grammar = 0;
01588     try
01589     {
01590         fParseInProgress = true;
01591         grammar = fScanner->loadGrammar(source, grammarType, toCache);
01592     }
01593     catch(const OutOfMemoryException&)
01594     {
01595         resetInProgress.release();
01596 
01597         throw;
01598     }
01599 
01600     return grammar;
01601 }
01602 
01603 void SAX2XMLReaderImpl::resetInProgress()
01604 {
01605     fParseInProgress = false;
01606 }
01607 
01608 void SAX2XMLReaderImpl::resetCachedGrammarPool()
01609 {
01610     fGrammarResolver->resetCachedGrammar();
01611     fScanner->resetCachedGrammar();
01612 }
01613 
01614 void SAX2XMLReaderImpl::setInputBufferSize(const XMLSize_t bufferSize)
01615 {
01616     fScanner->setInputBufferSize(bufferSize);
01617 }
01618 
01619 Grammar* SAX2XMLReaderImpl::getGrammar(const XMLCh* const nameSpaceKey)
01620 {
01621     return fGrammarResolver->getGrammar(nameSpaceKey);
01622 }
01623 
01624 
01625 XERCES_CPP_NAMESPACE_END