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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback
Bug-Todo

Download
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.8  2000/12/14 18:49:58  tng

00060   * Fix API document generation warning: "Warning: end of member group without matching begin"

00061   *
00062   * Revision 1.7  2000/08/09 22:09:09  jpolast

00063   * added const XMLCh* getURIText()

00064   * allows parsers to use const URIs instead of appending

00065   * to a XMLBuffer.

00066   *
00067   * Revision 1.6  2000/03/02 19:54:25  roddey

00068   * This checkin includes many changes done while waiting for the

00069   * 1.1.0 code to be finished. I can't list them all here, but a list is

00070   * available elsewhere.

00071   *
00072   * Revision 1.5  2000/02/24 20:00:24  abagchi

00073   * Swat for removing Log from API docs

00074   *
00075   * Revision 1.4  2000/02/15 23:59:07  roddey

00076   * More updated documentation of Framework classes.

00077   *
00078   * Revision 1.3  2000/02/15 01:21:31  roddey

00079   * Some initial documentation improvements. More to come...

00080   *
00081   * Revision 1.2  2000/02/06 07:47:49  rahulj

00082   * Year 2K copyright swat.

00083   *
00084   * Revision 1.1.1.1  1999/11/09 01:08:38  twl

00085   * Initial checkin

00086   *
00087   * Revision 1.4  1999/11/08 20:44:41  rahul

00088   * Swat for adding in Product name and CVS comment log variable.

