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

Home

Readme
Download
Installation
Build

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
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  

IDOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 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) 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: IDOMParser.hpp,v 1.2 2002/02/20 18:17:01 tng Exp $
00059  *
00060  */
00061 
00062 #if !defined(IDOMPARSER_HPP)
00063 #define IDOMPARSER_HPP
00064 
00065 
00066 #include <xercesc/idom/IDOM_Document.hpp>
00067 #include <xercesc/framework/XMLDocumentHandler.hpp>
00068 #include <xercesc/framework/XMLErrorReporter.hpp>
00069 #include <xercesc/framework/XMLEntityHandler.hpp>
00070 #include <xercesc/util/ValueStackOf.hpp>
00071 
00072 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00073 #include <xercesc/idom/IDOM_DocumentType.hpp>
00074 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00075 
00076 class EntityResolver;
00077 class ErrorHandler;
00078 class XMLPScanToken;
00079 class XMLScanner;
00080 class XMLValidator;
00081 class IDDocumentImpl;
00082 class IDDocumentTypeImpl;
00083 
00084 
00095 class  IDOMParser :
00096 
00097     public XMLDocumentHandler
00098     , public XMLErrorReporter
00099     , public XMLEntityHandler
00100     , public DocTypeHandler
00101 {
00102 public :
00103     // -----------------------------------------------------------------------
00104     //  Class types
00105     // -----------------------------------------------------------------------
00106     enum ValSchemes
00107     {
00108         Val_Never
00109         , Val_Always
00110         , Val_Auto
00111     };
00112 
00113 
00114     // -----------------------------------------------------------------------
00115     //  Constructors and Detructor
00116     // -----------------------------------------------------------------------
00117 
00120 
00129     IDOMParser(XMLValidator* const valToAdopt = 0);
00130 
00134     ~IDOMParser();
00135 
00137 
00143     void reset();
00144 
00168     void resetDocumentPool();
00169 
00170 
00171     // -----------------------------------------------------------------------
00172     //  Getter methods
00173     // -----------------------------------------------------------------------
00174 
00177 
00187     IDOM_Document* getDocument();
00188 
00196     ErrorHandler* getErrorHandler();
00197 
00205     const ErrorHandler* getErrorHandler() const;
00206 
00214     EntityResolver* getEntityResolver();
00215 
00223     const EntityResolver* getEntityResolver() const;
00224 
00232     const XMLValidator& getValidator() const;
00233 
00241     ValSchemes getValidationScheme() const;
00242 
00253     bool getDoSchema() const;
00254 
00265     bool getValidationSchemaFullChecking() const;
00266 
00278     int getErrorCount() const;
00279 
00290     bool getDoNamespaces() const;
00291 
00304     bool getExitOnFirstFatalError() const;
00305 
00316     bool getValidationConstraintFatal() const;
00317 
00329     bool getExpandEntityReferences() const;
00330 
00348     bool  getCreateEntityReferenceNodes()const;
00349 
00360     bool getIncludeIgnorableWhitespace() const;
00361 
00381     XMLCh* getExternalSchemaLocation() const;
00382 
00402     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00403 
00405 
00406 
00407     // -----------------------------------------------------------------------
00408     //  Setter methods
00409     // -----------------------------------------------------------------------
00410 
00413 
00427     void setErrorHandler(ErrorHandler* const handler);
00428 
00444     void setEntityResolver(EntityResolver* const handler);
00445 
00464     void setDoNamespaces(const bool newState);
00465 
00482     void setExitOnFirstFatalError(const bool newState);
00483 
00499     void setValidationConstraintFatal(const bool newState);
00500 
00515     void setExpandEntityReferences(const bool expand);
00516 
00533     void setCreateEntityReferenceNodes(const bool create);
00534 
00556     void setIncludeIgnorableWhitespace(const bool include);
00557 
00574     void setValidationScheme(const ValSchemes newScheme);
00575 
00589     void setDoSchema(const bool newState);
00590 
00607     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00608 
00628 
00629     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00630 
00639     void setExternalSchemaLocation(const char* const schemaLocation);
00640 
00655     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00656 
00665     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00666 
00668 
00669 
00670     // -----------------------------------------------------------------------
00671     //  Parsing methods
00672     // -----------------------------------------------------------------------
00673 
00676 
00697     void parse(const InputSource& source, const bool reuseGrammar = false);
00698 
00718     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00719 
00738     void parse(const char* const systemId, const bool reuseGrammar = false);
00739 
00769     bool parseFirst
00770     (
00771         const   XMLCh* const    systemId
00772         ,       XMLPScanToken&  toFill
00773         , const bool            reuseGrammar = false
00774     );
00775 
00806     bool parseFirst
00807     (
00808         const   char* const     systemId
00809         ,       XMLPScanToken&  toFill
00810         , const bool            reuseGrammar = false
00811     );
00812 
00843     bool parseFirst
00844     (
00845         const   InputSource&    source
00846         ,       XMLPScanToken&  toFill
00847         , const bool            reuseGrammar = false
00848     );
00849 
00872     bool parseNext(XMLPScanToken& token);
00873 
00899     void parseReset(XMLPScanToken& token);
00900 
00902 
00903 
00904 
00905     // -----------------------------------------------------------------------
00906     //  Implementation of the XMLErrorReporter interface.
00907     // -----------------------------------------------------------------------
00908 
00911 
00936     virtual void error
00937     (
00938         const   unsigned int                errCode
00939         , const XMLCh* const                msgDomain
00940         , const XMLErrorReporter::ErrTypes  errType
00941         , const XMLCh* const                errorText
00942         , const XMLCh* const                systemId
00943         , const XMLCh* const                publicId
00944         , const unsigned int                lineNum
00945         , const unsigned int                colNum
00946     );
00947 
00956     virtual void resetErrors();
00958 
00959 
00960     // -----------------------------------------------------------------------
00961     //  Implementation of the XMLEntityHandler interface.
00962     // -----------------------------------------------------------------------
00963 
00966 
00979     virtual void endInputSource(const InputSource& inputSource);
00980 
00996     virtual bool expandSystemId
00997     (
00998         const   XMLCh* const    systemId
00999         ,       XMLBuffer&      toFill
01000     );
01001 
01010     virtual void resetEntities();
01011 
01027     virtual InputSource* resolveEntity
01028     (
01029         const   XMLCh* const    publicId
01030         , const XMLCh* const    systemId
01031     );
01032 
01045     virtual void startInputSource(const InputSource& inputSource);
01046 
01048 
01049 
01050 
01051     // -----------------------------------------------------------------------
01052     //  Implementation of the XMLDocumentHandler interface.
01053     // -----------------------------------------------------------------------
01054 
01057 
01070     virtual void docCharacters
01071     (
01072         const   XMLCh* const    chars
01073         , const unsigned int    length
01074         , const bool            cdataSection
01075     );
01076 
01085     virtual void docComment
01086     (
01087         const   XMLCh* const    comment
01088     );
01089 
01102     virtual void docPI
01103     (
01104         const   XMLCh* const    target
01105         , const XMLCh* const    data
01106     );
01107 
01112     virtual void endDocument();
01113 
01127     virtual void endElement
01128     (
01129         const   XMLElementDecl& elemDecl
01130         , const unsigned int    urlId
01131         , const bool            isRoot
01132     );
01133 
01142     virtual void endEntityReference
01143     (
01144         const   XMLEntityDecl&  entDecl
01145     );
01146 
01165     virtual void ignorableWhitespace
01166     (
01167         const   XMLCh* const    chars
01168         , const unsigned int    length
01169         , const bool            cdataSection
01170     );
01171 
01178     virtual void resetDocument();
01179 
01184     virtual void startDocument();
01185 
01213     virtual void startElement
01214     (
01215         const   XMLElementDecl&         elemDecl
01216         , const unsigned int            urlId
01217         , const XMLCh* const            elemPrefix
01218         , const RefVectorOf<XMLAttr>&   attrList
01219         , const unsigned int            attrCount
01220         , const bool                    isEmpty
01221         , const bool                    isRoot
01222     );
01223 
01233     virtual void startEntityReference
01234     (
01235         const   XMLEntityDecl&  entDecl
01236     );
01237 
01256     virtual void XMLDecl
01257     (
01258         const   XMLCh* const    versionStr
01259         , const XMLCh* const    encodingStr
01260         , const XMLCh* const    standaloneStr
01261         , const XMLCh* const    actualEncStr
01262     );
01264 
01265 
01268 
01278     bool getDoValidation() const;
01279 
01293     void setDoValidation(const bool newState);
01294 
01298     virtual void attDef
01299     (
01300         const   DTDElementDecl&     elemDecl
01301         , const DTDAttDef&          attDef
01302         , const bool                ignoring
01303     );
01304 
01305     virtual void doctypeComment
01306     (
01307         const   XMLCh* const    comment
01308     );
01309 
01310     virtual void doctypeDecl
01311     (
01312         const   DTDElementDecl& elemDecl
01313         , const XMLCh* const    publicId
01314         , const XMLCh* const    systemId
01315         , const bool            hasIntSubset
01316     );
01317 
01318     virtual void doctypePI
01319     (
01320         const   XMLCh* const    target
01321         , const XMLCh* const    data
01322     );
01323 
01324     virtual void doctypeWhitespace
01325     (
01326         const   XMLCh* const    chars
01327         , const unsigned int    length
01328     );
01329 
01330     virtual void elementDecl
01331     (
01332         const   DTDElementDecl& decl
01333         , const bool            isIgnored
01334     );
01335 
01336     virtual void endAttList
01337     (
01338         const   DTDElementDecl& elemDecl
01339     );
01340 
01341     virtual void endIntSubset();
01342 
01343     virtual void endExtSubset();
01344 
01345     virtual void entityDecl
01346     (
01347         const   DTDEntityDecl&  entityDecl
01348         , const bool            isPEDecl
01349         , const bool            isIgnored
01350     );
01351 
01352     virtual void resetDocType();
01353 
01354     virtual void notationDecl
01355     (
01356         const   XMLNotationDecl&    notDecl
01357         , const bool                isIgnored
01358     );
01359 
01360     virtual void startAttList
01361     (
01362         const   DTDElementDecl& elemDecl
01363     );
01364 
01365     virtual void startIntSubset();
01366 
01367     virtual void startExtSubset();
01368 
01369     virtual void TextDecl
01370     (
01371         const   XMLCh* const    versionStr
01372         , const XMLCh* const    encodingStr
01373     );
01374 
01375 
01377 
01378 
01379 protected :
01380     // -----------------------------------------------------------------------
01381     //  Protected getter methods
01382     // -----------------------------------------------------------------------
01383 
01386 
01391     IDOM_Node* getCurrentNode();
01392 
01394 
01395 
01396     // -----------------------------------------------------------------------
01397     //  Protected setter methods
01398     // -----------------------------------------------------------------------
01399 
01402 
01410     void setCurrentNode(IDOM_Node* toSet);
01411 
01418     void setDocument(IDOM_Document* toSet);
01420 
01421 
01422 private :
01423     // -----------------------------------------------------------------------
01424     //  Private data members
01425     //
01426     //  fCurrentNode
01427     //  fCurrentParent
01428     //      Used to track the current node during nested element events. Since
01429     //      the tree must be built from a set of disjoint callbacks, we need
01430     //      these to keep up with where we currently are.
01431     //
01432     //  fDocument
01433     //      The root document object, filled with the document contents.
01434     //
01435     //  fEntityResolver
01436     //      The installed SAX entity resolver, if any. Null if none.
01437     //
01438     //  fErrorHandler
01439     //      The installed SAX error handler, if any. Null if none.
01440     //
01441     //  fCreateEntityReferenceNode
01442     //      Indicates whether entity reference nodes should be created.
01443     //
01444     //  fIncludeIgnorableWhitespace
01445     //      Indicates whether ignorable whiltespace should be added to
01446     //      the IDOM tree for validating parsers.
01447     //
01448     //  fNodeStack
01449     //      Used to track previous parent nodes during nested element events.
01450     //
01451     //  fParseInProgress
01452     //      Used to prevent multiple entrance to the parser while its doing
01453     //      a parse.
01454     //
01455     //  fScanner
01456     //      The scanner used for this parser. This is created during the
01457     //      constructor.
01458     //
01459     //  fWithinElement
01460     //      A flag to indicate that the parser is within at least one level
01461     //      of element processing.
01462     //
01463     //  fDocumentType
01464     //      Used to store and update the documentType variable information
01465     //      in fDocument
01466     //
01467     //  fDocumentVector
01468     //      Store all the previous fDocument(s) (thus not the current fDocument)
01469     //      created in this parser.  It is destroyed when the parser is destructed.
01470     // -----------------------------------------------------------------------
01471     IDOM_Node*               fCurrentParent;
01472     IDOM_Node*               fCurrentNode;
01473     IDDocumentImpl*          fDocument;
01474     EntityResolver*          fEntityResolver;
01475     ErrorHandler*            fErrorHandler;
01476     bool                     fCreateEntityReferenceNodes;
01477     bool                     fIncludeIgnorableWhitespace;
01478     ValueStackOf<IDOM_Node*>* fNodeStack;
01479     bool                     fParseInProgress;
01480     XMLScanner*              fScanner;
01481     bool                     fWithinElement;
01482     IDDocumentTypeImpl*      fDocumentType;
01483     RefVectorOf<IDDocumentImpl>* fDocumentVector;
01484 };
01485 
01486 
01487 
01488 // ---------------------------------------------------------------------------
01489 //  IDOMParser: Handlers for the XMLEntityHandler interface
01490 // ---------------------------------------------------------------------------
01491 inline void IDOMParser::endInputSource(const InputSource&)
01492 {
01493     // The IDOM entity resolver doesn't handle this
01494 }
01495 
01496 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01497 {
01498     // The IDOM entity resolver doesn't handle this
01499     return false;
01500 }
01501 
01502 inline void IDOMParser::resetEntities()
01503 {
01504     // Nothing to do on this one
01505 }
01506 
01507 inline void IDOMParser::startInputSource(const InputSource&)
01508 {
01509     // The IDOM entity resolver doesn't handle this
01510 }
01511 
01512 
01513 // ---------------------------------------------------------------------------
01514 //  IDOMParser: Getter methods
01515 // ---------------------------------------------------------------------------
01516 inline ErrorHandler* IDOMParser::getErrorHandler()
01517 {
01518     return fErrorHandler;
01519 }
01520 
01521 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01522 {
01523     return fErrorHandler;
01524 }
01525 
01526 inline EntityResolver* IDOMParser::getEntityResolver()
01527 {
01528     return fEntityResolver;
01529 }
01530 
01531 inline const EntityResolver* IDOMParser::getEntityResolver() const
01532 {
01533     return fEntityResolver;
01534 }
01535 
01536 inline bool IDOMParser::getExpandEntityReferences() const
01537 {
01538     return fCreateEntityReferenceNodes;
01539 }
01540 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01541 {
01542     return fCreateEntityReferenceNodes;
01543 }
01544 
01545 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01546 {
01547     return fIncludeIgnorableWhitespace;
01548 }
01549 
01550 
01551 // ---------------------------------------------------------------------------
01552 //  IDOMParser: Setter methods
01553 // ---------------------------------------------------------------------------
01554 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01555 {
01556     fCreateEntityReferenceNodes = expand;
01557 }
01558 
01559 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01560 {
01561     fCreateEntityReferenceNodes = create;
01562 }
01563 
01564 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01565 {
01566     fIncludeIgnorableWhitespace = include;
01567 }
01568 
01569 
01570 // ---------------------------------------------------------------------------
01571 //  IDOMParser: Protected getter methods
01572 // ---------------------------------------------------------------------------
01573 inline IDOM_Node* IDOMParser::getCurrentNode()
01574 {
01575     return fCurrentNode;
01576 }
01577 
01578 
01579 // ---------------------------------------------------------------------------
01580 //  IDOMParser: Protected setter methods
01581 // ---------------------------------------------------------------------------
01582 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01583 {
01584     fCurrentNode = toSet;
01585 }
01586 
01587 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01588 {
01589     fDocument = (IDDocumentImpl *)toSet;
01590 }
01591 
01592 #endif


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