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.10 2001/10/18 15:04:35 tng Exp $
00059  *
00060  */
00061 
00062 #if !defined(IDOMPARSER_HPP)
00063 #define IDOMPARSER_HPP
00064 
00065 
00066 #include <idom/IDOM_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 <idom/IDOM_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 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 
00363 
00364 
00365     // -----------------------------------------------------------------------
00366     //  Setter methods
00367     // -----------------------------------------------------------------------
00368 
00371 
00385     void setErrorHandler(ErrorHandler* const handler);
00386 
00402     void setEntityResolver(EntityResolver* const handler);
00403 
00422     void setDoNamespaces(const bool newState);
00423 
00440     void setExitOnFirstFatalError(const bool newState);
00441 
00457     void setValidationConstraintFatal(const bool newState);
00458 
00473     void setExpandEntityReferences(const bool expand);
00474 
00491     void setCreateEntityReferenceNodes(const bool create);
00492 
00514     void setIncludeIgnorableWhitespace(const bool include);
00515 
00532     void setValidationScheme(const ValSchemes newScheme);
00533 
00547     void setDoSchema(const bool newState);
00548 
00565     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00566 
00568 
00569 
00570     // -----------------------------------------------------------------------
00571     //  Parsing methods
00572     // -----------------------------------------------------------------------
00573 
00576 
00597     void parse(const InputSource& source, const bool reuseGrammar = false);
00598 
00618     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00619 
00638     void parse(const char* const systemId, const bool reuseGrammar = false);
00639 
00669     bool parseFirst
00670     (
00671         const   XMLCh* const    systemId
00672         ,       XMLPScanToken&  toFill
00673         , const bool            reuseGrammar = false
00674     );
00675 
00706     bool parseFirst
00707     (
00708         const   char* const     systemId
00709         ,       XMLPScanToken&  toFill
00710         , const bool            reuseGrammar = false
00711     );
00712 
00743     bool parseFirst
00744     (
00745         const   InputSource&    source
00746         ,       XMLPScanToken&  toFill
00747         , const bool            reuseGrammar = false
00748     );
00749 
00772     bool parseNext(XMLPScanToken& token);
00773 
00799     void parseReset(XMLPScanToken& token);
00800 
00802 
00803 
00804 
00805     // -----------------------------------------------------------------------
00806     //  Implementation of the XMLErrorReporter interface.
00807     // -----------------------------------------------------------------------
00808 
00811 
00836     virtual void error
00837     (
00838         const   unsigned int                errCode
00839         , const XMLCh* const                msgDomain
00840         , const XMLErrorReporter::ErrTypes  errType
00841         , const XMLCh* const                errorText
00842         , const XMLCh* const                systemId
00843         , const XMLCh* const                publicId
00844         , const unsigned int                lineNum
00845         , const unsigned int                colNum
00846     );
00847 
00856     virtual void resetErrors();
00858 
00859 
00860     // -----------------------------------------------------------------------
00861     //  Implementation of the XMLEntityHandler interface.
00862     // -----------------------------------------------------------------------
00863 
00866 
00879     virtual void endInputSource(const InputSource& inputSource);
00880 
00896     virtual bool expandSystemId
00897     (
00898         const   XMLCh* const    systemId
00899         ,       XMLBuffer&      toFill
00900     );
00901 
00910     virtual void resetEntities();
00911 
00927     virtual InputSource* resolveEntity
00928     (
00929         const   XMLCh* const    publicId
00930         , const XMLCh* const    systemId
00931     );
00932 
00945     virtual void startInputSource(const InputSource& inputSource);
00946 
00948 
00949 
00950 
00951     // -----------------------------------------------------------------------
00952     //  Implementation of the XMLDocumentHandler interface.
00953     // -----------------------------------------------------------------------
00954 
00957 
00970     virtual void docCharacters
00971     (
00972         const   XMLCh* const    chars
00973         , const unsigned int    length
00974         , const bool            cdataSection
00975     );
00976 
00985     virtual void docComment
00986     (
00987         const   XMLCh* const    comment
00988     );
00989 
01002     virtual void docPI
01003     (
01004         const   XMLCh* const    target
01005         , const XMLCh* const    data
01006     );
01007 
01012     virtual void endDocument();
01013 
01027     virtual void endElement
01028     (
01029         const   XMLElementDecl& elemDecl
01030         , const unsigned int    urlId
01031         , const bool            isRoot
01032     );
01033 
01042     virtual void endEntityReference
01043     (
01044         const   XMLEntityDecl&  entDecl
01045     );
01046 
01065     virtual void ignorableWhitespace
01066     (
01067         const   XMLCh* const    chars
01068         , const unsigned int    length
01069         , const bool            cdataSection
01070     );
01071 
01078     virtual void resetDocument();
01079 
01084     virtual void startDocument();
01085 
01113     virtual void startElement
01114     (
01115         const   XMLElementDecl&         elemDecl
01116         , const unsigned int            urlId
01117         , const XMLCh* const            elemPrefix
01118         , const RefVectorOf<XMLAttr>&   attrList
01119         , const unsigned int            attrCount
01120         , const bool                    isEmpty
01121         , const bool                    isRoot
01122     );
01123 
01133     virtual void startEntityReference
01134     (
01135         const   XMLEntityDecl&  entDecl
01136     );
01137 
01156     virtual void XMLDecl
01157     (
01158         const   XMLCh* const    versionStr
01159         , const XMLCh* const    encodingStr
01160         , const XMLCh* const    standaloneStr
01161         , const XMLCh* const    actualEncStr
01162     );
01164 
01165 
01168 
01178     bool getDoValidation() const;
01179 
01193     void setDoValidation(const bool newState);
01194 
01198     virtual void attDef
01199     (
01200         const   DTDElementDecl&     elemDecl
01201         , const DTDAttDef&          attDef
01202         , const bool                ignoring
01203     );
01204 
01205     virtual void doctypeComment
01206     (
01207         const   XMLCh* const    comment
01208     );
01209 
01210     virtual void doctypeDecl
01211     (
01212         const   DTDElementDecl& elemDecl
01213         , const XMLCh* const    publicId
01214         , const XMLCh* const    systemId
01215         , const bool            hasIntSubset
01216     );
01217 
01218     virtual void doctypePI
01219     (
01220         const   XMLCh* const    target
01221         , const XMLCh* const    data
01222     );
01223 
01224     virtual void doctypeWhitespace
01225     (
01226         const   XMLCh* const    chars
01227         , const unsigned int    length
01228     );
01229 
01230     virtual void elementDecl
01231     (
01232         const   DTDElementDecl& decl
01233         , const bool            isIgnored
01234     );
01235 
01236     virtual void endAttList
01237     (
01238         const   DTDElementDecl& elemDecl
01239     );
01240 
01241     virtual void endIntSubset();
01242 
01243     virtual void endExtSubset();
01244 
01245     virtual void entityDecl
01246     (
01247         const   DTDEntityDecl&  entityDecl
01248         , const bool            isPEDecl
01249         , const bool            isIgnored
01250     );
01251 
01252     virtual void resetDocType();
01253 
01254     virtual void notationDecl
01255     (
01256         const   XMLNotationDecl&    notDecl
01257         , const bool                isIgnored
01258     );
01259 
01260     virtual void startAttList
01261     (
01262         const   DTDElementDecl& elemDecl
01263     );
01264 
01265     virtual void startIntSubset();
01266 
01267     virtual void startExtSubset();
01268 
01269     virtual void TextDecl
01270     (
01271         const   XMLCh* const    versionStr
01272         , const XMLCh* const    encodingStr
01273     );
01274 
01275 
01277 
01278 
01279 protected :
01280     // -----------------------------------------------------------------------
01281     //  Protected getter methods
01282     // -----------------------------------------------------------------------
01283 
01286 
01291     IDOM_Node* getCurrentNode();
01292 
01294 
01295 
01296     // -----------------------------------------------------------------------
01297     //  Protected setter methods
01298     // -----------------------------------------------------------------------
01299 
01302 
01310     void setCurrentNode(IDOM_Node* toSet);
01311 
01318     void setDocument(IDOM_Document* toSet);
01320 
01321 
01322 private :
01323     // -----------------------------------------------------------------------
01324     //  Private data members
01325     //
01326     //  fCurrentNode
01327     //  fCurrentParent
01328     //      Used to track the current node during nested element events. Since
01329     //      the tree must be built from a set of disjoint callbacks, we need
01330     //      these to keep up with where we currently are.
01331     //
01332     //  fDocument
01333     //      The root document object, filled with the document contents.
01334     //
01335     //  fEntityResolver
01336     //      The installed SAX entity resolver, if any. Null if none.
01337     //
01338     //  fErrorHandler
01339     //      The installed SAX error handler, if any. Null if none.
01340     //
01341     //  fCreateEntityReferenceNode
01342     //      Indicates whether entity reference nodes should be created.
01343     //
01344     //  fIncludeIgnorableWhitespace
01345     //      Indicates whether ignorable whiltespace should be added to
01346     //      the IDOM tree for validating parsers.
01347     //
01348     //  fNodeStack
01349     //      Used to track previous parent nodes during nested element events.
01350     //
01351     //  fParseInProgress
01352     //      Used to prevent multiple entrance to the parser while its doing
01353     //      a parse.
01354     //
01355     //  fScanner
01356     //      The scanner used for this parser. This is created during the
01357     //      constructor.
01358     //
01359     //  fWithinElement
01360     //      A flag to indicate that the parser is within at least one level
01361     //      of element processing.
01362     //
01363     //  fDocumentType
01364     //      Used to store and update the documentType variable information
01365     //      in fDocument
01366     //
01367     //  fDocumentVector
01368     //      Store all the previous fDocument(s) (thus not the current fDocument)
01369     //      created in this parser.  It is destroyed when the parser is destructed.
01370     // -----------------------------------------------------------------------
01371     IDOM_Node*               fCurrentParent;
01372     IDOM_Node*               fCurrentNode;
01373     IDDocumentImpl*          fDocument;
01374     EntityResolver*          fEntityResolver;
01375     ErrorHandler*            fErrorHandler;
01376     bool                     fCreateEntityReferenceNodes;
01377     bool                     fIncludeIgnorableWhitespace;
01378     ValueStackOf<IDOM_Node*>* fNodeStack;
01379     bool                     fParseInProgress;
01380     XMLScanner*              fScanner;
01381     bool                     fWithinElement;
01382     IDDocumentTypeImpl*      fDocumentType;
01383     RefVectorOf<IDDocumentImpl>* fDocumentVector;
01384 };
01385 
01386 
01387 
01388 // ---------------------------------------------------------------------------
01389 //  IDOMParser: Handlers for the XMLEntityHandler interface
01390 // ---------------------------------------------------------------------------
01391 inline void IDOMParser::endInputSource(const InputSource&)
01392 {
01393     // The IDOM entity resolver doesn't handle this
01394 }
01395 
01396 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01397 {
01398     // The IDOM entity resolver doesn't handle this
01399     return false;
01400 }
01401 
01402 inline void IDOMParser::resetEntities()
01403 {
01404     // Nothing to do on this one
01405 }
01406 
01407 inline void IDOMParser::startInputSource(const InputSource&)
01408 {
01409     // The IDOM entity resolver doesn't handle this
01410 }
01411 
01412 
01413 // ---------------------------------------------------------------------------
01414 //  IDOMParser: Getter methods
01415 // ---------------------------------------------------------------------------
01416 inline ErrorHandler* IDOMParser::getErrorHandler()
01417 {
01418     return fErrorHandler;
01419 }
01420 
01421 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01422 {
01423     return fErrorHandler;
01424 }
01425 
01426 inline EntityResolver* IDOMParser::getEntityResolver()
01427 {
01428     return fEntityResolver;
01429 }
01430 
01431 inline const EntityResolver* IDOMParser::getEntityResolver() const
01432 {
01433     return fEntityResolver;
01434 }
01435 
01436 inline bool IDOMParser::getExpandEntityReferences() const
01437 {
01438     return fCreateEntityReferenceNodes;
01439 }
01440 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01441 {
01442     return fCreateEntityReferenceNodes;
01443 }
01444 
01445 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01446 {
01447     return fIncludeIgnorableWhitespace;
01448 }
01449 
01450 
01451 // ---------------------------------------------------------------------------
01452 //  IDOMParser: Setter methods
01453 // ---------------------------------------------------------------------------
01454 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01455 {
01456     fCreateEntityReferenceNodes = expand;
01457 }
01458 
01459 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01460 {
01461     fCreateEntityReferenceNodes = create;
01462 }
01463 
01464 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01465 {
01466     fIncludeIgnorableWhitespace = include;
01467 }
01468 
01469 
01470 // ---------------------------------------------------------------------------
01471 //  IDOMParser: Protected getter methods
01472 // ---------------------------------------------------------------------------
01473 inline IDOM_Node* IDOMParser::getCurrentNode()
01474 {
01475     return fCurrentNode;
01476 }
01477 
01478 
01479 // ---------------------------------------------------------------------------
01480 //  IDOMParser: Protected setter methods
01481 // ---------------------------------------------------------------------------
01482 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01483 {
01484     fCurrentNode = toSet;
01485 }
01486 
01487 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01488 {
01489     fDocument = (IDDocumentImpl *)toSet;
01490 }
01491 
01492 #endif


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