00089   *
00090   */
00091 
00092 
00093 #if !defined(XMLVALIDATOR_HPP)
00094 #define XMLVALIDATOR_HPP
00095 
00096 #include <util/XercesDefs.hpp>
00097 #include <util/XMLEnumerator.hpp>
00098 #include <util/RefHashTableOf.hpp>
00099 #include <framework/XMLAttr.hpp>
00100 #include <framework/XMLValidityCodes.hpp>
00101 #include <framework/XMLRefInfo.hpp>
00102 
00103 class ReaderMgr;
00104 class XMLBuffer;
00105 class XMLBufferMgr;
00106 class XMLElementDecl;
00107 class XMLEntityDecl;
00108 class XMLEntityHandler;
00109 class XMLErrorReporter;
00110 class XMLNotationDecl;
00111 class XMLMsgLoader;
00112 class XMLScanner;
00113 
00114 
00130 class  XMLValidator
00131 {
00132 public:
00133     // -----------------------------------------------------------------------
00134     //  Class specific types
00135     // -----------------------------------------------------------------------
00136     enum Constants
00137     {
00138         Success     = -1
00139         , BadParent = -2
00140         , BadChild  = -3
00141     };
00142 
00143 
00144     enum LookupOpts
00145     {
00146         AddIfNotFound
00147         , FailIfNotFound
00148     };
00149 
00150 
00151     // -----------------------------------------------------------------------
00152     //  Constructors are hidden, just the virtual destructor is exposed
00153     // -----------------------------------------------------------------------
00154 
00157 
00162     virtual ~XMLValidator()

00163     {
00164     }
00166 
00167 
00168     // -----------------------------------------------------------------------
00169     //  Getter methods
00170     // -----------------------------------------------------------------------
00171 
00174 
00183     unsigned int getEmptyNamespaceId() const;
00184 
00193     unsigned int getGlobalNamespaceId() const;
00194 
00204     unsigned int getUnknownNamespaceId() const;
00205 
00213     unsigned int getXMLNamespaceId() const;
00214 
00222     unsigned int getXMLNSNamespaceId() const;
00223 
00225 
00226 
00227     // -----------------------------------------------------------------------
00228     //  Setter methods
00229     //
00230     //  setScannerInfo() is called by the scanner to tell the validator
00231     //  about the stuff it needs to have access to.
00232     // -----------------------------------------------------------------------
00233 
00236 
00250     void setScannerInfo
00251     (
00252         XMLScanner* const           owningScanner
00253         , ReaderMgr* const          readerMgr
00254         , XMLBufferMgr* const       bufMgr
00255     );
00256 
00266     void setErrorReporter
00267     (
00268         XMLErrorReporter* const errorReporter
00269     );
00270 
00272 
00273 
00274     // -----------------------------------------------------------------------
00275     //  The virtual validator interface
00276     // -----------------------------------------------------------------------
00277 
00280 
00286     virtual int addOrFindNSId
00287     (
00288         const   XMLCh* const    uriText
00289     ) = 0;
00290 
00311     virtual int checkContent
00312     (
00313         const   unsigned int    elemId
00314         , const unsigned int*   childIds
00315         , const unsigned int    childCount
00316     ) = 0;
00317 
00323     virtual bool checkRootElement
00324     (
00325         const   unsigned int    elemId
00326     ) = 0;
00327 
00336     virtual void faultInAttr
00337     (
00338                 XMLAttr&    toFill
00339         , const XMLAttDef&  attDef
00340     )   const = 0;
00341 
00355     virtual const XMLElementDecl* findElemDecl
00356     (
00357         const   unsigned int    uriId
00358         , const XMLCh* const    baseName
00359         , const XMLCh* const    qName
00360         , const LookupOpts      options
00361         ,       bool&           wasAdded
00362     )   const = 0;
00363 
00364     /*
00365      *  This method is identical to the previous one, except that it is a non-

00366      *  const version.

00367      */
00368     virtual XMLElementDecl* findElemDecl
00369     (
00370         const   unsigned int    uriId
00371         , const XMLCh* const    baseName
00372         , const XMLCh* const    qName
00373         , const LookupOpts      options
00374         ,       bool&           wasAdded
00375     ) = 0;
00376 
00390     virtual const XMLEntityDecl* findEntityDecl
00391     (
00392         const   XMLCh* const    entName
00393         , const bool            isPE
00394     )   const = 0;
00395 
00408     virtual XMLEntityDecl* findEntityDecl
00409     (
00410         const   XMLCh* const    entName
00411         , const bool            isPE
00412     ) = 0;
00413 
00421     virtual unsigned int findElemId
00422     (
00423         const   unsigned int    uriId
00424         , const XMLCh* const    baseName
00425         , const XMLCh* const    qName
00426     )   const = 0;
00427 
00434     virtual const XMLNotationDecl* findNotationDecl
00435     (
00436         const   XMLCh* const    notName
00437     )   const = 0;
00438 
00443     virtual XMLNotationDecl* findNotationDecl
00444     (
00445         const   XMLCh* const    notName
00446     ) = 0;
00447 
00453     virtual unsigned int findNSId
00454     (
00455         const   XMLCh* const    nsName
00456     )   const = 0;
00457 
00464     virtual const XMLElementDecl* getElemDecl
00465     (
00466         const   unsigned int    elemId
00467     )   const = 0;
00468 
00473     virtual XMLElementDecl* getElemDecl
00474     (
00475         const   unsigned int    elemId
00476     ) = 0;
00477 
00484     virtual bool getURIText
00485     (
00486         const   unsigned int    uriId
00487         ,       XMLBuffer&      uriBufToFill
00488     )   const = 0;
00489 
00490     virtual const XMLCh* getURIText
00491     (   
00492         const   unsigned int    uriId
00493     )   const = 0;
00494 
00502     virtual void postParseValidation() = 0;
00503 
00509     virtual void reset() = 0;
00510 
00517     virtual bool requiresNamespaces() const = 0;
00518 
00529     virtual void validateAttrValue
00530     (
00531         const   XMLAttDef&                  attDef
00532         , const XMLCh* const                attrValue
00533     ) = 0;
00534 
00536 
00537     // -----------------------------------------------------------------------
00538     //  Virtual DTD handler interface. If handlesDTD() returns true, then
00539     //  scanDTD() will be called when a DOCTYPE is seen.
00540     // -----------------------------------------------------------------------
00541 
00544 
00549     virtual bool handlesDTD() const = 0;
00550 
00564     virtual void scanDTD(const bool reuseValidator) = 0;
00565 
00567 
00568 
00569     // -----------------------------------------------------------------------
00570     //  Error emitter methods
00571     // -----------------------------------------------------------------------
00572 
00575 
00593     void emitError(const XMLValid::Codes toEmit);
00594     void emitError
00595     (
00596         const   XMLValid::Codes toEmit
00597         , const XMLCh* const    text1
00598         , const XMLCh* const    text2 = 0
00599         , const XMLCh* const    text3 = 0
00600         , const XMLCh* const    text4 = 0
00601     );
00602     void emitError
00603     (
00604         const   XMLValid::Codes toEmit
00605         , const char* const     text1
00606         , const char* const     text2 = 0
00607         , const char* const     text3 = 0
00608         , const char* const     text4 = 0
00609     );
00610 
00612 
00613 
00614 protected :
00615     // -----------------------------------------------------------------------
00616     //  Hidden constructors
00617     // -----------------------------------------------------------------------
00618     XMLValidator
00619     (
00620         XMLErrorReporter* const errReporter = 0
00621     );
00622 
00623 
00624     // -----------------------------------------------------------------------
00625     //  Protected getters
00626     // -----------------------------------------------------------------------
00627     const XMLBufferMgr* getBufMgr() const;
00628     XMLBufferMgr* getBufMgr();
00629     const ReaderMgr* getReaderMgr() const;
00630     ReaderMgr* getReaderMgr();
00631     const XMLScanner* getScanner() const;
00632     XMLScanner* getScanner();
00633 
00634 
00635     // -----------------------------------------------------------------------
00636     //  Protected methods
00637     // -----------------------------------------------------------------------
00638     void setBaseFields
00639     (
00640         const   unsigned int    emptyNamespaceId
00641         , const unsigned int    globalNamespaceId
00642         , const unsigned int    unknownNamespaceId
00643         , const unsigned int    xmlNamespaceId
00644         , const unsigned int    xmlNSNamespaceId
00645     );
00646 
00647 
00648 private :
00649     // -----------------------------------------------------------------------
00650     //  Unimplemented Constructors and Operators
00651     // -----------------------------------------------------------------------
00652     XMLValidator(const XMLValidator&);
00653     void operator=(const XMLValidator&);
00654 
00655 
00656     // -----------------------------------------------------------------------
00657     //  Private data members
00658     //
00659     //  fEmptyNamespaceId
00660     //      This is the id of the empty namespace URI. This is a special one
00661     //      because of the xmlns="" type of deal. We have to quickly sense
00662     //      that its the empty namespace.
00663     //
00664     //  fErrorReporter
00665     //      The error reporter we are to use, if any.
00666     //
00667     //  fGlobalNamespaceId
00668     //      This is the id of the namespace URI which is assigned to the
00669     //      global namespace. Its for debug purposes only, since there is no
00670     //      real global namespace URI. Its set by the derived class.
00671     //
00672     //  fUnknownNamespaceId
00673     //      This is the id of the namespace URI which is assigned to the
00674     //      global namespace. Its for debug purposes only, since there is no
00675     //      real global namespace URI. Its set by the derived class.
00676     //
00677     //  fXMLNamespaceId
00678     //  fXMLNSNamespaceId
00679     //      These are the ids of the namespace URIs which are assigned to the
00680     //      'xml' and 'xmlns' special prefixes. The former is officially
00681     //      defined but the latter is not, so we just provide one for debug
00682     //      purposes.
00683     // -----------------------------------------------------------------------
00684     XMLBufferMgr*       fBufMgr;
00685     unsigned int        fEmptyNamespaceId;
00686     XMLErrorReporter*   fErrorReporter;
00687     unsigned int        fGlobalNamespaceId;
00688     ReaderMgr*          fReaderMgr;
00689     XMLScanner*         fScanner;
00690     unsigned int        fUnknownNamespaceId;
00691     unsigned int        fXMLNamespaceId;
00692     unsigned int        fXMLNSNamespaceId;
00693 
00694 };
00695 
00696 
00697 // ---------------------------------------------------------------------------
00698 //  XMLValidator: Getter methods
00699 // ---------------------------------------------------------------------------
00700 inline unsigned int XMLValidator::getEmptyNamespaceId() const

