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.6 2001/07/16 13:15:07 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 
00145 
00146     // -----------------------------------------------------------------------
00147     //  Getter methods
00148     // -----------------------------------------------------------------------
00149 
00152 
00162     IDOM_Document* getDocument();
00163 
00171     ErrorHandler* getErrorHandler();
00172 
00180     const ErrorHandler* getErrorHandler() const;
00181 
00189     EntityResolver* getEntityResolver();
00190 
00198     const EntityResolver* getEntityResolver() const;
00199 
00207     const XMLValidator& getValidator() const;
00208 
00216     ValSchemes getValidationScheme() const;
00217 
00228     bool getDoSchema() const;
00229 
00241     int getErrorCount() const;
00242 
00253     bool getDoNamespaces() const;
00254 
00267     bool getExitOnFirstFatalError() const;
00268 
00279     bool getValidationConstraintFatal() const;
00280 
00292     bool getExpandEntityReferences() const;
00293 
00311     bool  getCreateEntityReferenceNodes()const;
00312 
00323     bool getIncludeIgnorableWhitespace() const;
00324 
00326 
00327 
00328     // -----------------------------------------------------------------------
00329     //  Setter methods
00330     // -----------------------------------------------------------------------
00331 
00334 
00348     void setErrorHandler(ErrorHandler* const handler);
00349 
00365     void setEntityResolver(EntityResolver* const handler);
00366 
00385     void setDoNamespaces(const bool newState);
00386 
00403     void setExitOnFirstFatalError(const bool newState);
00404 
00420     void setValidationConstraintFatal(const bool newState);
00421 
00436     void setExpandEntityReferences(const bool expand);
00437 
00454     void setCreateEntityReferenceNodes(const bool create);
00455 
00477     void setIncludeIgnorableWhitespace(const bool include);
00478 
00495     void setValidationScheme(const ValSchemes newScheme);
00496 
00510     void setDoSchema(const bool newState);
00511 
00513 
00514 
00515     // -----------------------------------------------------------------------
00516     //  Parsing methods
00517     // -----------------------------------------------------------------------
00518 
00521 
00542     void parse(const InputSource& source, const bool reuseGrammar = false);
00543 
00563     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00564 
00583     void parse(const char* const systemId, const bool reuseGrammar = false);
00584 
00614     bool parseFirst
00615     (
00616         const   XMLCh* const    systemId
00617         ,       XMLPScanToken&  toFill
00618         , const bool            reuseGrammar = false
00619     );
00620 
00651     bool parseFirst
00652     (
00653         const   char* const     systemId
00654         ,       XMLPScanToken&  toFill
00655         , const bool            reuseGrammar = false
00656     );
00657 
00688     bool parseFirst
00689     (
00690         const   InputSource&    source
00691         ,       XMLPScanToken&  toFill
00692         , const bool            reuseGrammar = false
00693     );
00694 
00717     bool parseNext(XMLPScanToken& token);
00718 
00744     void parseReset(XMLPScanToken& token);
00745 
00747 
00748 
00749 
00750     // -----------------------------------------------------------------------
00751     //  Implementation of the XMLErrorReporter interface.
00752     // -----------------------------------------------------------------------
00753 
00756 
00781     virtual void error
00782     (
00783         const   unsigned int                errCode
00784         , const XMLCh* const                msgDomain
00785         , const XMLErrorReporter::ErrTypes  errType
00786         , const XMLCh* const                errorText
00787         , const XMLCh* const                systemId
00788         , const XMLCh* const                publicId
00789         , const unsigned int                lineNum
00790         , const unsigned int                colNum
00791     );
00792 
00801     virtual void resetErrors();
00803 
00804 
00805     // -----------------------------------------------------------------------
00806     //  Implementation of the XMLEntityHandler interface.
00807     // -----------------------------------------------------------------------
00808 
00811 
00824     virtual void endInputSource(const InputSource& inputSource);
00825 
00841     virtual bool expandSystemId
00842     (
00843         const   XMLCh* const    systemId
00844         ,       XMLBuffer&      toFill
00845     );
00846 
00855     virtual void resetEntities();
00856 
00872     virtual InputSource* resolveEntity
00873     (
00874         const   XMLCh* const    publicId
00875         , const XMLCh* const    systemId
00876     );
00877 
00890     virtual void startInputSource(const InputSource& inputSource);
00891 
00893 
00894 
00895 
00896     // -----------------------------------------------------------------------
00897     //  Implementation of the XMLDocumentHandler interface.
00898     // -----------------------------------------------------------------------
00899 
00902 
00915     virtual void docCharacters
00916     (
00917         const   XMLCh* const    chars
00918         , const unsigned int    length
00919         , const bool            cdataSection
00920     );
00921 
00930     virtual void docComment
00931     (
00932         const   XMLCh* const    comment
00933     );
00934 
00947     virtual void docPI
00948     (
00949         const   XMLCh* const    target
00950         , const XMLCh* const    data
00951     );
00952 
00957     virtual void endDocument();
00958 
00972     virtual void endElement
00973     (
00974         const   XMLElementDecl& elemDecl
00975         , const unsigned int    urlId
00976         , const bool            isRoot
00977     );
00978 
00987     virtual void endEntityReference
00988     (
00989         const   XMLEntityDecl&  entDecl
00990     );
00991 
01010     virtual void ignorableWhitespace
01011     (
01012         const   XMLCh* const    chars
01013         , const unsigned int    length
01014         , const bool            cdataSection
01015     );
01016 
01023     virtual void resetDocument();
01024 
01029     virtual void startDocument();
01030 
01058     virtual void startElement
01059     (
01060         const   XMLElementDecl&         elemDecl
01061         , const unsigned int            urlId
01062         , const XMLCh* const            elemPrefix
01063         , const RefVectorOf<XMLAttr>&   attrList
01064         , const unsigned int            attrCount
01065         , const bool                    isEmpty
01066         , const bool                    isRoot
01067     );
01068 
01078     virtual void startEntityReference
01079     (
01080         const   XMLEntityDecl&  entDecl
01081     );
01082 
01101     virtual void XMLDecl
01102     (
01103         const   XMLCh* const    versionStr
01104         , const XMLCh* const    encodingStr
01105         , const XMLCh* const    standaloneStr
01106         , const XMLCh* const    actualEncStr
01107     );
01109 
01110 
01113 
01123     bool getDoValidation() const;
01124 
01138     void setDoValidation(const bool newState);
01139 
01143     virtual void attDef
01144     (
01145         const   DTDElementDecl&     elemDecl
01146         , const DTDAttDef&          attDef
01147         , const bool                ignoring
01148     );
01149 
01150     virtual void doctypeComment
01151     (
01152         const   XMLCh* const    comment
01153     );
01154 
01155     virtual void doctypeDecl
01156     (
01157         const   DTDElementDecl& elemDecl
01158         , const XMLCh* const    publicId
01159         , const XMLCh* const    systemId
01160         , const bool            hasIntSubset
01161     );
01162 
01163     virtual void doctypePI
01164     (
01165         const   XMLCh* const    target
01166         , const XMLCh* const    data
01167     );
01168 
01169     virtual void doctypeWhitespace
01170     (
01171         const   XMLCh* const    chars
01172         , const unsigned int    length
01173     );
01174 
01175     virtual void elementDecl
01176     (
01177         const   DTDElementDecl& decl
01178         , const bool            isIgnored
01179     );
01180 
01181     virtual void endAttList
01182     (
01183         const   DTDElementDecl& elemDecl
01184     );
01185 
01186     virtual void endIntSubset();
01187 
01188     virtual void endExtSubset();
01189 
01190     virtual void entityDecl
01191     (
01192         const   DTDEntityDecl&  entityDecl
01193         , const bool            isPEDecl
01194         , const bool            isIgnored
01195     );
01196 
01197     virtual void resetDocType();
01198 
01199     virtual void notationDecl
01200     (
01201         const   XMLNotationDecl&    notDecl
01202         , const bool                isIgnored
01203     );
01204 
01205     virtual void startAttList
01206     (
01207         const   DTDElementDecl& elemDecl
01208     );
01209 
01210     virtual void startIntSubset();
01211 
01212     virtual void startExtSubset();
01213 
01214     virtual void TextDecl
01215     (
01216         const   XMLCh* const    versionStr
01217         , const XMLCh* const    encodingStr
01218     );
01219 
01220 
01222 
01223 
01224 protected :
01225     // -----------------------------------------------------------------------
01226     //  Protected getter methods
01227     // -----------------------------------------------------------------------
01228 
01231 
01236     IDOM_Node* getCurrentNode();
01237 
01239 
01240 
01241     // -----------------------------------------------------------------------
01242     //  Protected setter methods
01243     // -----------------------------------------------------------------------
01244 
01247 
01255     void setCurrentNode(IDOM_Node* toSet);
01256 
01263     void setDocument(IDOM_Document* toSet);
01265 
01266 
01267 private :
01268     // -----------------------------------------------------------------------
01269     //  Private data members
01270     //
01271     //  fCurrentNode
01272     //  fCurrentParent
01273     //      Used to track the current node during nested element events. Since
01274     //      the tree must be built from a set of disjoint callbacks, we need
01275     //      these to keep up with where we currently are.
01276     //
01277     //  fDocument
01278     //      The root document object, filled with the document contents.
01279     //
01280     //  fEntityResolver
01281     //      The installed SAX entity resolver, if any. Null if none.
01282     //
01283     //  fErrorHandler
01284     //      The installed SAX error handler, if any. Null if none.
01285     //
01286     //  fCreateEntityReferenceNode
01287     //      Indicates whether entity reference nodes should be created.
01288     //
01289     //  fIncludeIgnorableWhitespace
01290     //      Indicates whether ignorable whiltespace should be added to
01291     //      the IDOM tree for validating parsers.
01292     //
01293     //  fNodeStack
01294     //      Used to track previous parent nodes during nested element events.
01295     //
01296     //  fParseInProgress
01297     //      Used to prevent multiple entrance to the parser while its doing
01298     //      a parse.
01299     //
01300     //  fScanner
01301     //      The scanner used for this parser. This is created during the
01302     //      constructor.
01303     //
01304     //  fWithinElement
01305     //      A flag to indicate that the parser is within at least one level
01306     //      of element processing.
01307     //
01308     //  fDocumentType
01309     //      Used to store and update the documentType variable information
01310     //      in fDocument
01311     //
01312     // -----------------------------------------------------------------------
01313     IDOM_Node*               fCurrentParent;
01314     IDOM_Node*               fCurrentNode;
01315     IDDocumentImpl*          fDocument;
01316     EntityResolver*          fEntityResolver;
01317     ErrorHandler*            fErrorHandler;
01318     bool                     fCreateEntityReferenceNodes;
01319     bool                     fIncludeIgnorableWhitespace;
01320     ValueStackOf<IDOM_Node*>* fNodeStack;
01321     bool                     fParseInProgress;
01322     XMLScanner*              fScanner;
01323     bool                     fWithinElement;
01324     IDDocumentTypeImpl*      fDocumentType;
01325 };
01326 
01327 
01328 
01329 // ---------------------------------------------------------------------------
01330 //  IDOMParser: Handlers for the XMLEntityHandler interface
01331 // ---------------------------------------------------------------------------
01332 inline void IDOMParser::endInputSource(const InputSource&)
01333 {
01334     // The IDOM entity resolver doesn't handle this
01335 }
01336 
01337 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01338 {
01339     // The IDOM entity resolver doesn't handle this
01340     return false;
01341 }
01342 
01343 inline void IDOMParser::resetEntities()
01344 {
01345     // Nothing to do on this one
01346 }
01347 
01348 inline void IDOMParser::startInputSource(const InputSource&)
01349 {
01350     // The IDOM entity resolver doesn't handle this
01351 }
01352 
01353 
01354 // ---------------------------------------------------------------------------
01355 //  IDOMParser: Getter methods
01356 // ---------------------------------------------------------------------------
01357 inline ErrorHandler* IDOMParser::getErrorHandler()
01358 {
01359     return fErrorHandler;
01360 }
01361 
01362 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01363 {
01364     return fErrorHandler;
01365 }
01366 
01367 inline EntityResolver* IDOMParser::getEntityResolver()
01368 {
01369     return fEntityResolver;
01370 }
01371 
01372 inline const EntityResolver* IDOMParser::getEntityResolver() const
01373 {
01374     return fEntityResolver;
01375 }
01376 
01377 inline bool IDOMParser::getExpandEntityReferences() const
01378 {
01379     return fCreateEntityReferenceNodes;
01380 }
01381 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01382 {
01383     return fCreateEntityReferenceNodes;
01384 }
01385 
01386 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01387 {
01388     return fIncludeIgnorableWhitespace;
01389 }
01390 
01391 
01392 // ---------------------------------------------------------------------------
01393 //  IDOMParser: Setter methods
01394 // ---------------------------------------------------------------------------
01395 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01396 {
01397     fCreateEntityReferenceNodes = expand;
01398 }
01399 
01400 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01401 {
01402     fCreateEntityReferenceNodes = create;
01403 }
01404 
01405 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01406 {
01407     fIncludeIgnorableWhitespace = include;
01408 }
01409 
01410 
01411 // ---------------------------------------------------------------------------
01412 //  IDOMParser: Protected getter methods
01413 // ---------------------------------------------------------------------------
01414 inline IDOM_Node* IDOMParser::getCurrentNode()
01415 {
01416     return fCurrentNode;
01417 }
01418 
01419 
01420 // ---------------------------------------------------------------------------
01421 //  IDOMParser: Protected setter methods
01422 // ---------------------------------------------------------------------------
01423 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01424 {
01425     fCurrentNode = toSet;
01426 }
01427 
01428 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01429 {
01430     fDocument = (IDDocumentImpl *)toSet;
01431 }
01432 
01433 #endif


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