| API Docs for SAX and DOM |
| Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members # 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,v 1.35 2004/09/28 02:14:14 cargilld Exp $
    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
    00434
    00435
    00436     // -----------------------------------------------------------------------
    00437     //  Setter methods
    00438     // -----------------------------------------------------------------------
    00439
    00453     void setGenerateSyntheticAnnotations(const bool newValue);
    00454
    00462     void setValidateAnnotations(const bool newValue);
    00463
    00478     void setDoNamespaces(const bool newState);
    00479
    00496     void setExitOnFirstFatalError(const bool newState);
    00497
    00517     void setValidationConstraintFatal(const bool newState);
    00518
    00537     void setCreateEntityReferenceNodes(const bool create);
    00538
    00560     void setIncludeIgnorableWhitespace(const bool include);
    00561
    00578     void setValidationScheme(const ValSchemes newScheme);
    00579
    00595     void setDoSchema(const bool newState);
    00596
    00613     void setValidationSchemaFullChecking(const bool schemaFullChecking);
    00614
    00628     void setIdentityConstraintChecking(const bool newState);
    00629
    00650     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
    00651
    00660     void setExternalSchemaLocation(const char* const schemaLocation);
    00661
    00676     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
    00677
    00686     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
    00687
    00703     void setSecurityManager(SecurityManager* const securityManager);
    00704
    00721     void setLoadExternalDTD(const bool newState);
    00722
    00733     void setCreateCommentNodes(const bool create);
    00734
    00747     void setCalculateSrcOfs(const bool newState);
    00748
    00759     void setStandardUriConformant(const bool newState);
    00760
    00768     void useScanner(const XMLCh* const scannerName);
    00769
    00777     void useImplementation(const XMLCh* const implementationFeatures);
    00778
    00787     virtual void setPSVIHandler(PSVIHandler* const handler);
    00788
    00798     void  setCreateSchemaInfo(const bool newState);
    00799
    00801
    00802
    00803     // -----------------------------------------------------------------------
    00804     //  Parsing methods
    00805     // -----------------------------------------------------------------------
    00806
    00809
    00825     void parse(const InputSource& source);
    00826
    00843     void parse(const XMLCh* const systemId);
    00844
    00860     void parse(const char* const systemId);
    00861
    00888     bool parseFirst
    00889     (
    00890         const   XMLCh* const    systemId
    00891         ,       XMLPScanToken&  toFill
    00892     );
    00893
    00921     bool parseFirst
    00922     (
    00923         const   char* const     systemId
    00924         ,       XMLPScanToken&  toFill
    00925     );
    00926
    00954     bool parseFirst
    00955     (
    00956         const   InputSource&    source
    00957         ,       XMLPScanToken&  toFill
    00958     );
    00959
    00982     bool parseNext(XMLPScanToken& token);
    00983
    01009     void parseReset(XMLPScanToken& token);
    01010
    01012
    01013     // -----------------------------------------------------------------------
    01014     //  Implementation of the PSVIHandler interface.
    01015     // -----------------------------------------------------------------------
    01016
    01019
    01030     virtual void handleElementPSVI
    01031     (
    01032         const   XMLCh* const            localName
    01033         , const XMLCh* const            uri
    01034         ,       PSVIElement *           elementInfo
    01035     );
    01036
    01037     virtual void handlePartialElementPSVI
    01038     (
    01039         const   XMLCh* const            localName
    01040         , const XMLCh* const            uri
    01041         ,       PSVIElement *           elementInfo
    01042     );
    01054     virtual void handleAttributesPSVI
    01055     (
    01056         const   XMLCh* const            localName
    01057         , const XMLCh* const            uri
    01058         ,       PSVIAttributeList *     psviAttributes
    01059     );
    01061
    01062     // -----------------------------------------------------------------------
    01063     //  Implementation of the XMLDocumentHandler interface.
    01064     // -----------------------------------------------------------------------
    01065
    01068
    01081     virtual void docCharacters
    01082     (
    01083         const   XMLCh* const    chars
    01084         , const unsigned int    length
    01085         , const bool            cdataSection
    01086     );
    01087
    01096     virtual void docComment
    01097     (
    01098         const   XMLCh* const    comment
    01099     );
    01100
    01113     virtual void docPI
    01114     (
    01115         const   XMLCh* const    target
    01116         , const XMLCh* const    data
    01117     );
    01118
    01123     virtual void endDocument();
    01124
    01141     virtual void endElement
    01142     (
    01143         const   XMLElementDecl& elemDecl
    01144         , const unsigned int    urlId
    01145         , const bool            isRoot
    01146         , const XMLCh* const    elemPrefix
    01147     );
    01148
    01157     virtual void endEntityReference
    01158     (
    01159         const   XMLEntityDecl&  entDecl
    01160     );
    01161
    01180     virtual void ignorableWhitespace
    01181     (
    01182         const   XMLCh* const    chars
    01183         , const unsigned int    length
    01184         , const bool            cdataSection
    01185     );
    01186
    01193     virtual void resetDocument();
    01194
    01199     virtual void startDocument();
    01200
    01228     virtual void startElement
    01229     (
    01230         const   XMLElementDecl&         elemDecl
    01231         , const unsigned int            urlId
    01232         , const XMLCh* const            elemPrefix
    01233         , const RefVectorOf<XMLAttr>&   attrList
    01234         , const unsigned int            attrCount
    01235         , const bool                    isEmpty
    01236         , const bool                    isRoot
    01237     );
    01238
    01248     virtual void startEntityReference
    01249     (
    01250         const   XMLEntityDecl&  entDecl
    01251     );
    01252
    01271     virtual void XMLDecl
    01272     (
    01273         const   XMLCh* const    versionStr
    01274         , const XMLCh* const    encodingStr
    01275         , const XMLCh* const    standaloneStr
    01276         , const XMLCh* const    actualEncStr
    01277     );
    01278
    01298     virtual void elementTypeInfo
    01299     (
    01300         const   XMLCh* const    typeName
    01301         , const XMLCh* const    typeURI
    01302     );
    01304
    01305
    01306     // -----------------------------------------------------------------------
    01307     //  Implementation of the deprecated DocTypeHandler interface.
    01308     // -----------------------------------------------------------------------
    01311     virtual void attDef
    01312     (
    01313         const   DTDElementDecl&     elemDecl
    01314         , const DTDAttDef&          attDef
    01315         , const bool                ignoring
    01316     );
    01317
    01318     virtual void doctypeComment
    01319     (
    01320         const   XMLCh* const    comment
    01321     );
    01322
    01323     virtual void doctypeDecl
    01324     (
    01325         const   DTDElementDecl& elemDecl
    01326         , const XMLCh* const    publicId
    01327         , const XMLCh* const    systemId
    01328         , const bool            hasIntSubset
    01329         , const bool            hasExtSubset = false
    01330     );
    01331
    01332     virtual void doctypePI
    01333     (
    01334         const   XMLCh* const    target
    01335         , const XMLCh* const    data
    01336     );
    01337
    01338     virtual void doctypeWhitespace
    01339     (
    01340         const   XMLCh* const    chars
    01341         , const unsigned int    length
    01342     );
    01343
    01344     virtual void elementDecl
    01345     (
    01346         const   DTDElementDecl& decl
    01347         , const bool            isIgnored
    01348     );
    01349
    01350     virtual void endAttList
    01351     (
    01352         const   DTDElementDecl& elemDecl
    01353     );
    01354
    01355     virtual void endIntSubset();
    01356
    01357     virtual void endExtSubset();
    01358
    01359     virtual void entityDecl
    01360     (
    01361         const   DTDEntityDecl&  entityDecl
    01362         , const bool            isPEDecl
    01363         , const bool            isIgnored
    01364     );
    01365
    01366     virtual void resetDocType();
    01367
    01368     virtual void notationDecl
    01369     (
    01370         const   XMLNotationDecl&    notDecl
    01371         , const bool                isIgnored
    01372     );
    01373
    01374     virtual void startAttList
    01375     (
    01376         const   DTDElementDecl& elemDecl
    01377     );
    01378
    01379     virtual void startIntSubset();
    01380
    01381     virtual void startExtSubset();
    01382
    01383     virtual void TextDecl
    01384     (
    01385         const   XMLCh* const    versionStr
    01386         , const XMLCh* const    encodingStr
    01387     );
    01388
    01389
    01391
    01392
    01393     // -----------------------------------------------------------------------
    01394     //  Deprecated Methods
    01395     // -----------------------------------------------------------------------
    01408     bool getDoValidation() const;
    01409
    01423     void setDoValidation(const bool newState);
    01424
    01438     bool getExpandEntityReferences() const;
    01439
    01456     void setExpandEntityReferences(const bool expand);
    01457
    01459
    01460 protected :
    01461     // -----------------------------------------------------------------------
    01462     //  Protected Constructor Methods
    01463     // -----------------------------------------------------------------------
    01482     AbstractDOMParser
    01483     (
    01484           XMLValidator* const   valToAdopt = 0
    01485         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01486         , XMLGrammarPool* const gramPool = 0
    01487     );
    01488
    01490
    01491     // -----------------------------------------------------------------------
    01492     //  Protected getter methods
    01493     // -----------------------------------------------------------------------
    01501     DOMNode* getCurrentNode();
    01502
    01507     XMLScanner* getScanner() const;
    01508
    01513     GrammarResolver* getGrammarResolver() const;
    01514
    01520     bool getParseInProgress() const;
    01521
    01522     MemoryManager* getMemoryManager() const;
    01523
    01525
    01526
    01527     // -----------------------------------------------------------------------
    01528     //  Protected setter methods
    01529     // -----------------------------------------------------------------------
    01530
    01533
    01541     void setCurrentNode(DOMNode* toSet);
    01542
    01549     void setDocument(DOMDocument* toSet);
    01550
    01557     void setParseInProgress(const bool toSet);
    01559
    01560     // -----------------------------------------------------------------------
    01561     //  Protected Helper methods
    01562     // -----------------------------------------------------------------------
    01565     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
    01566                                               const XMLCh *qualifiedName);
    01567
    01568     void resetPool();
    01569
    01573     bool isDocumentAdopted() const;
    01574
    01576
    01577
    01578 private :
    01579     // -----------------------------------------------------------------------
    01580     //  Initialize/Cleanup methods
    01581     // -----------------------------------------------------------------------
    01582     void initialize();
    01583     void cleanUp();
    01584
    01585     // -----------------------------------------------------------------------
    01586     //  Unimplemented constructors and operators
    01587     // -----------------------------------------------------------------------
    01588     AbstractDOMParser(const AbstractDOMParser&);
    01589     AbstractDOMParser& operator=(const AbstractDOMParser&);
    01590
    01591 protected:
    01592     // -----------------------------------------------------------------------
    01593     //  Protected data members
    01594     //
    01595     //  fCurrentNode
    01596     //  fCurrentParent
    01597     //      Used to track the current node during nested element events. Since
    01598     //      the tree must be built from a set of disjoint callbacks, we need
    01599     //      these to keep up with where we currently are.
    01600     //
    01601     //  fCurrentEntity
    01602     //      Used to track the current entity decl.  If a text decl is seen later on,
    01603     //      it is used to update the encoding and version information.
    01604     //
    01605     //  fDocument
    01606     //      The root document object, filled with the document contents.
    01607     //
    01608     //  fCreateEntityReferenceNodes
    01609     //      Indicates whether entity reference nodes should be created.
    01610     //
    01611     //  fIncludeIgnorableWhitespace
    01612     //      Indicates whether ignorable whiltespace should be added to
    01613     //      the DOM tree for validating parsers.
    01614     //
    01615     //  fScanner
    01616     //      The scanner used for this parser. This is created during the
    01617     //      constructor.
    01618     //
    01619     //  fImplementationFeatures
    01620     //      The implementation features that we use to get an implementation
    01621     //      for use in creating the DOMDocument used during parse. If this is
    01622     //      null then the default DOMImplementation is used
    01623     //
    01624     //  fNodeStack
    01625     //      Used to track previous parent nodes during nested element events.
    01626     //
    01627     //  fParseInProgress
    01628     //      Used to prevent multiple entrance to the parser while its doing
    01629     //      a parse.
    01630     //
    01631     //  fWithinElement
    01632     //      A flag to indicate that the parser is within at least one level
    01633     //      of element processing.
    01634     //
    01635     //  fDocumentType
    01636     //      Used to store and update the documentType variable information
    01637     //      in fDocument
    01638     //
    01639     //  fDocumentVector
    01640     //      Store all the previous fDocument(s) (thus not the current fDocument)
    01641     //      created in this parser.  It is destroyed when the parser is destructed.
    01642     //
    01643     //  fCreateCommentNodes
    01644     //      Indicates whether comment nodes should be created.
    01645     //
    01646     //  fDocumentAdoptedByUser
    01647     //      The DOMDocument ownership has been transferred to application
    01648     //      If set to true, the parser does not own the document anymore
    01649     //      and thus will not release its memory.
    01650     //
    01651     //  fInternalSubset
    01652     //      Buffer for storing the internal subset information.
    01653     //      Once complete (after DOCTYPE is finished scanning), send
    01654     //      it to DocumentType Node
    01655     //
    01656     //   fGrammarPool
    01657     //      The grammar pool passed from external application (through derivatives).
    01658     //      which could be 0, not owned.
    01659     //
    01660     //  fCreateSchemaInfo
    01661     //      Indicates whether element and attributes will have schema info associated
    01662     //
    01663     // -----------------------------------------------------------------------
    01664     bool                          fCreateEntityReferenceNodes;
    01665     bool                          fIncludeIgnorableWhitespace;
    01666     bool                          fWithinElement;
    01667     bool                          fParseInProgress;
    01668     bool                          fCreateCommentNodes;
    01669     bool                          fDocumentAdoptedByUser;
    01670     bool                          fCreateSchemaInfo;
    01671     XMLScanner*                   fScanner;
    01672     XMLCh*                        fImplementationFeatures;
    01673     DOMNode*                      fCurrentParent;
    01674     DOMNode*                      fCurrentNode;
    01675     DOMEntity*                    fCurrentEntity;
    01676     DOMDocumentImpl*              fDocument;
    01677     ValueStackOf<DOMNode*>*       fNodeStack;
    01678     DOMDocumentTypeImpl*          fDocumentType;
    01679     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
    01680     GrammarResolver*              fGrammarResolver;
    01681     XMLStringPool*                fURIStringPool;
    01682     XMLValidator*                 fValidator;
    01683     MemoryManager*                fMemoryManager;
    01684     XMLGrammarPool*               fGrammarPool;
    01685     XMLBufferMgr                  fBufMgr;
    01686     XMLBuffer&                    fInternalSubset;
    01687     PSVIHandler*                  fPSVIHandler;
    01688 };
    01689
    01690
    01691
    01692 // ---------------------------------------------------------------------------
    01693 //  AbstractDOMParser: Getter methods
    01694 // ---------------------------------------------------------------------------
    01695 inline bool AbstractDOMParser::getExpandEntityReferences() const
    01696 {
    01697     return !fCreateEntityReferenceNodes;
    01698 }
    01699 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
    01700 {
    01701     return fCreateEntityReferenceNodes;
    01702 }
    01703
    01704 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
    01705 {
    01706     return fIncludeIgnorableWhitespace;
    01707 }
    01708
    01709 inline bool AbstractDOMParser::getParseInProgress() const
    01710 {
    01711     return fParseInProgress;
    01712 }
    01713
    01714 inline XMLScanner* AbstractDOMParser::getScanner() const
    01715 {
    01716     return fScanner;
    01717 }
    01718
    01719 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
    01720 {
    01721     return fGrammarResolver;
    01722 }
    01723
    01724 inline bool AbstractDOMParser::getCreateCommentNodes() const
    01725 {
    01726     return fCreateCommentNodes;
    01727 }
    01728
    01729 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
    01730 {
    01731     return fPSVIHandler;
    01732 }
    01733
    01734 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
    01735 {
    01736     return fPSVIHandler;
    01737 }
    01738
    01739 inline bool AbstractDOMParser::getCreateSchemaInfo() const
    01740 {
    01741     return fCreateSchemaInfo;
    01742 }
    01743 // ---------------------------------------------------------------------------
    01744 //  AbstractDOMParser: Setter methods
    01745 // ---------------------------------------------------------------------------
    01746 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
    01747 {
    01748     fCreateEntityReferenceNodes = !expand;
    01749 }
    01750
    01751 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
    01752 {
    01753     fCreateEntityReferenceNodes = create;
    01754 }
    01755
    01756 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
    01757 {
    01758     fIncludeIgnorableWhitespace = include;
    01759 }
    01760
    01761 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
    01762 {
    01763     fCreateCommentNodes = create;
    01764 }
    01765
    01766 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
    01767 {
    01768     fMemoryManager->deallocate(fImplementationFeatures);
    01769     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager);
    01770 }
    01771
    01772 // ---------------------------------------------------------------------------
    01773 //  AbstractDOMParser: Protected getter methods
    01774 // ---------------------------------------------------------------------------
    01775 inline DOMNode* AbstractDOMParser::getCurrentNode()
    01776 {
    01777     return fCurrentNode;
    01778 }
    01779
    01780 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
    01781 {
    01782     return fMemoryManager;
    01783 }
    01784
    01785 // ---------------------------------------------------------------------------
    01786 //  AbstractDOMParser: Protected setter methods
    01787 // ---------------------------------------------------------------------------
    01788 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
    01789 {
    01790     fCurrentNode = toSet;
    01791 }
    01792
    01793 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
    01794 {
    01795     fDocument = (DOMDocumentImpl *)toSet;
    01796 }
    01797
    01798 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
    01799 {
    01800     fParseInProgress = toSet;
    01801 }
    01802
    01803 XERCES_CPP_NAMESPACE_END
    01804
    01805 #endif
    01806
    01807
    01808

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