00701 {
00702     return fEmptyNamespaceId;
00703 }
00704 
00705 inline unsigned int XMLValidator::getGlobalNamespaceId() const

00706 {
00707     return fGlobalNamespaceId;
00708 }
00709 
00710 inline unsigned int XMLValidator::getUnknownNamespaceId() const

00711 {
00712     return fUnknownNamespaceId;
00713 }
00714 
00715 inline unsigned int XMLValidator::getXMLNamespaceId() const

00716 {
00717     return fXMLNamespaceId;
00718 }
00719 
00720 inline unsigned int XMLValidator::getXMLNSNamespaceId() const

00721 {
00722     return fXMLNSNamespaceId;
00723 }
00724 
00725 
00726 // -----------------------------------------------------------------------
00727 //  Setter methods
00728 // -----------------------------------------------------------------------
00729 inline void
00730 XMLValidator::setScannerInfo(XMLScanner* const      owningScanner
00731                             , ReaderMgr* const      readerMgr
00732                             , XMLBufferMgr* const   bufMgr)

00733 {
00734     // We don't own any of these, we just reference them
00735     fScanner = owningScanner;
00736     fReaderMgr = readerMgr;
00737     fBufMgr = bufMgr;
00738 }
00739 
00740 inline void
00741 XMLValidator::setErrorReporter(XMLErrorReporter* const errorReporter)

