http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

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  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2002, 2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 2001, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: AbstractDOMParser.hpp,v 1.19 2003/05/16 21:36:59 knoaman Exp $
00059  *
00060  */
00061 #if !defined(ABSTRACTDOMPARSER_HPP)
00062 #define ABSTRACTDOMPARSER_HPP
00063 
00064 #include <xercesc/dom/DOMDocument.hpp>
00065 #include <xercesc/framework/XMLDocumentHandler.hpp>
00066 #include <xercesc/framework/XMLErrorReporter.hpp>
00067 #include <xercesc/framework/XMLEntityHandler.hpp>
00068 #include <xercesc/util/SecurityManager.hpp>
00069 #include <xercesc/util/ValueStackOf.hpp>
00070 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00071 #include <xercesc/dom/DOMDocumentType.hpp>
00072 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00073 #include <xercesc/framework/XMLBufferMgr.hpp>
00074 
00075 
00076 XERCES_CPP_NAMESPACE_BEGIN
00077 
00078 class XMLPScanToken;
00079 class XMLScanner;
00080 class XMLValidator;
00081 class DOMDocumentImpl;
00082 class DOMDocumentTypeImpl;
00083 class DOMElement;
00084 class GrammarResolver;
00085 
00086 
00091 class  AbstractDOMParser :
00092 
00093     public XMemory
00094     , public XMLDocumentHandler
00095     , public XMLErrorReporter
00096     , public XMLEntityHandler
00097     , public DocTypeHandler
00098 {
00099 public :
00100     // -----------------------------------------------------------------------
00101     //  Class types
00102     // -----------------------------------------------------------------------
00105 
00113     enum ValSchemes
00114     {
00115         Val_Never
00116         , Val_Always
00117         , Val_Auto
00118     };
00120 
00121 
00122     // -----------------------------------------------------------------------
00123     //  Constructors and Detructor
00124     // -----------------------------------------------------------------------
00127 
00131     virtual ~AbstractDOMParser();
00132 
00134 
00135     // -----------------------------------------------------------------------
00136     //  Utility methods
00137     // -----------------------------------------------------------------------
00138 
00146     void reset();
00147 
00161     DOMDocument* adoptDocument();
00162 
00164 
00165 
00166     // -----------------------------------------------------------------------
00167     //  Getter methods
00168     // -----------------------------------------------------------------------
00169 
00172 
00184     DOMDocument* getDocument();
00185 
00193     const XMLValidator& getValidator() const;
00194 
00202     ValSchemes getValidationScheme() const;
00203 
00214     bool getDoSchema() const;
00215 
00226     bool getValidationSchemaFullChecking() const;
00227 
00239     int getErrorCount() const;
00240 
00251     bool getDoNamespaces() const;
00252 
00265     bool getExitOnFirstFatalError() const;
00266 
00277     bool getValidationConstraintFatal() const;
00278 
00288     bool  getCreateEntityReferenceNodes()const;
00289 
00300     bool getIncludeIgnorableWhitespace() const;
00301 
00321     XMLCh* getExternalSchemaLocation() const;
00322 
00342     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00343 
00359     SecurityManager* getSecurityManager() const;
00360 
00372     bool getLoadExternalDTD() const;
00373 
00382     bool  getCreateCommentNodes()const;
00383 
00395     bool getCalculateSrcOfs() const;
00396 
00407     bool getStandardUriConformant() const;
00408 
00410 
00411 
00412     // -----------------------------------------------------------------------
00413     //  Setter methods
00414     // -----------------------------------------------------------------------
00415 
00418 
00433     void setDoNamespaces(const bool newState);
00434 
00451     void setExitOnFirstFatalError(const bool newState);
00452 
00472     void setValidationConstraintFatal(const bool newState);
00473 
00492     void setCreateEntityReferenceNodes(const bool create);
00493 
00515     void setIncludeIgnorableWhitespace(const bool include);
00516 
00533     void setValidationScheme(const ValSchemes newScheme);
00534 
00550     void setDoSchema(const bool newState);
00551 
00568     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00569 
00590     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00591 
00600     void setExternalSchemaLocation(const char* const schemaLocation);
00601 
00616     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00617 
00626     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00627 
00643     void setSecurityManager(SecurityManager* const securityManager);
00644 
00661     void setLoadExternalDTD(const bool newState);
00662 
00673     void setCreateCommentNodes(const bool create);
00674 
00687     void setCalculateSrcOfs(const bool newState);
00688 
00699     void setStandardUriConformant(const bool newState);
00700 
00708     void useScanner(const XMLCh* const scannerName);
00709 
00711 
00712 
00713     // -----------------------------------------------------------------------
00714     //  Parsing methods
00715     // -----------------------------------------------------------------------
00716 
00719 
00735     void parse(const InputSource& source);
00736 
00753     void parse(const XMLCh* const systemId);
00754 
00770     void parse(const char* const systemId);
00771 
00798     bool parseFirst
00799     (
00800         const   XMLCh* const    systemId
00801         ,       XMLPScanToken&  toFill
00802     );
00803 
00831     bool parseFirst
00832     (
00833         const   char* const     systemId
00834         ,       XMLPScanToken&  toFill
00835     );
00836 
00864     bool parseFirst
00865     (
00866         const   InputSource&    source
00867         ,       XMLPScanToken&  toFill
00868     );
00869 
00892     bool parseNext(XMLPScanToken& token);
00893 
00919     void parseReset(XMLPScanToken& token);
00920 
00922 
00923     // -----------------------------------------------------------------------
00924     //  Implementation of the XMLDocumentHandler interface.
00925     // -----------------------------------------------------------------------
00926 
00929 
00942     virtual void docCharacters
00943     (
00944         const   XMLCh* const    chars
00945         , const unsigned int    length
00946         , const bool            cdataSection
00947     );
00948 
00957     virtual void docComment
00958     (
00959         const   XMLCh* const    comment
00960     );
00961 
00974     virtual void docPI
00975     (
00976         const   XMLCh* const    target
00977         , const XMLCh* const    data
00978     );
00979 
00984     virtual void endDocument();
00985 
01002     virtual void endElement
01003     (
01004         const   XMLElementDecl& elemDecl
01005         , const unsigned int    urlId
01006         , const bool            isRoot
01007         , const XMLCh* const    elemPrefix
01008     );
01009 
01018     virtual void endEntityReference
01019     (
01020         const   XMLEntityDecl&  entDecl
01021     );
01022 
01041     virtual void ignorableWhitespace
01042     (
01043         const   XMLCh* const    chars
01044         , const unsigned int    length
01045         , const bool            cdataSection
01046     );
01047 
01054     virtual void resetDocument();
01055 
01060     virtual void startDocument();
01061 
01089     virtual void startElement
01090     (
01091         const   XMLElementDecl&         elemDecl
01092         , const unsigned int            urlId
01093         , const XMLCh* const            elemPrefix
01094         , const RefVectorOf<XMLAttr>&   attrList
01095         , const unsigned int            attrCount
01096         , const bool                    isEmpty
01097         , const bool                    isRoot
01098     );
01099 
01109     virtual void startEntityReference
01110     (
01111         const   XMLEntityDecl&  entDecl
01112     );
01113 
01132     virtual void XMLDecl
01133     (
01134         const   XMLCh* const    versionStr
01135         , const XMLCh* const    encodingStr
01136         , const XMLCh* const    standaloneStr
01137         , const XMLCh* const    actualEncStr
01138     );
01140 
01141 
01142     // -----------------------------------------------------------------------
01143     //  Implementation of the deprecated DocTypeHandler interface.
01144     // -----------------------------------------------------------------------
01147     virtual void attDef
01148     (
01149         const   DTDElementDecl&     elemDecl
01150         , const DTDAttDef&          attDef
01151         , const bool                ignoring
01152     );
01153 
01154     virtual void doctypeComment
01155     (
01156         const   XMLCh* const    comment
01157     );
01158 
01159     virtual void doctypeDecl
01160     (
01161         const   DTDElementDecl& elemDecl
01162         , const XMLCh* const    publicId
01163         , const XMLCh* const    systemId
01164         , const bool            hasIntSubset
01165         , const bool            hasExtSubset = false
01166     );
01167 
01168     virtual void doctypePI
01169     (
01170         const   XMLCh* const    target
01171         , const XMLCh* const    data
01172     );
01173 
01174     virtual void doctypeWhitespace
01175     (
01176         const   XMLCh* const    chars
01177         , const unsigned int    length
01178     );
01179 
01180     virtual void elementDecl
01181     (
01182         const   DTDElementDecl& decl
01183         , const bool            isIgnored
01184     );
01185 
01186     virtual void endAttList
01187     (
01188         const   DTDElementDecl& elemDecl
01189     );
01190 
01191     virtual void endIntSubset();
01192 
01193     virtual void endExtSubset();
01194 
01195     virtual void entityDecl
01196     (
01197         const   DTDEntityDecl&  entityDecl
01198         , const bool            isPEDecl
01199         , const bool            isIgnored
01200     );
01201 
01202     virtual void resetDocType();
01203 
01204     virtual void notationDecl
01205     (
01206         const   XMLNotationDecl&    notDecl
01207         , const bool                isIgnored
01208     );
01209 
01210     virtual void startAttList
01211     (
01212         const   DTDElementDecl& elemDecl
01213     );
01214 
01215     virtual void startIntSubset();
01216 
01217     virtual void startExtSubset();
01218 
01219     virtual void TextDecl
01220     (
01221         const   XMLCh* const    versionStr
01222         , const XMLCh* const    encodingStr
01223     );
01224 
01225 
01227 
01228 
01229     // -----------------------------------------------------------------------
01230     //  Deprecated Methods
01231     // -----------------------------------------------------------------------
01244     bool getDoValidation() const;
01245 
01259     void setDoValidation(const bool newState);
01260 
01274     bool getExpandEntityReferences() const;
01275 
01292     void setExpandEntityReferences(const bool expand);
01293 
01295 
01296 protected :
01297     // -----------------------------------------------------------------------
01298     //  Protected Constructor Methods
01299     // -----------------------------------------------------------------------
01311     AbstractDOMParser
01312     (
01313           XMLValidator* const valToAdopt = 0
01314         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01315     );
01316 
01318 
01319     // -----------------------------------------------------------------------
01320     //  Protected getter methods
01321     // -----------------------------------------------------------------------
01329     DOMNode* getCurrentNode();
01330 
01335     XMLScanner* getScanner() const;
01336 
01341     GrammarResolver* getGrammarResolver() const;
01342 
01348     bool getParseInProgress() const;
01349 
01350     MemoryManager* getMemoryManager() const;
01351 
01353 
01354 
01355     // -----------------------------------------------------------------------
01356     //  Protected setter methods
01357     // -----------------------------------------------------------------------
01358 
01361 
01369     void setCurrentNode(DOMNode* toSet);
01370 
01377     void setDocument(DOMDocument* toSet);
01378 
01385     void setParseInProgress(const bool toSet);
01387 
01388     // -----------------------------------------------------------------------
01389     //  Protected Helper methods
01390     // -----------------------------------------------------------------------
01393     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
01394                                               const XMLCh *qualifiedName);
01395 
01396     void resetPool();
01397 
01401     bool isDocumentAdopted() const;
01402 
01404 
01405 
01406 private :
01407     // -----------------------------------------------------------------------
01408     //  Initialize/Cleanup methods
01409     // -----------------------------------------------------------------------
01410     void initialize();
01411     void cleanUp();
01412 
01413     // -----------------------------------------------------------------------
01414     //  Private data members
01415     //
01416     //  fCurrentNode
01417     //  fCurrentParent
01418     //      Used to track the current node during nested element events. Since
01419     //      the tree must be built from a set of disjoint callbacks, we need
01420     //      these to keep up with where we currently are.
01421     //
01422     //  fCurrentEntity
01423     //      Used to track the current entity decl.  If a text decl is seen later on,
01424     //      it is used to update the encoding and version information.
01425     //
01426     //  fDocument
01427     //      The root document object, filled with the document contents.
01428     //
01429     //  fCreateEntityReferenceNodes
01430     //      Indicates whether entity reference nodes should be created.
01431     //
01432     //  fIncludeIgnorableWhitespace
01433     //      Indicates whether ignorable whiltespace should be added to
01434     //      the DOM tree for validating parsers.
01435     //
01436     //  fScanner
01437     //      The scanner used for this parser. This is created during the
01438     //      constructor.
01439     //
01440     //  fNodeStack
01441     //      Used to track previous parent nodes during nested element events.
01442     //
01443     //  fParseInProgress
01444     //      Used to prevent multiple entrance to the parser while its doing
01445     //      a parse.
01446     //
01447     //  fWithinElement
01448     //      A flag to indicate that the parser is within at least one level
01449     //      of element processing.
01450     //
01451     //  fDocumentType
01452     //      Used to store and update the documentType variable information
01453     //      in fDocument
01454     //
01455     //  fDocumentVector
01456     //      Store all the previous fDocument(s) (thus not the current fDocument)
01457     //      created in this parser.  It is destroyed when the parser is destructed.
01458     //
01459     //  fCreateCommentNodes
01460     //      Indicates whether comment nodes should be created.
01461     //
01462     //  fDocumentAdoptedByUser
01463     //      The DOMDocument ownership has been transferred to application
01464     //      If set to true, the parser does not own the document anymore
01465     //      and thus will not release its memory.
01466     //
01467     //  fInternalSubset
01468     //      Buffer for storing the internal subset information.
01469     //      Once complete (after DOCTYPE is finished scanning), send
01470     //      it to DocumentType Node
01471     // -----------------------------------------------------------------------
01472     bool                          fCreateEntityReferenceNodes;
01473     bool                          fIncludeIgnorableWhitespace;
01474     bool                          fWithinElement;
01475     bool                          fParseInProgress;
01476     bool                          fCreateCommentNodes;
01477     bool                          fDocumentAdoptedByUser;
01478     XMLScanner*                   fScanner;
01479     DOMNode*                      fCurrentParent;
01480     DOMNode*                      fCurrentNode;
01481     DOMEntity*                    fCurrentEntity;
01482     DOMDocumentImpl*              fDocument;
01483     ValueStackOf<DOMNode*>*       fNodeStack;
01484     DOMDocumentTypeImpl*          fDocumentType;
01485     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
01486     GrammarResolver*              fGrammarResolver;
01487     XMLStringPool*                fURIStringPool;
01488     XMLValidator*                 fValidator;
01489     MemoryManager*                fMemoryManager;
01490     XMLBufferMgr                  fBufMgr;
01491     XMLBuffer&                    fInternalSubset;
01492 };
01493 
01494 
01495 
01496 // ---------------------------------------------------------------------------
01497 //  AbstractDOMParser: Getter methods
01498 // ---------------------------------------------------------------------------
01499 inline bool AbstractDOMParser::getExpandEntityReferences() const
01500 {
01501     return !fCreateEntityReferenceNodes;
01502 }
01503 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01504 {
01505     return fCreateEntityReferenceNodes;
01506 }
01507 
01508 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01509 {
01510     return fIncludeIgnorableWhitespace;
01511 }
01512 
01513 inline bool AbstractDOMParser::getParseInProgress() const
01514 {
01515     return fParseInProgress;
01516 }
01517 
01518 inline XMLScanner* AbstractDOMParser::getScanner() const
01519 {
01520     return fScanner;
01521 }
01522 
01523 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
01524 {
01525     return fGrammarResolver;
01526 }
01527 
01528 inline bool AbstractDOMParser::getCreateCommentNodes() const
01529 {
01530     return fCreateCommentNodes;
01531 }
01532 
01533 // ---------------------------------------------------------------------------
01534 //  AbstractDOMParser: Setter methods
01535 // ---------------------------------------------------------------------------
01536 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
01537 {
01538     fCreateEntityReferenceNodes = !expand;
01539 }
01540 
01541 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01542 {
01543     fCreateEntityReferenceNodes = create;
01544 }
01545 
01546 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01547 {
01548     fIncludeIgnorableWhitespace = include;
01549 }
01550 
01551 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01552 {
01553     fCreateCommentNodes = create;
01554 }
01555 
01556 
01557 // ---------------------------------------------------------------------------
01558 //  AbstractDOMParser: Protected getter methods
01559 // ---------------------------------------------------------------------------
01560 inline DOMNode* AbstractDOMParser::getCurrentNode()
01561 {
01562     return fCurrentNode;
01563 }
01564 
01565 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
01566 {
01567     return fMemoryManager;
01568 }
01569 
01570 // ---------------------------------------------------------------------------
01571 //  AbstractDOMParser: Protected setter methods
01572 // ---------------------------------------------------------------------------
01573 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01574 {
01575     fCurrentNode = toSet;
01576 }
01577 
01578 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
01579 {
01580     fDocument = (DOMDocumentImpl *)toSet;
01581 }
01582 
01583 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01584 {
01585     fParseInProgress = toSet;
01586 }
01587 
01588 XERCES_CPP_NAMESPACE_END
01589 
01590 #endif
01591 
01592 
01593 


Copyright © 2000 The Apache Software Foundation. All Rights Reserved.