| API Docs for SAX and DOM |

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

# AbstractDOMParser.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 2002, 2003,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: AbstractDOMParser.hpp 191708 2005-06-21 19:02:15Z cargilld $
    00019  *
    00020  */
    00021 #if !defined(ABSTRACTDOMPARSER_HPP)
    00022 #define ABSTRACTDOMPARSER_HPP
    00023
    00024 #include <xercesc/dom/DOMDocument.hpp>
    00025 #include <xercesc/framework/XMLDocumentHandler.hpp>
    00026 #include <xercesc/framework/XMLErrorReporter.hpp>
    00027 #include <xercesc/framework/XMLEntityHandler.hpp>
    00028 #include <xercesc/util/SecurityManager.hpp>
    00029 #include <xercesc/util/ValueStackOf.hpp>
    00030 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
    00031 #include <xercesc/dom/DOMDocumentType.hpp>
    00032 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
    00033 #include <xercesc/framework/XMLBufferMgr.hpp>
    00034 #include <xercesc/framework/psvi/PSVIHandler.hpp>
    00035
    00036 XERCES_CPP_NAMESPACE_BEGIN
    00037
    00038 class XMLPScanToken;
    00039 class XMLScanner;
    00040 class XMLValidator;
    00041 class DOMDocumentImpl;
    00042 class DOMDocumentTypeImpl;
    00043 class DOMElement;
    00044 class GrammarResolver;
    00045 class XMLGrammarPool;
    00046 class PSVIHandler;
    00047
    00052 class  AbstractDOMParser :
    00053
    00054     public XMemory
    00055     , public XMLDocumentHandler
    00056     , public XMLErrorReporter
    00057     , public XMLEntityHandler
    00058     , public DocTypeHandler
    00059     , public PSVIHandler
    00060 {
    00061 public :
    00062     // -----------------------------------------------------------------------
    00063     //  Class types
    00064     // -----------------------------------------------------------------------
    00067
    00075     enum ValSchemes
    00076     {
    00077         Val_Never
    00078         , Val_Always
    00079         , Val_Auto
    00080     };
    00081
    00083
    00084
    00085     // -----------------------------------------------------------------------
    00086     //  Constructors and Detructor
    00087     // -----------------------------------------------------------------------
    00090
    00094     virtual ~AbstractDOMParser();
    00095
    00097
    00098     // -----------------------------------------------------------------------
    00099     //  Utility methods
    00100     // -----------------------------------------------------------------------
    00101
    00109     void reset();
    00110
    00124     DOMDocument* adoptDocument();
    00125
    00127
    00128
    00129     // -----------------------------------------------------------------------
    00130     //  Getter methods
    00131     // -----------------------------------------------------------------------
    00132
    00135
    00147     DOMDocument* getDocument();
    00148
    00156     const XMLValidator& getValidator() const;
    00157
    00165     ValSchemes getValidationScheme() const;
    00166
    00177     bool getDoSchema() const;
    00178
    00189     bool getValidationSchemaFullChecking() const;
    00190
    00201     bool getIdentityConstraintChecking() const;
    00202
    00214     int getErrorCount() const;
    00215
    00226     bool getDoNamespaces() const;
    00227
    00240     bool getExitOnFirstFatalError() const;
    00241
    00252     bool getValidationConstraintFatal() const;
    00253
    00263     bool  getCreateEntityReferenceNodes()const;
    00264
    00275     bool getIncludeIgnorableWhitespace() const;
    00276
    00296     XMLCh* getExternalSchemaLocation() const;
    00297
    00317     XMLCh* getExternalNoNamespaceSchemaLocation() const;
    00318
    00334     SecurityManager* getSecurityManager() const;
    00335
    00347     bool getLoadExternalDTD() const;
    00348
    00357     bool  getCreateCommentNodes()const;
    00358
    00370     bool getCalculateSrcOfs() const;
    00371
    00382     bool getStandardUriConformant() const;
    00383
    00390     PSVIHandler* getPSVIHandler();
    00391
    00398     const PSVIHandler* getPSVIHandler() const;
    00399
    00409     bool  getCreateSchemaInfo() const;
    00410
    00422     bool getGenerateSyntheticAnnotations() const;
    00423
    00431     bool getValidateAnnotations() const;
    00432
    00440     bool getIgnoreAnnotations() const;
    00441
    00449     bool getDisableDefaultEntityResolution() const;
    00450
    00458     bool getSkipDTDValidation() const;
    00459
    00461
    00462
    00463     // -----------------------------------------------------------------------
    00464     //  Setter methods
    00465     // -----------------------------------------------------------------------
    00466
    00480     void setGenerateSyntheticAnnotations(const bool newValue);
    00481
    00489     void setValidateAnnotations(const bool newValue);
    00490
    00505     void setDoNamespaces(const bool newState);
    00506
    00523     void setExitOnFirstFatalError(const bool newState);
    00524
    00544     void setValidationConstraintFatal(const bool newState);
    00545
    00564     void setCreateEntityReferenceNodes(const bool create);
    00565
    00587     void setIncludeIgnorableWhitespace(const bool include);
    00588
    00605     void setValidationScheme(const ValSchemes newScheme);
    00606
    00622     void setDoSchema(const bool newState);
    00623
    00640     void setValidationSchemaFullChecking(const bool schemaFullChecking);
    00641
    00655     void setIdentityConstraintChecking(const bool newState);
    00656
    00677     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
    00678
    00687     void setExternalSchemaLocation(const char* const schemaLocation);
    00688
    00703     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
    00704
    00713     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
    00714
    00730     void setSecurityManager(SecurityManager* const securityManager);
    00731
    00748     void setLoadExternalDTD(const bool newState);
    00749
    00760     void setCreateCommentNodes(const bool create);
    00761
    00774     void setCalculateSrcOfs(const bool newState);
    00775
    00786     void setStandardUriConformant(const bool newState);
    00787
    00795     void useScanner(const XMLCh* const scannerName);
    00796
    00804     void useImplementation(const XMLCh* const implementationFeatures);
    00805
    00814     virtual void setPSVIHandler(PSVIHandler* const handler);
    00815
    00825     void  setCreateSchemaInfo(const bool newState);
    00826
    00836     void setIgnoreAnnotations(const bool newValue);
    00837
    00852     void setDisableDefaultEntityResolution(const bool newValue);
    00853
    00866     void setSkipDTDValidation(const bool newValue);
    00868
    00869
    00870     // -----------------------------------------------------------------------
    00871     //  Parsing methods
    00872     // -----------------------------------------------------------------------
    00873
    00876
    00892     void parse(const InputSource& source);
    00893
    00910     void parse(const XMLCh* const systemId);
    00911
    00927     void parse(const char* const systemId);
    00928
    00955     bool parseFirst
    00956     (
    00957         const   XMLCh* const    systemId
    00958         ,       XMLPScanToken&  toFill
    00959     );
    00960
    00988     bool parseFirst
    00989     (
    00990         const   char* const     systemId
    00991         ,       XMLPScanToken&  toFill
    00992     );
    00993
    01021     bool parseFirst
    01022     (
    01023         const   InputSource&    source
    01024         ,       XMLPScanToken&  toFill
    01025     );
    01026
    01049     bool parseNext(XMLPScanToken& token);
    01050
    01076     void parseReset(XMLPScanToken& token);
    01077
    01079
    01080     // -----------------------------------------------------------------------
    01081     //  Implementation of the PSVIHandler interface.
    01082     // -----------------------------------------------------------------------
    01083
    01086
    01097     virtual void handleElementPSVI
    01098     (
    01099         const   XMLCh* const            localName
    01100         , const XMLCh* const            uri
    01101         ,       PSVIElement *           elementInfo
    01102     );
    01103
    01104     virtual void handlePartialElementPSVI
    01105     (
    01106         const   XMLCh* const            localName
    01107         , const XMLCh* const            uri
    01108         ,       PSVIElement *           elementInfo
    01109     );
    01121     virtual void handleAttributesPSVI
    01122     (
    01123         const   XMLCh* const            localName
    01124         , const XMLCh* const            uri
    01125         ,       PSVIAttributeList *     psviAttributes
    01126     );
    01128
    01129     // -----------------------------------------------------------------------
    01130     //  Implementation of the XMLDocumentHandler interface.
    01131     // -----------------------------------------------------------------------
    01132
    01135
    01148     virtual void docCharacters
    01149     (
    01150         const   XMLCh* const    chars
    01151         , const unsigned int    length
    01152         , const bool            cdataSection
    01153     );
    01154
    01163     virtual void docComment
    01164     (
    01165         const   XMLCh* const    comment
    01166     );
    01167
    01180     virtual void docPI
    01181     (
    01182         const   XMLCh* const    target
    01183         , const XMLCh* const    data
    01184     );
    01185
    01190     virtual void endDocument();
    01191
    01208     virtual void endElement
    01209     (
    01210         const   XMLElementDecl& elemDecl
    01211         , const unsigned int    urlId
    01212         , const bool            isRoot
    01213         , const XMLCh* const    elemPrefix
    01214     );
    01215
    01224     virtual void endEntityReference
    01225     (
    01226         const   XMLEntityDecl&  entDecl
    01227     );
    01228
    01247     virtual void ignorableWhitespace
    01248     (
    01249         const   XMLCh* const    chars
    01250         , const unsigned int    length
    01251         , const bool            cdataSection
    01252     );
    01253
    01260     virtual void resetDocument();
    01261
    01266     virtual void startDocument();
    01267
    01295     virtual void startElement
    01296     (
    01297         const   XMLElementDecl&         elemDecl
    01298         , const unsigned int            urlId
    01299         , const XMLCh* const            elemPrefix
    01300         , const RefVectorOf<XMLAttr>&   attrList
    01301         , const unsigned int            attrCount
    01302         , const bool                    isEmpty
    01303         , const bool                    isRoot
    01304     );
    01305
    01315     virtual void startEntityReference
    01316     (
    01317         const   XMLEntityDecl&  entDecl
    01318     );
    01319
    01338     virtual void XMLDecl
    01339     (
    01340         const   XMLCh* const    versionStr
    01341         , const XMLCh* const    encodingStr
    01342         , const XMLCh* const    standaloneStr
    01343         , const XMLCh* const    actualEncStr
    01344     );
    01345
    01365     virtual void elementTypeInfo
    01366     (
    01367         const   XMLCh* const    typeName
    01368         , const XMLCh* const    typeURI
    01369     );
    01371
    01372
    01373     // -----------------------------------------------------------------------
    01374     //  Implementation of the deprecated DocTypeHandler interface.
    01375     // -----------------------------------------------------------------------
    01378     virtual void attDef
    01379     (
    01380         const   DTDElementDecl&     elemDecl
    01381         , const DTDAttDef&          attDef
    01382         , const bool                ignoring
    01383     );
    01384
    01385     virtual void doctypeComment
    01386     (
    01387         const   XMLCh* const    comment
    01388     );
    01389
    01390     virtual void doctypeDecl
    01391     (
    01392         const   DTDElementDecl& elemDecl
    01393         , const XMLCh* const    publicId
    01394         , const XMLCh* const    systemId
    01395         , const bool            hasIntSubset
    01396         , const bool            hasExtSubset = false
    01397     );
    01398
    01399     virtual void doctypePI
    01400     (
    01401         const   XMLCh* const    target
    01402         , const XMLCh* const    data
    01403     );
    01404
    01405     virtual void doctypeWhitespace
    01406     (
    01407         const   XMLCh* const    chars
    01408         , const unsigned int    length
    01409     );
    01410
    01411     virtual void elementDecl
    01412     (
    01413         const   DTDElementDecl& decl
    01414         , const bool            isIgnored
    01415     );
    01416
    01417     virtual void endAttList
    01418     (
    01419         const   DTDElementDecl& elemDecl
    01420     );
    01421
    01422     virtual void endIntSubset();
    01423
    01424     virtual void endExtSubset();
    01425
    01426     virtual void entityDecl
    01427     (
    01428         const   DTDEntityDecl&  entityDecl
    01429         , const bool            isPEDecl
    01430         , const bool            isIgnored
    01431     );
    01432
    01433     virtual void resetDocType();
    01434
    01435     virtual void notationDecl
    01436     (
    01437         const   XMLNotationDecl&    notDecl
    01438         , const bool                isIgnored
    01439     );
    01440
    01441     virtual void startAttList
    01442     (
    01443         const   DTDElementDecl& elemDecl
    01444     );
    01445
    01446     virtual void startIntSubset();
    01447
    01448     virtual void startExtSubset();
    01449
    01450     virtual void TextDecl
    01451     (
    01452         const   XMLCh* const    versionStr
    01453         , const XMLCh* const    encodingStr
    01454     );
    01455
    01456
    01458
    01459
    01460     // -----------------------------------------------------------------------
    01461     //  Deprecated Methods
    01462     // -----------------------------------------------------------------------
    01475     bool getDoValidation() const;
    01476
    01490     void setDoValidation(const bool newState);
    01491
    01505     bool getExpandEntityReferences() const;
    01506
    01523     void setExpandEntityReferences(const bool expand);
    01524
    01526
    01527 protected :
    01528     // -----------------------------------------------------------------------
    01529     //  Protected Constructor Methods
    01530     // -----------------------------------------------------------------------
    01549     AbstractDOMParser
    01550     (
    01551           XMLValidator* const   valToAdopt = 0
    01552         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01553         , XMLGrammarPool* const gramPool = 0
    01554     );
    01555
    01557
    01558     // -----------------------------------------------------------------------
    01559     //  Protected getter methods
    01560     // -----------------------------------------------------------------------
    01568     DOMNode* getCurrentNode();
    01569
    01574     XMLScanner* getScanner() const;
    01575
    01580     GrammarResolver* getGrammarResolver() const;
    01581
    01587     bool getParseInProgress() const;
    01588
    01589     MemoryManager* getMemoryManager() const;
    01590
    01592
    01593
    01594     // -----------------------------------------------------------------------
    01595     //  Protected setter methods
    01596     // -----------------------------------------------------------------------
    01597
    01600
    01608     void setCurrentNode(DOMNode* toSet);
    01609
    01616     void setDocument(DOMDocument* toSet);
    01617
    01624     void setParseInProgress(const bool toSet);
    01626
    01627     // -----------------------------------------------------------------------
    01628     //  Protected Helper methods
    01629     // -----------------------------------------------------------------------
    01632     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
    01633                                               const XMLCh *qualifiedName);
    01634
    01635     void resetPool();
    01636
    01640     bool isDocumentAdopted() const;
    01641
    01643
    01644
    01645 private :
    01646     // -----------------------------------------------------------------------
    01647     //  Initialize/Cleanup methods
    01648     // -----------------------------------------------------------------------
    01649     void initialize();
    01650     void cleanUp();
    01651     void resetInProgress();
    01652
    01653     // -----------------------------------------------------------------------
    01654     //  Unimplemented constructors and operators
    01655     // -----------------------------------------------------------------------
    01656     AbstractDOMParser(const AbstractDOMParser&);
    01657     AbstractDOMParser& operator=(const AbstractDOMParser&);
    01658
    01659 protected:
    01660     // -----------------------------------------------------------------------
    01661     //  Protected data members
    01662     //
    01663     //  fCurrentNode
    01664     //  fCurrentParent
    01665     //      Used to track the current node during nested element events. Since
    01666     //      the tree must be built from a set of disjoint callbacks, we need
    01667     //      these to keep up with where we currently are.
    01668     //
    01669     //  fCurrentEntity
    01670     //      Used to track the current entity decl.  If a text decl is seen later on,
    01671     //      it is used to update the encoding and version information.
    01672     //
    01673     //  fDocument
    01674     //      The root document object, filled with the document contents.
    01675     //
    01676     //  fCreateEntityReferenceNodes
    01677     //      Indicates whether entity reference nodes should be created.
    01678     //
    01679     //  fIncludeIgnorableWhitespace
    01680     //      Indicates whether ignorable whiltespace should be added to
    01681     //      the DOM tree for validating parsers.
    01682     //
    01683     //  fScanner
    01684     //      The scanner used for this parser. This is created during the
    01685     //      constructor.
    01686     //
    01687     //  fImplementationFeatures
    01688     //      The implementation features that we use to get an implementation
    01689     //      for use in creating the DOMDocument used during parse. If this is
    01690     //      null then the default DOMImplementation is used
    01691     //
    01692     //  fNodeStack
    01693     //      Used to track previous parent nodes during nested element events.
    01694     //
    01695     //  fParseInProgress
    01696     //      Used to prevent multiple entrance to the parser while its doing
    01697     //      a parse.
    01698     //
    01699     //  fWithinElement
    01700     //      A flag to indicate that the parser is within at least one level
    01701     //      of element processing.
    01702     //
    01703     //  fDocumentType
    01704     //      Used to store and update the documentType variable information
    01705     //      in fDocument
    01706     //
    01707     //  fDocumentVector
    01708     //      Store all the previous fDocument(s) (thus not the current fDocument)
    01709     //      created in this parser.  It is destroyed when the parser is destructed.
    01710     //
    01711     //  fCreateCommentNodes
    01712     //      Indicates whether comment nodes should be created.
    01713     //
    01714     //  fDocumentAdoptedByUser
    01715     //      The DOMDocument ownership has been transferred to application
    01716     //      If set to true, the parser does not own the document anymore
    01717     //      and thus will not release its memory.
    01718     //
    01719     //  fInternalSubset
    01720     //      Buffer for storing the internal subset information.
    01721     //      Once complete (after DOCTYPE is finished scanning), send
    01722     //      it to DocumentType Node
    01723     //
    01724     //   fGrammarPool
    01725     //      The grammar pool passed from external application (through derivatives).
    01726     //      which could be 0, not owned.
    01727     //
    01728     //  fCreateSchemaInfo
    01729     //      Indicates whether element and attributes will have schema info associated
    01730     //
    01731     // -----------------------------------------------------------------------
    01732     bool                          fCreateEntityReferenceNodes;
    01733     bool                          fIncludeIgnorableWhitespace;
    01734     bool                          fWithinElement;
    01735     bool                          fParseInProgress;
    01736     bool                          fCreateCommentNodes;
    01737     bool                          fDocumentAdoptedByUser;
    01738     bool                          fCreateSchemaInfo;
    01739     XMLScanner*                   fScanner;
    01740     XMLCh*                        fImplementationFeatures;
    01741     DOMNode*                      fCurrentParent;
    01742     DOMNode*                      fCurrentNode;
    01743     DOMEntity*                    fCurrentEntity;
    01744     DOMDocumentImpl*              fDocument;
    01745     ValueStackOf<DOMNode*>*       fNodeStack;
    01746     DOMDocumentTypeImpl*          fDocumentType;
    01747     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
    01748     GrammarResolver*              fGrammarResolver;
    01749     XMLStringPool*                fURIStringPool;
    01750     XMLValidator*                 fValidator;
    01751     MemoryManager*                fMemoryManager;
    01752     XMLGrammarPool*               fGrammarPool;
    01753     XMLBufferMgr                  fBufMgr;
    01754     XMLBuffer&                    fInternalSubset;
    01755     PSVIHandler*                  fPSVIHandler;
    01756 };
    01757
    01758
    01759
    01760 // ---------------------------------------------------------------------------
    01761 //  AbstractDOMParser: Getter methods
    01762 // ---------------------------------------------------------------------------
    01763 inline bool AbstractDOMParser::getExpandEntityReferences() const
    01764 {
    01765     return !fCreateEntityReferenceNodes;
    01766 }
    01767 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
    01768 {
    01769     return fCreateEntityReferenceNodes;
    01770 }
    01771
    01772 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
    01773 {
    01774     return fIncludeIgnorableWhitespace;
    01775 }
    01776
    01777 inline bool AbstractDOMParser::getParseInProgress() const
    01778 {
    01779     return fParseInProgress;
    01780 }
    01781
    01782 inline XMLScanner* AbstractDOMParser::getScanner() const
    01783 {
    01784     return fScanner;
    01785 }
    01786
    01787 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
    01788 {
    01789     return fGrammarResolver;
    01790 }
    01791
    01792 inline bool AbstractDOMParser::getCreateCommentNodes() const
    01793 {
    01794     return fCreateCommentNodes;
    01795 }
    01796
    01797 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
    01798 {
    01799     return fPSVIHandler;
    01800 }
    01801
    01802 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
    01803 {
    01804     return fPSVIHandler;
    01805 }
    01806
    01807 inline bool AbstractDOMParser::getCreateSchemaInfo() const
    01808 {
    01809     return fCreateSchemaInfo;
    01810 }
    01811 // ---------------------------------------------------------------------------
    01812 //  AbstractDOMParser: Setter methods
    01813 // ---------------------------------------------------------------------------
    01814 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
    01815 {
    01816     fCreateEntityReferenceNodes = !expand;
    01817 }
    01818
    01819 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
    01820 {
    01821     fCreateEntityReferenceNodes = create;
    01822 }
    01823
    01824 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
    01825 {
    01826     fIncludeIgnorableWhitespace = include;
    01827 }
    01828
    01829 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
    01830 {
    01831     fCreateCommentNodes = create;
    01832 }
    01833
    01834 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
    01835 {
    01836     fMemoryManager->deallocate(fImplementationFeatures);
    01837     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager);
    01838 }
    01839
    01840 // ---------------------------------------------------------------------------
    01841 //  AbstractDOMParser: Protected getter methods
    01842 // ---------------------------------------------------------------------------
    01843 inline DOMNode* AbstractDOMParser::getCurrentNode()
    01844 {
    01845     return fCurrentNode;
    01846 }
    01847
    01848 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
    01849 {
    01850     return fMemoryManager;
    01851 }
    01852
    01853 // ---------------------------------------------------------------------------
    01854 //  AbstractDOMParser: Protected setter methods
    01855 // ---------------------------------------------------------------------------
    01856 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
    01857 {
    01858     fCurrentNode = toSet;
    01859 }
    01860
    01861 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
    01862 {
    01863     fParseInProgress = toSet;
    01864 }
    01865
    01866 XERCES_CPP_NAMESPACE_END
    01867
    01868 #endif
    01869
    01870
    01871

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