00742 {
00743     fErrorReporter = errorReporter;
00744 }
00745 
00746 
00747 // ---------------------------------------------------------------------------
00748 //  XMLValidator: Protected getter
00749 // ---------------------------------------------------------------------------
00750 inline const XMLBufferMgr* XMLValidator::getBufMgr() const

00751 {
00752     return fBufMgr;
00753 }
00754 
00755 inline XMLBufferMgr* XMLValidator::getBufMgr()

00756 {
00757     return fBufMgr;
00758 }
00759 
00760 inline const ReaderMgr* XMLValidator::getReaderMgr() const

00761 {
00762     return fReaderMgr;
00763 }
00764 
00765 inline ReaderMgr* XMLValidator::getReaderMgr()

00766 {
00767     return fReaderMgr;
00768 }
00769 
00770 inline const XMLScanner* XMLValidator::getScanner() const

00771 {
00772     return fScanner;
00773 }
00774 
00775 inline XMLScanner* XMLValidator::getScanner()

00776 {
00777     return fScanner;
00778 }
00779 
00780 
00781 // ---------------------------------------------------------------------------
00782 //  XMLValidator: Protected methods
00783 // ---------------------------------------------------------------------------
00784 inline void
00785 XMLValidator::setBaseFields(const   unsigned int    emptyNamespaceId
00786                             , const unsigned int    globalNamespaceId
00787                             , const unsigned int    unknownNamespaceId
00788                             , const unsigned int    xmlNamespaceId
00789                             , const unsigned int    xmlNSNamespaceId)

00790 {
00791     fEmptyNamespaceId   = emptyNamespaceId;
00792     fGlobalNamespaceId  = globalNamespaceId;
00793     fUnknownNamespaceId = unknownNamespaceId;
00794     fXMLNamespaceId     = xmlNamespaceId;
00795     fXMLNSNamespaceId   = xmlNSNamespaceId;
00796 }
00797 
00798 #endif


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