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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback

PDF Document

Download
Dev Snapshots
CVS Repository
Mail Archive

API Docs for SAX and DOM
 

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

XMLValidator.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  * 
00004  * Copyright (c) 1999-2000 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   * $Log: XMLValidator.hpp,v $
00059   * Revision 1.7  2000/08/09 22:09:09  jpolast
00060   * added const XMLCh* getURIText()
00061   * allows parsers to use const URIs instead of appending
00062   * to a XMLBuffer.
00063   *
00064   * Revision 1.6  2000/03/02 19:54:25  roddey
00065   * This checkin includes many changes done while waiting for the
00066   * 1.1.0 code to be finished. I can't list them all here, but a list is
00067   * available elsewhere.
00068   *
00069   * Revision 1.5  2000/02/24 20:00:24  abagchi
00070   * Swat for removing Log from API docs
00071   *
00072   * Revision 1.4  2000/02/15 23:59:07  roddey
00073   * More updated documentation of Framework classes.
00074   *
00075   * Revision 1.3  2000/02/15 01:21:31  roddey
00076   * Some initial documentation improvements. More to come...
00077   *
00078   * Revision 1.2  2000/02/06 07:47:49  rahulj
00079   * Year 2K copyright swat.
00080   *
00081   * Revision 1.1.1.1  1999/11/09 01:08:38  twl
00082   * Initial checkin
00083   *
00084   * Revision 1.4  1999/11/08 20:44:41  rahul
00085   * Swat for adding in Product name and CVS comment log variable.
00086   *
00087   */
00088 
00089 
00090 #if !defined(XMLVALIDATOR_HPP)
00091 #define XMLVALIDATOR_HPP
00092 
00093 #include <util/XercesDefs.hpp>
00094 #include <util/XMLEnumerator.hpp>
00095 #include <util/RefHashTableOf.hpp>
00096 #include <framework/XMLAttr.hpp>
00097 #include <framework/XMLValidityCodes.hpp>
00098 #include <framework/XMLRefInfo.hpp>
00099 
00100 class ReaderMgr;
00101 class XMLBuffer;
00102 class XMLBufferMgr;
00103 class XMLElementDecl;
00104 class XMLEntityDecl;
00105 class XMLEntityHandler;
00106 class XMLErrorReporter;
00107 class XMLNotationDecl;
00108 class XMLMsgLoader;
00109 class XMLScanner;
00110 
00111 
00127 class  XMLValidator
00128 {
00129 public:
00130     // -----------------------------------------------------------------------
00131     //  Class specific types
00132     // -----------------------------------------------------------------------
00133     enum Constants
00134     {
00135         Success     = -1
00136         , BadParent = -2
00137         , BadChild  = -3
00138     };
00139 
00140 
00141     enum LookupOpts
00142     {
00143         AddIfNotFound
00144         , FailIfNotFound
00145     };
00146 
00147 
00148     // -----------------------------------------------------------------------
00149     //  Constructors are hidden, just the virtual destructor is exposed
00150     // -----------------------------------------------------------------------
00151 
00153     //@{
00154 
00159     virtual ~XMLValidator()
00160     {
00161     }
00162     //@}
00163 
00164 
00165     // -----------------------------------------------------------------------
00166     //  Getter methods
00167     // -----------------------------------------------------------------------
00168 
00170     //{@
00171 
00180     unsigned int getEmptyNamespaceId() const;
00181 
00190     unsigned int getGlobalNamespaceId() const;
00191 
00201     unsigned int getUnknownNamespaceId() const;
00202 
00210     unsigned int getXMLNamespaceId() const;
00211 
00219     unsigned int getXMLNSNamespaceId() const;
00220 
00221     //@}
00222 
00223 
00224     // -----------------------------------------------------------------------
00225     //  Setter methods
00226     //
00227     //  setScannerInfo() is called by the scanner to tell the validator
00228     //  about the stuff it needs to have access to.
00229     // -----------------------------------------------------------------------
00230 
00232     //{@
00233 
00247     void setScannerInfo
00248     (
00249         XMLScanner* const           owningScanner
00250         , ReaderMgr* const          readerMgr
00251         , XMLBufferMgr* const       bufMgr
00252     );
00253 
00263     void setErrorReporter
00264     (
00265         XMLErrorReporter* const errorReporter
00266     );
00267 
00268     //@}
00269 
00270 
00271     // -----------------------------------------------------------------------
00272     //  The virtual validator interface
00273     // -----------------------------------------------------------------------
00274 
00276     //{@
00277 
00283     virtual int addOrFindNSId
00284     (
00285         const   XMLCh* const    uriText
00286     ) = 0;
00287 
00308     virtual int checkContent
00309     (
00310         const   unsigned int    elemId
00311         , const unsigned int*   childIds
00312         , const unsigned int    childCount
00313     ) = 0;
00314 
00320     virtual bool checkRootElement
00321     (
00322         const   unsigned int    elemId
00323     ) = 0;
00324 
00333     virtual void faultInAttr
00334     (
00335                 XMLAttr&    toFill
00336         , const XMLAttDef&  attDef
00337     )   const = 0;
00338 
00352     virtual const XMLElementDecl* findElemDecl
00353     (
00354         const   unsigned int    uriId
00355         , const XMLCh* const    baseName
00356         , const XMLCh* const    qName
00357         , const LookupOpts      options
00358         ,       bool&           wasAdded
00359     )   const = 0;
00360 
00361     /*
00362      *  This method is identical to the previous one, except that it is a non-
00363      *  const version.
00364      */
00365     virtual XMLElementDecl* findElemDecl
00366     (
00367         const   unsigned int    uriId
00368         , const XMLCh* const    baseName
00369         , const XMLCh* const    qName
00370         , const LookupOpts      options
00371         ,       bool&           wasAdded
00372     ) = 0;
00373 
00387     virtual const XMLEntityDecl* findEntityDecl
00388     (
00389         const   XMLCh* const    entName
00390         , const bool            isPE
00391     )   const = 0;
00392 
00405     virtual XMLEntityDecl* findEntityDecl
00406     (
00407         const   XMLCh* const    entName
00408         , const bool            isPE
00409     ) = 0;
00410 
00418     virtual unsigned int findElemId
00419     (
00420         const   unsigned int    uriId
00421         , const XMLCh* const    baseName
00422         , const XMLCh* const    qName
00423     )   const = 0;
00424 
00431     virtual const XMLNotationDecl* findNotationDecl
00432     (
00433         const   XMLCh* const    notName
00434     )   const = 0;
00435 
00440     virtual XMLNotationDecl* findNotationDecl
00441     (
00442         const   XMLCh* const    notName
00443     ) = 0;
00444 
00450     virtual unsigned int findNSId
00451     (
00452         const   XMLCh* const    nsName
00453     )   const = 0;
00454 
00461     virtual const XMLElementDecl* getElemDecl
00462     (
00463         const   unsigned int    elemId
00464     )   const = 0;
00465 
00470     virtual XMLElementDecl* getElemDecl
00471     (
00472         const   unsigned int    elemId
00473     ) = 0;
00474 
00481     virtual bool getURIText
00482     (
00483         const   unsigned int    uriId
00484         ,       XMLBuffer&      uriBufToFill
00485     )   const = 0;
00486 
00487     virtual const XMLCh* getURIText
00488     (   
00489         const   unsigned int    uriId
00490     )   const = 0;
00491 
00499     virtual void postParseValidation() = 0;
00500 
00506     virtual void reset() = 0;
00507 
00514     virtual bool requiresNamespaces() const = 0;
00515 
00526     virtual void validateAttrValue
00527     (
00528         const   XMLAttDef&                  attDef
00529         , const XMLCh* const                attrValue
00530     ) = 0;
00531 
00532     //@}
00533 
00534     // -----------------------------------------------------------------------
00535     //  Virtual DTD handler interface. If handlesDTD() returns true, then
00536     //  scanDTD() will be called when a DOCTYPE is seen.
00537     // -----------------------------------------------------------------------
00538 
00540     //{@
00541 
00546     virtual bool handlesDTD() const = 0;
00547 
00561     virtual void scanDTD(const bool reuseValidator) = 0;
00562 
00563     //@}
00564 
00565 
00566     // -----------------------------------------------------------------------
00567     //  Error emitter methods
00568     // -----------------------------------------------------------------------
00569 
00571     //{@
00572 
00590     void emitError(const XMLValid::Codes toEmit);
00591     void emitError
00592     (
00593         const   XMLValid::Codes toEmit
00594         , const XMLCh* const    text1
00595         , const XMLCh* const    text2 = 0
00596         , const XMLCh* const    text3 = 0
00597         , const XMLCh* const    text4 = 0
00598     );
00599     void emitError
00600     (
00601         const   XMLValid::Codes toEmit
00602         , const char* const     text1
00603         , const char* const     text2 = 0
00604         , const char* const     text3 = 0
00605         , const char* const     text4 = 0
00606     );
00607 
00608     //@}
00609 
00610 
00611 protected :
00612     // -----------------------------------------------------------------------
00613     //  Hidden constructors
00614     // -----------------------------------------------------------------------
00615     XMLValidator
00616     (
00617         XMLErrorReporter* const errReporter = 0
00618     );
00619 
00620 
00621     // -----------------------------------------------------------------------
00622     //  Protected getters
00623     // -----------------------------------------------------------------------
00624     const XMLBufferMgr* getBufMgr() const;
00625     XMLBufferMgr* getBufMgr();
00626     const ReaderMgr* getReaderMgr() const;
00627     ReaderMgr* getReaderMgr();
00628     const XMLScanner* getScanner() const;
00629     XMLScanner* getScanner();
00630 
00631 
00632     // -----------------------------------------------------------------------
00633     //  Protected methods
00634     // -----------------------------------------------------------------------
00635     void setBaseFields
00636     (
00637         const   unsigned int    emptyNamespaceId
00638         , const unsigned int    globalNamespaceId
00639         , const unsigned int    unknownNamespaceId
00640         , const unsigned int    xmlNamespaceId
00641         , const unsigned int    xmlNSNamespaceId
00642     );
00643 
00644 
00645 private :
00646     // -----------------------------------------------------------------------
00647     //  Unimplemented Constructors and Operators
00648     // -----------------------------------------------------------------------
00649     XMLValidator(const XMLValidator&);
00650     void operator=(const XMLValidator&);
00651 
00652 
00653     // -----------------------------------------------------------------------
00654     //  Private data members
00655     //
00656     //  fEmptyNamespaceId
00657     //      This is the id of the empty namespace URI. This is a special one
00658     //      because of the xmlns="" type of deal. We have to quickly sense
00659     //      that its the empty namespace.
00660     //
00661     //  fErrorReporter
00662     //      The error reporter we are to use, if any.
00663     //
00664     //  fGlobalNamespaceId
00665     //      This is the id of the namespace URI which is assigned to the
00666     //      global namespace. Its for debug purposes only, since there is no
00667     //      real global namespace URI. Its set by the derived class.
00668     //
00669     //  fUnknownNamespaceId
00670     //      This is the id of the namespace URI which is assigned to the
00671     //      global namespace. Its for debug purposes only, since there is no
00672     //      real global namespace URI. Its set by the derived class.
00673     //
00674     //  fXMLNamespaceId
00675     //  fXMLNSNamespaceId
00676     //      These are the ids of the namespace URIs which are assigned to the
00677     //      'xml' and 'xmlns' special prefixes. The former is officially
00678     //      defined but the latter is not, so we just provide one for debug
00679     //      purposes.
00680     // -----------------------------------------------------------------------
00681     XMLBufferMgr*       fBufMgr;
00682     unsigned int        fEmptyNamespaceId;
00683     XMLErrorReporter*   fErrorReporter;
00684     unsigned int        fGlobalNamespaceId;
00685     ReaderMgr*          fReaderMgr;
00686     XMLScanner*         fScanner;
00687     unsigned int        fUnknownNamespaceId;
00688     unsigned int        fXMLNamespaceId;
00689     unsigned int        fXMLNSNamespaceId;
00690 
00691 };
00692 
00693 
00694 // ---------------------------------------------------------------------------
00695 //  XMLValidator: Getter methods
00696 // ---------------------------------------------------------------------------
00697 inline unsigned int XMLValidator::getEmptyNamespaceId() const
00698 {
00699     return fEmptyNamespaceId;
00700 }
00701 
00702 inline unsigned int XMLValidator::getGlobalNamespaceId() const
00703 {
00704     return fGlobalNamespaceId;
00705 }
00706 
00707 inline unsigned int XMLValidator::getUnknownNamespaceId() const
00708 {
00709     return fUnknownNamespaceId;
00710 }
00711 
00712 inline unsigned int XMLValidator::getXMLNamespaceId() const
00713 {
00714     return fXMLNamespaceId;
00715 }
00716 
00717 inline unsigned int XMLValidator::getXMLNSNamespaceId() const
00718 {
00719     return fXMLNSNamespaceId;
00720 }
00721 
00722 
00723 // -----------------------------------------------------------------------
00724 //  Setter methods
00725 // -----------------------------------------------------------------------
00726 inline void
00727 XMLValidator::setScannerInfo(XMLScanner* const      owningScanner
00728                             , ReaderMgr* const      readerMgr
00729                             , XMLBufferMgr* const   bufMgr)
00730 {
00731     // We don't own any of these, we just reference them
00732     fScanner = owningScanner;
00733     fReaderMgr = readerMgr;
00734     fBufMgr = bufMgr;
00735 }
00736 
00737 inline void
00738 XMLValidator::setErrorReporter(XMLErrorReporter* const errorReporter)
00739 {
00740     fErrorReporter = errorReporter;
00741 }
00742 
00743 
00744 // ---------------------------------------------------------------------------
00745 //  XMLValidator: Protected getter
00746 // ---------------------------------------------------------------------------
00747 inline const XMLBufferMgr* XMLValidator::getBufMgr() const
00748 {
00749     return fBufMgr;
00750 }
00751 
00752 inline XMLBufferMgr* XMLValidator::getBufMgr()
00753 {
00754     return fBufMgr;
00755 }
00756 
00757 inline const ReaderMgr* XMLValidator::getReaderMgr() const
00758 {
00759     return fReaderMgr;
00760 }
00761 
00762 inline ReaderMgr* XMLValidator::getReaderMgr()
00763 {
00764     return fReaderMgr;
00765 }
00766 
00767 inline const XMLScanner* XMLValidator::getScanner() const
00768 {
00769     return fScanner;
00770 }
00771 
00772 inline XMLScanner* XMLValidator::getScanner()
00773 {
00774     return fScanner;
00775 }
00776 
00777 
00778 // ---------------------------------------------------------------------------
00779 //  XMLValidator: Protected methods
00780 // ---------------------------------------------------------------------------
00781 inline void
00782 XMLValidator::setBaseFields(const   unsigned int    emptyNamespaceId
00783                             , const unsigned int    globalNamespaceId
00784                             , const unsigned int    unknownNamespaceId
00785                             , const unsigned int    xmlNamespaceId
00786                             , const unsigned int    xmlNSNamespaceId)
00787 {
00788     fEmptyNamespaceId   = emptyNamespaceId;
00789     fGlobalNamespaceId  = globalNamespaceId;
00790     fUnknownNamespaceId = unknownNamespaceId;
00791     fXMLNamespaceId     = xmlNamespaceId;
00792     fXMLNSNamespaceId   = xmlNSNamespaceId;
00793 }
00794 
00795 #endif


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