www.alphaworks.ibm.comwww.ibm.com/developerwww.ibm.com

Home

Readme
Download

Build







Migration

Releases

Feedback

Y2K Compliance


CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2001 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) 1999, 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: DOMParser.hpp,v 1.27 2001/07/27 20:24:21 tng Exp $
00059  *
00060  */
00061 
00062 #if !defined(DOMPARSER_HPP)
00063 #define DOMPARSER_HPP
00064 
00065 
00066 #include <dom/DOM_Document.hpp>
00067 #include <framework/XMLDocumentHandler.hpp>
00068 #include <framework/XMLErrorReporter.hpp>
00069 #include <framework/XMLEntityHandler.hpp>
00070 #include <util/ValueStackOf.hpp>
00071 
00072 #include <validators/DTD/DocTypeHandler.hpp>
00073 #include <dom/DOM_DocumentType.hpp>
00074 #include <validators/DTD/DTDElementDecl.hpp>
00075 
00076 class EntityResolver;
00077 class ErrorHandler;
00078 class XMLPScanToken;
00079 class XMLScanner;
00080 class XMLValidator;
00081 
00082 
00093 class  DOMParser :
00094 
00095     public XMLDocumentHandler
00096     , public XMLErrorReporter
00097     , public XMLEntityHandler
00098     , public DocTypeHandler
00099 {
00100 public :
00101     // -----------------------------------------------------------------------
00102     //  Class types
00103     // -----------------------------------------------------------------------
00104     enum ValSchemes
00105     {
00106         Val_Never
00107         , Val_Always
00108         , Val_Auto
00109     };
00110 
00111 
00112     // -----------------------------------------------------------------------
00113     //  Constructors and Detructor
00114     // -----------------------------------------------------------------------
00115 
00118 
00127     DOMParser(XMLValidator* const valToAdopt = 0);
00128 
00132     ~DOMParser();
00133 
00135 
00141     void reset();
00142 
00143 
00144     // -----------------------------------------------------------------------
00145     //  Getter methods
00146     // -----------------------------------------------------------------------
00147 
00150 
00160     DOM_Document getDocument();
00161 
00169     ErrorHandler* getErrorHandler();
00170 
00178     const ErrorHandler* getErrorHandler() const;
00179 
00187     EntityResolver* getEntityResolver();
00188 
00196     const EntityResolver* getEntityResolver() const;
00197 
00205     const XMLScanner& getScanner() const;
00206 
00214     const XMLValidator& getValidator() const;
00215 
00223     ValSchemes getValidationScheme() const;
00224 
00235     bool getDoSchema() const;
00236 
00248     int getErrorCount() const;
00249 
00260     bool getDoNamespaces() const;
00261 
00274     bool getExitOnFirstFatalError() const;
00275 
00286     bool getValidationConstraintFatal() const;
00287 
00299     bool getExpandEntityReferences() const;
00300 
00318     bool  getCreateEntityReferenceNodes()const;
00319 
00330     bool getIncludeIgnorableWhitespace() const;
00331 
00341     bool getToCreateXMLDeclTypeNode() const;
00342 
00344 
00345 
00346     // -----------------------------------------------------------------------
00347     //  Setter methods
00348     // -----------------------------------------------------------------------
00349 
00352 
00366     void setErrorHandler(ErrorHandler* const handler);
00367 
00383     void setEntityResolver(EntityResolver* const handler);
00384 
00403     void setDoNamespaces(const bool newState);
00404 
00421     void setExitOnFirstFatalError(const bool newState);
00422 
00438     void setValidationConstraintFatal(const bool newState);
00439 
00454     void setExpandEntityReferences(const bool expand);
00455 
00472     void setCreateEntityReferenceNodes(const bool create);
00473 
00495     void setIncludeIgnorableWhitespace(const bool include);
00496 
00513     void setValidationScheme(const ValSchemes newScheme);
00514 
00528     void setDoSchema(const bool newState);
00529 
00540     void setToCreateXMLDeclTypeNode(const bool create);
00541 
00543 
00544 
00545     // -----------------------------------------------------------------------
00546     //  Parsing methods
00547     // -----------------------------------------------------------------------
00548 
00551 
00572     void parse(const InputSource& source, const bool reuseGrammar = false);
00573 
00593     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00594 
00612     void parse(const char* const systemId, const bool reuseGrammar = false);
00613 
00643     bool parseFirst
00644     (
00645         const   XMLCh* const    systemId
00646         ,       XMLPScanToken&  toFill
00647         , const bool            reuseGrammar = false
00648     );
00649 
00680     bool parseFirst
00681     (
00682         const   char* const     systemId
00683         ,       XMLPScanToken&  toFill
00684         , const bool            reuseGrammar = false
00685     );
00686 
00717     bool parseFirst
00718     (
00719         const   InputSource&    source
00720         ,       XMLPScanToken&  toFill
00721         , const bool            reuseGrammar = false
00722     );
00723 
00746     bool parseNext(XMLPScanToken& token);
00747 
00773     void parseReset(XMLPScanToken& token);
00774 
00776 
00777 
00778 
00779     // -----------------------------------------------------------------------
00780     //  Implementation of the XMLErrorReporter interface.
00781     // -----------------------------------------------------------------------
00782 
00785 
00810     virtual void error
00811     (
00812         const   unsigned int                errCode
00813         , const XMLCh* const                msgDomain
00814         , const XMLErrorReporter::ErrTypes  errType
00815         , const XMLCh* const                errorText
00816         , const XMLCh* const                systemId
00817         , const XMLCh* const                publicId
00818         , const unsigned int                lineNum
00819         , const unsigned int                colNum
00820     );
00821 
00830     virtual void resetErrors();
00832 
00833 
00834     // -----------------------------------------------------------------------
00835     //  Implementation of the XMLEntityHandler interface.
00836     // -----------------------------------------------------------------------
00837 
00840 
00853     virtual void endInputSource(const InputSource& inputSource);
00854 
00870     virtual bool expandSystemId
00871     (
00872         const   XMLCh* const    systemId
00873         ,       XMLBuffer&      toFill
00874     );
00875 
00884     virtual void resetEntities();
00885 
00901     virtual InputSource* resolveEntity
00902     (
00903         const   XMLCh* const    publicId
00904         , const XMLCh* const    systemId
00905     );
00906 
00919     virtual void startInputSource(const InputSource& inputSource);
00920 
00922 
00923 
00924 
00925     // -----------------------------------------------------------------------
00926     //  Implementation of the XMLDocumentHandler interface.
00927     // -----------------------------------------------------------------------
00928 
00931 
00944     virtual void docCharacters
00945     (
00946         const   XMLCh* const    chars
00947         , const unsigned int    length
00948         , const bool            cdataSection
00949     );
00950 
00959     virtual void docComment
00960     (
00961         const   XMLCh* const    comment
00962     );
00963 
00976     virtual void docPI
00977     (
00978         const   XMLCh* const    target
00979         , const XMLCh* const    data
00980     );
00981 
00986     virtual void endDocument();
00987 
01001     virtual void endElement
01002     (
01003         const   XMLElementDecl& elemDecl
01004         , const unsigned int    urlId
01005         , const bool            isRoot
01006     );
01007 
01016     virtual void endEntityReference
01017     (
01018         const   XMLEntityDecl&  entDecl
01019     );
01020 
01039     virtual void ignorableWhitespace
01040     (
01041         const   XMLCh* const    chars
01042         , const unsigned int    length
01043         , const bool            cdataSection
01044     );
01045 
01052     virtual void resetDocument();
01053 
01058     virtual void startDocument();
01059 
01087     virtual void startElement
01088     (
01089         const   XMLElementDecl&         elemDecl
01090         , const unsigned int            urlId
01091         , const XMLCh* const            elemPrefix
01092         , const RefVectorOf<XMLAttr>&   attrList
01093         , const unsigned int            attrCount
01094         , const bool                    isEmpty
01095         , const bool                    isRoot
01096     );
01097 
01107     virtual void startEntityReference
01108     (
01109         const   XMLEntityDecl&  entDecl
01110     );
01111 
01130     virtual void XMLDecl
01131     (
01132         const   XMLCh* const    versionStr
01133         , const XMLCh* const    encodingStr
01134         , const XMLCh* const    standaloneStr
01135         , const XMLCh* const    actualEncStr
01136     );
01138 
01139 
01142 
01152     bool getDoValidation() const;
01153 
01167     void setDoValidation(const bool newState);
01168 
01172     virtual void attDef
01173     (
01174         const   DTDElementDecl&     elemDecl
01175         , const DTDAttDef&          attDef
01176         , const bool                ignoring
01177     );
01178 
01179     virtual void doctypeComment
01180     (
01181         const   XMLCh* const    comment
01182     );
01183 
01184     virtual void doctypeDecl
01185     (
01186         const   DTDElementDecl& elemDecl
01187         , const XMLCh* const    publicId
01188         , const XMLCh* const    systemId
01189         , const bool            hasIntSubset
01190     );
01191 
01192     virtual void doctypePI
01193     (
01194         const   XMLCh* const    target
01195         , const XMLCh* const    data
01196     );
01197 
01198     virtual void doctypeWhitespace
01199     (
01200         const   XMLCh* const    chars
01201         , const unsigned int    length
01202     );
01203 
01204     virtual void elementDecl
01205     (
01206         const   DTDElementDecl& decl
01207         , const bool            isIgnored
01208     );
01209 
01210     virtual void endAttList
01211     (
01212         const   DTDElementDecl& elemDecl
01213     );
01214 
01215     virtual void endIntSubset();
01216 
01217     virtual void endExtSubset();
01218 
01219     virtual void entityDecl
01220     (
01221         const   DTDEntityDecl&  entityDecl
01222         , const bool            isPEDecl
01223         , const bool            isIgnored
01224     );
01225 
01226     virtual void resetDocType();
01227 
01228     virtual void notationDecl
01229     (
01230         const   XMLNotationDecl&    notDecl
01231         , const bool                isIgnored
01232     );
01233 
01234     virtual void startAttList
01235     (
01236         const   DTDElementDecl& elemDecl
01237     );
01238 
01239     virtual void startIntSubset();
01240 
01241     virtual void startExtSubset();
01242 
01243     virtual void TextDecl
01244     (
01245         const   XMLCh* const    versionStr
01246         , const XMLCh* const    encodingStr
01247     );
01248 
01249 
01251 
01252 
01253 protected :
01254     // -----------------------------------------------------------------------
01255     //  Protected getter methods
01256     // -----------------------------------------------------------------------
01257 
01260 
01265     DOM_Node getCurrentNode();
01266 
01268 
01269 
01270     // -----------------------------------------------------------------------
01271     //  Protected setter methods
01272     // -----------------------------------------------------------------------
01273 
01276 
01284     void setCurrentNode(DOM_Node toSet);
01285 
01292     void setDocument(DOM_Document toSet);
01294 
01295 
01296 private :
01297     // -----------------------------------------------------------------------
01298     //  Private data members
01299     //
01300     //  fCurrentNode
01301     //  fCurrentParent
01302     //      Used to track the current node during nested element events. Since
01303     //      the tree must be built from a set of disjoint callbacks, we need
01304     //      these to keep up with where we currently are.
01305     //
01306     //  fDocument
01307     //      The root document object, filled with the document contents.
01308     //
01309     //  fEntityResolver
01310     //      The installed SAX entity resolver, if any. Null if none.
01311     //
01312     //  fErrorHandler
01313     //      The installed SAX error handler, if any. Null if none.
01314     //
01315     //  fCreateEntityReferenceNode
01316     //      Indicates whether entity reference nodes should be created.
01317     //
01318     //  fIncludeIgnorableWhitespace
01319     //      Indicates whether ignorable whiltespace should be added to
01320     //      the DOM tree for validating parsers.
01321     //
01322     //  fNodeStack
01323     //      Used to track previous parent nodes during nested element events.
01324     //
01325     //  fParseInProgress
01326     //      Used to prevent multiple entrance to the parser while its doing
01327     //      a parse.
01328     //
01329     //  fScanner
01330     //      The scanner used for this parser. This is created during the
01331     //      constructor.
01332     //
01333     //  fWithinElement
01334     //      A flag to indicate that the parser is within at least one level
01335     //      of element processing.
01336     //
01337     //  fDocumentType
01338     //      Used to store and update the documentType variable information
01339     //      in fDocument
01340     //
01341     //  fToCreateXMLDecTypeNode
01342     //      A flag to create a DOM_XMLDecl node in the ODM tree if it exists
01343     //      This is an extension to xerces implementation
01344     //
01345     // -----------------------------------------------------------------------
01346     DOM_Node                fCurrentParent;
01347     DOM_Node                fCurrentNode;
01348     DOM_Document            fDocument;
01349     EntityResolver*         fEntityResolver;
01350     ErrorHandler*           fErrorHandler;
01351     bool                    fCreateEntityReferenceNodes;
01352     bool                    fIncludeIgnorableWhitespace;
01353     ValueStackOf<DOM_Node>* fNodeStack;
01354     bool                    fParseInProgress;
01355     XMLScanner*             fScanner;
01356     bool                    fWithinElement;
01357     DocumentTypeImpl*       fDocumentType;
01358     bool                    fToCreateXMLDeclTypeNode;
01359 };
01360 
01361 
01362 
01363 // ---------------------------------------------------------------------------
01364 //  DOMParser: Handlers for the XMLEntityHandler interface
01365 // ---------------------------------------------------------------------------
01366 inline void DOMParser::endInputSource(const InputSource&)
01367 {
01368     // The DOM entity resolver doesn't handle this
01369 }
01370 
01371 inline bool DOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01372 {
01373     // The DOM entity resolver doesn't handle this
01374     return false;
01375 }
01376 
01377 inline void DOMParser::resetEntities()
01378 {
01379     // Nothing to do on this one
01380 }
01381 
01382 inline void DOMParser::startInputSource(const InputSource&)
01383 {
01384     // The DOM entity resolver doesn't handle this
01385 }
01386 
01387 
01388 // ---------------------------------------------------------------------------
01389 //  DOMParser: Getter methods
01390 // ---------------------------------------------------------------------------
01391 inline DOM_Document DOMParser::getDocument()
01392 {
01393     return fDocument;
01394 }
01395 
01396 inline ErrorHandler* DOMParser::getErrorHandler()
01397 {
01398     return fErrorHandler;
01399 }
01400 
01401 inline const ErrorHandler* DOMParser::getErrorHandler() const
01402 {
01403     return fErrorHandler;
01404 }
01405 
01406 inline EntityResolver* DOMParser::getEntityResolver()
01407 {
01408     return fEntityResolver;
01409 }
01410 
01411 inline const EntityResolver* DOMParser::getEntityResolver() const
01412 {
01413     return fEntityResolver;
01414 }
01415 
01416 inline bool DOMParser::getExpandEntityReferences() const
01417 {
01418     return fCreateEntityReferenceNodes;
01419 }
01420 inline bool DOMParser::getCreateEntityReferenceNodes() const
01421 {
01422     return fCreateEntityReferenceNodes;
01423 }
01424 
01425 inline bool DOMParser::getIncludeIgnorableWhitespace() const
01426 {
01427     return fIncludeIgnorableWhitespace;
01428 }
01429 
01430 inline const XMLScanner& DOMParser::getScanner() const
01431 {
01432     return *fScanner;
01433 }
01434 
01435 inline bool DOMParser::getToCreateXMLDeclTypeNode() const
01436 {
01437     return fToCreateXMLDeclTypeNode;
01438 }
01439 
01440 
01441 // ---------------------------------------------------------------------------
01442 //  DOMParser: Setter methods
01443 // ---------------------------------------------------------------------------
01444 inline void DOMParser::setExpandEntityReferences(const bool expand)
01445 {
01446     fCreateEntityReferenceNodes = expand;
01447 }
01448 
01449 inline void DOMParser::setCreateEntityReferenceNodes(const bool create)
01450 {
01451     fCreateEntityReferenceNodes = create;
01452 }
01453 
01454 inline void DOMParser::setIncludeIgnorableWhitespace(const bool include)
01455 {
01456     fIncludeIgnorableWhitespace = include;
01457 }
01458 
01459 inline void DOMParser::setToCreateXMLDeclTypeNode(const bool create)
01460 {
01461     fToCreateXMLDeclTypeNode = create;
01462 }
01463 
01464 
01465 // ---------------------------------------------------------------------------
01466 //  DOMParser: Protected getter methods
01467 // ---------------------------------------------------------------------------
01468 inline DOM_Node DOMParser::getCurrentNode()
01469 {
01470     return fCurrentNode;
01471 }
01472 
01473 
01474 // ---------------------------------------------------------------------------
01475 //  DOMParser: Protected setter methods
01476 // ---------------------------------------------------------------------------
01477 inline void DOMParser::setCurrentNode(DOM_Node toSet)
01478 {
01479     fCurrentNode = toSet;
01480 }
01481 
01482 inline void DOMParser::setDocument(DOM_Document toSet)
01483 {
01484     fDocument = toSet;
01485 }
01486 
01487 #endif


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