| API Docs for SAX and DOM |

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

# SAXParser.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 1999-2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *      http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016
    00017 /*
    00018  * $Id: SAXParser.hpp 191671 2005-06-21 15:48:06Z cargilld $
    00019  */
    00020
    00021 #if !defined(SAXPARSER_HPP)
    00022 #define SAXPARSER_HPP
    00023
    00024 #include <xercesc/sax/Parser.hpp>
    00025 #include <xercesc/internal/VecAttrListImpl.hpp>
    00026 #include <xercesc/framework/XMLDocumentHandler.hpp>
    00027 #include <xercesc/framework/XMLElementDecl.hpp>
    00028 #include <xercesc/framework/XMLEntityHandler.hpp>
    00029 #include <xercesc/framework/XMLErrorReporter.hpp>
    00030 #include <xercesc/framework/XMLBuffer.hpp>
    00031 #include <xercesc/util/SecurityManager.hpp>
    00032 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
    00033
    00034 XERCES_CPP_NAMESPACE_BEGIN
    00035
    00036
    00037 class DocumentHandler;
    00038 class EntityResolver;
    00039 class XMLPScanToken;
    00040 class XMLScanner;
    00041 class XMLValidator;
    00042 class Grammar;
    00043 class GrammarResolver;
    00044 class XMLGrammarPool;
    00045 class XMLEntityResolver;
    00046 class XMLResourceIdentifier;
    00047 class PSVIHandler;
    00048
    00063 class  SAXParser :
    00064
    00065     public XMemory
    00066     , public Parser
    00067     , public XMLDocumentHandler
    00068     , public XMLErrorReporter
    00069     , public XMLEntityHandler
    00070     , public DocTypeHandler
    00071 {
    00072 public :
    00073     // -----------------------------------------------------------------------
    00074     //  Class types
    00075     // -----------------------------------------------------------------------
    00084     enum ValSchemes
    00085     {
    00086         Val_Never
    00087         , Val_Always
    00088         , Val_Auto
    00089     };
    00090
    00091
    00092     // -----------------------------------------------------------------------
    00093     //  Constructors and Destructor
    00094     // -----------------------------------------------------------------------
    00105     SAXParser
    00106     (
    00107           XMLValidator*   const valToAdopt = 0
    00108         , MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
    00109         , XMLGrammarPool* const gramPool = 0
    00110     );
    00111
    00115     ~SAXParser();
    00117
    00118
    00119     // -----------------------------------------------------------------------
    00120     //  Getter Methods
    00121     // -----------------------------------------------------------------------
    00130     DocumentHandler* getDocumentHandler();
    00131
    00138     const DocumentHandler* getDocumentHandler() const;
    00139
    00146     EntityResolver* getEntityResolver();
    00147
    00154     const EntityResolver* getEntityResolver() const;
    00155
    00162     XMLEntityResolver* getXMLEntityResolver();
    00163
    00170     const XMLEntityResolver* getXMLEntityResolver() const;
    00171
    00178     ErrorHandler* getErrorHandler();
    00179
    00186     const ErrorHandler* getErrorHandler() const;
    00187
    00194     PSVIHandler* getPSVIHandler();
    00195
    00202     const PSVIHandler* getPSVIHandler() const;
    00203
    00210     const XMLValidator& getValidator() const;
    00211
    00219     ValSchemes getValidationScheme() const;
    00220
    00231     bool getDoSchema() const;
    00232
    00243     bool getValidationSchemaFullChecking() const;
    00244
    00255     bool getIdentityConstraintChecking() const;
    00256
    00267     int getErrorCount() const;
    00268
    00278     bool getDoNamespaces() const;
    00279
    00289     bool getExitOnFirstFatalError() const;
    00290
    00301     bool getValidationConstraintFatal() const;
    00302
    00322     XMLCh* getExternalSchemaLocation() const;
    00323
    00343     XMLCh* getExternalNoNamespaceSchemaLocation() const;
    00344
    00360     SecurityManager* getSecurityManager() const;
    00361
    00373     bool getLoadExternalDTD() const;
    00374
    00385     bool isCachingGrammarFromParse() const;
    00386
    00397     bool isUsingCachedGrammarInParse() const;
    00398
    00410     bool getCalculateSrcOfs() const;
    00411
    00422     bool getStandardUriConformant() const;
    00423
    00430     Grammar* getGrammar(const XMLCh* const nameSpaceKey);
    00431
    00437     Grammar* getRootGrammar();
    00438
    00445     const XMLCh* getURIText(unsigned int uriId) const;
    00446
    00453     unsigned int getSrcOffset() const;
    00454
    00466     bool getGenerateSyntheticAnnotations() const;
    00467
    00475     bool getValidateAnnotations() const;
    00476
    00484     bool getIgnoreCachedDTD() const;
    00485
    00493     bool getIgnoreAnnotations() const;
    00494
    00502     bool getDisableDefaultEntityResolution() const;
    00503
    00511     bool getSkipDTDValidation() const;
    00512
    00514
    00515
    00516     // -----------------------------------------------------------------------
    00517     //  Setter methods
    00518     // -----------------------------------------------------------------------
    00519
    00532     void setGenerateSyntheticAnnotations(const bool newValue);
    00533
    00541     void setValidateAnnotations(const bool newValue);
    00542
    00556     void setDoNamespaces(const bool newState);
    00557
    00574     void setValidationScheme(const ValSchemes newScheme);
    00575
    00591     void setDoSchema(const bool newState);
    00592
    00609     void setValidationSchemaFullChecking(const bool schemaFullChecking);
    00610
    00622     void setIdentityConstraintChecking(const bool identityConstraintChecking);
    00623
    00639     void setExitOnFirstFatalError(const bool newState);
    00640
    00660     void setValidationConstraintFatal(const bool newState);
    00661
    00682     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
    00683
    00692     void setExternalSchemaLocation(const char* const schemaLocation);
    00693
    00708     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
    00709
    00718     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
    00719
    00735     void setSecurityManager(SecurityManager* const securityManager);
    00736
    00753     void setLoadExternalDTD(const bool newState);
    00754
    00772     void cacheGrammarFromParse(const bool newState);
    00773
    00792     void useCachedGrammarInParse(const bool newState);
    00793
    00806     void setCalculateSrcOfs(const bool newState);
    00807
    00818     void setStandardUriConformant(const bool newState);
    00819
    00827     void useScanner(const XMLCh* const scannerName);
    00828
    00839     void setInputBufferSize(const size_t bufferSize);
    00840
    00855     void setIgnoreCachedDTD(const bool newValue);
    00856
    00866     void setIgnoreAnnotations(const bool newValue);
    00867
    00882     void setDisableDefaultEntityResolution(const bool newValue);
    00883
    00896     void setSkipDTDValidation(const bool newValue);
    00898
    00899
    00900     // -----------------------------------------------------------------------
    00901     //  Advanced document handler list maintenance methods
    00902     // -----------------------------------------------------------------------
    00903
    00919     void installAdvDocHandler(XMLDocumentHandler* const toInstall);
    00920
    00930     bool removeAdvDocHandler(XMLDocumentHandler* const toRemove);
    00932
    00933
    00934     // -----------------------------------------------------------------------
    00935     //  Progressive scan methods
    00936     // -----------------------------------------------------------------------
    00937
    00940
    00968     bool parseFirst
    00969     (
    00970         const   XMLCh* const    systemId
    00971         ,       XMLPScanToken&  toFill
    00972     );
    00973
    01001     bool parseFirst
    01002     (
    01003         const   char* const     systemId
    01004         ,       XMLPScanToken&  toFill
    01005     );
    01006
    01034     bool parseFirst
    01035     (
    01036         const   InputSource&    source
    01037         ,       XMLPScanToken&  toFill
    01038     );
    01039
    01064     bool parseNext(XMLPScanToken& token);
    01065
    01087     void parseReset(XMLPScanToken& token);
    01088
    01090
    01091     // -----------------------------------------------------------------------
    01092     //  Grammar preparsing interface
    01093     // -----------------------------------------------------------------------
    01094
    01124     Grammar* loadGrammar(const InputSource& source,
    01125                          const short grammarType,
    01126                          const bool toCache = false);
    01127
    01153     Grammar* loadGrammar(const XMLCh* const systemId,
    01154                          const short grammarType,
    01155                          const bool toCache = false);
    01156
    01181     Grammar* loadGrammar(const char* const systemId,
    01182                          const short grammarType,
    01183                          const bool toCache = false);
    01184
    01188     void resetCachedGrammarPool();
    01189
    01191
    01192
    01193     // -----------------------------------------------------------------------
    01194     //  Implementation of the SAX Parser interface
    01195     // -----------------------------------------------------------------------
    01196
    01208     virtual void parse(const InputSource& source);
    01209
    01219     virtual void parse(const XMLCh* const systemId);
    01220
    01228     virtual void parse(const char* const systemId);
    01229
    01240     virtual void setDocumentHandler(DocumentHandler* const handler);
    01241
    01251     virtual void setDTDHandler(DTDHandler* const handler);
    01252
    01263     virtual void setErrorHandler(ErrorHandler* const handler);
    01264
    01275     virtual void setPSVIHandler(PSVIHandler* const handler);
    01276
    01292     virtual void setEntityResolver(EntityResolver* const resolver);
    01293
    01309     virtual void setXMLEntityResolver(XMLEntityResolver* const resolver);
    01310
    01312
    01313
    01314     // -----------------------------------------------------------------------
    01315     //  Implementation of the XMLDocumentHandler interface
    01316     // -----------------------------------------------------------------------
    01317
    01335     virtual void docCharacters
    01336     (
    01337         const   XMLCh* const    chars
    01338         , const unsigned int    length
    01339         , const bool            cdataSection
    01340     );
    01341
    01351     virtual void docComment
    01352     (
    01353         const   XMLCh* const    comment
    01354     );
    01355
    01375     virtual void docPI
    01376     (
    01377         const   XMLCh* const    target
    01378         , const XMLCh* const    data
    01379     );
    01380
    01392     virtual void endDocument();
    01393
    01413     virtual void endElement
    01414     (
    01415         const   XMLElementDecl& elemDecl
    01416         , const unsigned int    urlId
    01417         , const bool            isRoot
    01418         , const XMLCh* const    elemPrefix
    01419     );
    01420
    01431     virtual void endEntityReference
    01432     (
    01433         const   XMLEntityDecl&  entDecl
    01434     );
    01435
    01455     virtual void ignorableWhitespace
    01456     (
    01457         const   XMLCh* const    chars
    01458         , const unsigned int    length
    01459         , const bool            cdataSection
    01460     );
    01461
    01466     virtual void resetDocument();
    01467
    01478     virtual void startDocument();
    01479
    01506     virtual void startElement
    01507     (
    01508         const   XMLElementDecl&         elemDecl
    01509         , const unsigned int            urlId
    01510         , const XMLCh* const            elemPrefix
    01511         , const RefVectorOf<XMLAttr>&   attrList
    01512         , const unsigned int            attrCount
    01513         , const bool                    isEmpty
    01514         , const bool                    isRoot
    01515     );
    01516
    01526     virtual void startEntityReference
    01527     (
    01528         const   XMLEntityDecl&  entDecl
    01529     );
    01530
    01548     virtual void XMLDecl
    01549     (
    01550         const   XMLCh* const    versionStr
    01551         , const XMLCh* const    encodingStr
    01552         , const XMLCh* const    standaloneStr
    01553         , const XMLCh* const    actualEncodingStr
    01554     );
    01556
    01557
    01558     // -----------------------------------------------------------------------
    01559     //  Implementation of the XMLErrorReporter interface
    01560     // -----------------------------------------------------------------------
    01561
    01587     virtual void error
    01588     (
    01589         const   unsigned int                errCode
    01590         , const XMLCh* const                msgDomain
    01591         , const XMLErrorReporter::ErrTypes  errType
    01592         , const XMLCh* const                errorText
    01593         , const XMLCh* const                systemId
    01594         , const XMLCh* const                publicId
    01595         , const XMLSSize_t                  lineNum
    01596         , const XMLSSize_t                  colNum
    01597     );
    01598
    01607     virtual void resetErrors();
    01609
    01610
    01611     // -----------------------------------------------------------------------
    01612     //  Implementation of the XMLEntityHandler interface
    01613     // -----------------------------------------------------------------------
    01614
    01628     virtual void endInputSource(const InputSource& inputSource);
    01629
    01644     virtual bool expandSystemId
    01645     (
    01646         const   XMLCh* const    systemId
    01647         ,       XMLBuffer&      toFill
    01648     );
    01649
    01657     virtual void resetEntities();
    01658
    01681     virtual InputSource* resolveEntity
    01682     (
    01683         const   XMLCh* const    publicId
    01684         , const XMLCh* const    systemId
    01685         , const XMLCh* const    baseURI = 0
    01686     );
    01687
    01704     virtual InputSource* resolveEntity
    01705     (
    01706         XMLResourceIdentifier* resourceIdentifier
    01707     );
    01708
    01720     virtual void startInputSource(const InputSource& inputSource);
    01722
    01723
    01724     // -----------------------------------------------------------------------
    01725     //  Implementation of the Deprecated DocTypeHandler Interface
    01726     // -----------------------------------------------------------------------
    01743     virtual void attDef
    01744     (
    01745         const   DTDElementDecl& elemDecl
    01746         , const DTDAttDef&      attDef
    01747         , const bool            ignore
    01748     );
    01749
    01759     virtual void doctypeComment
    01760     (
    01761         const   XMLCh* const    comment
    01762     );
    01763
    01782     virtual void doctypeDecl
    01783     (
    01784         const   DTDElementDecl& elemDecl
    01785         , const XMLCh* const    publicId
    01786         , const XMLCh* const    systemId
    01787         , const bool            hasIntSubset
    01788         , const bool            hasExtSubset = false
    01789     );
    01790
    01804     virtual void doctypePI
    01805     (
    01806         const   XMLCh* const    target
    01807         , const XMLCh* const    data
    01808     );
    01809
    01821     virtual void doctypeWhitespace
    01822     (
    01823         const   XMLCh* const    chars
    01824         , const unsigned int    length
    01825     );
    01826
    01839     virtual void elementDecl
    01840     (
    01841         const   DTDElementDecl& decl
    01842         , const bool            isIgnored
    01843     );
    01844
    01855     virtual void endAttList
    01856     (
    01857         const   DTDElementDecl& elemDecl
    01858     );
    01859
    01866     virtual void endIntSubset();
    01867
    01874     virtual void endExtSubset();
    01875
    01890     virtual void entityDecl
    01891     (
    01892         const   DTDEntityDecl&  entityDecl
    01893         , const bool            isPEDecl
    01894         , const bool            isIgnored
    01895     );
    01896
    01901     virtual void resetDocType();
    01902
    01915     virtual void notationDecl
    01916     (
    01917         const   XMLNotationDecl&    notDecl
    01918         , const bool                isIgnored
    01919     );
    01920
    01931     virtual void startAttList
    01932     (
    01933         const   DTDElementDecl& elemDecl
    01934     );
    01935
    01942     virtual void startIntSubset();
    01943
    01950     virtual void startExtSubset();
    01951
    01964     virtual void TextDecl
    01965     (
    01966         const   XMLCh* const    versionStr
    01967         , const XMLCh* const    encodingStr
    01968     );
    01970
    01971
    01972     // -----------------------------------------------------------------------
    01973     //  Deprecated Methods
    01974     // -----------------------------------------------------------------------
    01987     bool getDoValidation() const;
    01988
    02002     void setDoValidation(const bool newState);
    02004
    02005
    02006 protected :
    02007     // -----------------------------------------------------------------------
    02008     //  Protected Methods
    02009     // -----------------------------------------------------------------------
    02016     const XMLScanner& getScanner() const;
    02017
    02022     GrammarResolver* getGrammarResolver() const;
    02023
    02024
    02025 private:
    02026     // -----------------------------------------------------------------------
    02027     //  Unimplemented constructors and operators
    02028     // -----------------------------------------------------------------------
    02029     SAXParser(const SAXParser&);
    02030     SAXParser& operator=(const SAXParser&);
    02031
    02032     // -----------------------------------------------------------------------
    02033     //  Initialize/Cleanup methods
    02034     // -----------------------------------------------------------------------
    02035     void initialize();
    02036     void cleanUp();
    02037     void resetInProgress();
    02038
    02039     // -----------------------------------------------------------------------
    02040     //  Private data members
    02041     //
    02042     //  fAttrList
    02043     //      A temporary implementation of the basic SAX attribute list
    02044     //      interface. We use this one over and over on each startElement
    02045     //      event to allow SAX-like access to the element attributes.
    02046     //
    02047     //  fDocHandler
    02048     //      The installed SAX doc handler, if any. Null if none.
    02049     //
    02050     //  fDTDHandler
    02051     //      The installed SAX DTD handler, if any. Null if none.
    02052     //
    02053     //  fElemDepth
    02054     //      This is used to track the element nesting depth, so that we can
    02055     //      know when we are inside content. This is so we can ignore char
    02056     //      data outside of content.
    02057     //
    02058     //  fEntityResolver
    02059     //      The installed SAX entity handler, if any. Null if none.
    02060     //
    02061     //  fErrorHandler
    02062     //      The installed SAX error handler, if any. Null if none.
    02063     //
    02064     //  fPSVIHandler
    02065     //      The installed PSVI handler, if any. Null if none.
    02066     //
    02067     //  fAdvDHCount
    02068     //  fAdvDHList
    02069     //  fAdvDHListSize
    02070     //      This is an array of pointers to XMLDocumentHandlers, which is
    02071     //      how we see installed advanced document handlers. There will
    02072     //      usually not be very many at all, so a simple array is used
    02073     //      instead of a collection, for performance. It will grow if needed,
    02074     //      but that is unlikely.
    02075     //
    02076     //      The count is how many handlers are currently installed. The size
    02077     //      is how big the array itself is (for expansion purposes.) When
    02078     //      count == size, is time to expand.
    02079     //
    02080     //  fParseInProgress
    02081     //      This flag is set once a parse starts. It is used to prevent
    02082     //      multiple entrance or reentrance of the parser.
    02083     //
    02084     //  fScanner
    02085     //      The scanner being used by this parser. It is created internally
    02086     //      during construction.
    02087     //
    02088     //   fGrammarPool
    02089     //      The grammar pool passed from external application (through derivatives).
    02090     //      which could be 0, not owned.
    02091     //
    02092     // -----------------------------------------------------------------------
    02093     bool                 fParseInProgress;
    02094     unsigned int         fElemDepth;
    02095     unsigned int         fAdvDHCount;
    02096     unsigned int         fAdvDHListSize;
    02097     VecAttrListImpl      fAttrList;
    02098     DocumentHandler*     fDocHandler;
    02099     DTDHandler*          fDTDHandler;
    02100     EntityResolver*      fEntityResolver;
    02101     XMLEntityResolver*   fXMLEntityResolver;
    02102     ErrorHandler*        fErrorHandler;
    02103     PSVIHandler*         fPSVIHandler;
    02104     XMLDocumentHandler** fAdvDHList;
    02105     XMLScanner*          fScanner;
    02106     GrammarResolver*     fGrammarResolver;
    02107     XMLStringPool*       fURIStringPool;
    02108     XMLValidator*        fValidator;
    02109     MemoryManager*       fMemoryManager;
    02110     XMLGrammarPool*      fGrammarPool;
    02111     XMLBuffer            fElemQNameBuf;
    02112 };
    02113
    02114
    02115 // ---------------------------------------------------------------------------
    02116 //  SAXParser: Getter methods
    02117 // ---------------------------------------------------------------------------
    02118 inline DocumentHandler* SAXParser::getDocumentHandler()
    02119 {
    02120     return fDocHandler;
    02121 }
    02122
    02123 inline const DocumentHandler* SAXParser::getDocumentHandler() const
    02124 {
    02125     return fDocHandler;
    02126 }
    02127
    02128 inline EntityResolver* SAXParser::getEntityResolver()
    02129 {
    02130     return fEntityResolver;
    02131 }
    02132
    02133 inline XMLEntityResolver* SAXParser::getXMLEntityResolver()
    02134 {
    02135     return fXMLEntityResolver;
    02136 }
    02137
    02138 inline const XMLEntityResolver* SAXParser::getXMLEntityResolver() const
    02139 {
    02140     return fXMLEntityResolver;
    02141 }
    02142
    02143 inline const EntityResolver* SAXParser::getEntityResolver() const
    02144 {
    02145     return fEntityResolver;
    02146 }
    02147
    02148 inline ErrorHandler* SAXParser::getErrorHandler()
    02149 {
    02150     return fErrorHandler;
    02151 }
    02152
    02153 inline const ErrorHandler* SAXParser::getErrorHandler() const
    02154 {
    02155     return fErrorHandler;
    02156 }
    02157
    02158 inline PSVIHandler* SAXParser::getPSVIHandler()
    02159 {
    02160     return fPSVIHandler;
    02161 }
    02162
    02163 inline const PSVIHandler* SAXParser::getPSVIHandler() const
    02164 {
    02165     return fPSVIHandler;
    02166 }
    02167
    02168 inline const XMLScanner& SAXParser::getScanner() const
    02169 {
    02170     return *fScanner;
    02171 }
    02172
    02173 inline GrammarResolver* SAXParser::getGrammarResolver() const
    02174 {
    02175     return fGrammarResolver;
    02176 }
    02177
    02178 XERCES_CPP_NAMESPACE_END
    02179
    02180 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.