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.6 2000/03/02 19:54:25 roddey
00060 * This checkin includes many changes done while waiting for the
00061 * 1.1.0 code to be finished. I can't list them all here, but a list is
00062 * available elsewhere.
00063 *
00064 * Revision 1.5 2000/02/24 20:00:24 abagchi
00065 * Swat for removing Log from API docs
00066 *
00067 * Revision 1.4 2000/02/15 23:59:07 roddey
00068 * More updated documentation of Framework classes.
00069 *
00070 * Revision 1.3 2000/02/15 01:21:31 roddey
00071 * Some initial documentation improvements. More to come...
00072 *
00073 * Revision 1.2 2000/02/06 07:47:49 rahulj
00074 * Year 2K copyright swat.
00075 *
00076 * Revision 1.1.1.1 1999/11/09 01:08:38 twl
00077 * Initial checkin
00078 *
00079 * Revision 1.4 1999/11/08 20:44:41 rahul
00080 * Swat for adding in Product name and CVS comment log variable.
00081 *
00082 */
00083
00084
00085 #if !defined(XMLVALIDATOR_HPP)
00086 #define XMLVALIDATOR_HPP
00087
00088 #include <util/XercesDefs.hpp>
00089 #include <util/XMLEnumerator.hpp>
00090 #include <util/RefHashTableOf.hpp>
00091 #include <framework/XMLAttr.hpp>
00092 #include <framework/XMLValidityCodes.hpp>
00093 #include <framework/XMLRefInfo.hpp>
00094
00095 class ReaderMgr;
00096 class XMLBuffer;
00097 class XMLBufferMgr;
00098 class XMLElementDecl;
00099 class XMLEntityDecl;
00100 class XMLEntityHandler;
00101 class XMLErrorReporter;
00102 class XMLNotationDecl;
00103 class XMLMsgLoader;
00104 class XMLScanner;
00105
00106
00122 class XMLValidator
00123 {
00124 public:
00125 // -----------------------------------------------------------------------
00126 // Class specific types
00127 // -----------------------------------------------------------------------
00128 enum Constants
00129 {
00130 Success = -1
00131 , BadParent = -2
00132 , BadChild = -3
00133 };
00134
00135
00136 enum LookupOpts
00137 {
00138 AddIfNotFound
00139 , FailIfNotFound
00140 };
00141
00142
00143 // -----------------------------------------------------------------------
00144 // Constructors are hidden, just the virtual destructor is exposed
00145 // -----------------------------------------------------------------------
00146
00148 //@{
00149
00154 virtual ~XMLValidator()
00155 {
00156 }
00157 //@}
00158
00159
00160 // -----------------------------------------------------------------------
00161 // Getter methods
00162 // -----------------------------------------------------------------------
00163
00165 //{@
00166
00175 unsigned int getEmptyNamespaceId() const;
00176
00185 unsigned int getGlobalNamespaceId() const;
00186
00196 unsigned int getUnknownNamespaceId() const;
00197
00205 unsigned int getXMLNamespaceId() const;
00206
00214 unsigned int getXMLNSNamespaceId() const;
00215
00216 //@}
00217
00218
00219 // -----------------------------------------------------------------------
00220 // Setter methods
00221 //
00222 // setScannerInfo() is called by the scanner to tell the validator
00223 // about the stuff it needs to have access to.
00224 // -----------------------------------------------------------------------
00225
00227 //{@
00228
00242 void setScannerInfo
00243 (
00244 XMLScanner* const owningScanner
00245 , ReaderMgr* const readerMgr
00246 , XMLBufferMgr* const bufMgr
00247 );
00248
00258 void setErrorReporter
00259 (
00260 XMLErrorReporter* const errorReporter
00261 );
00262
00263 //@}
00264
00265
00266 // -----------------------------------------------------------------------
00267 // The virtual validator interface
00268 // -----------------------------------------------------------------------
00269
00271 //{@
00272
00278 virtual int addOrFindNSId
00279 (
00280 const XMLCh* const uriText
00281 ) = 0;
00282
00303 virtual int checkContent
00304 (
00305 const unsigned int elemId
00306 , const unsigned int* childIds
00307 , const unsigned int childCount
00308 ) = 0;
00309
00315 virtual bool checkRootElement
00316 (
00317 const unsigned int elemId
00318 ) = 0;
00319
00328 virtual void faultInAttr
00329 (
00330 XMLAttr& toFill
00331 , const XMLAttDef& attDef
00332 ) const = 0;
00333
00347 virtual const XMLElementDecl* findElemDecl
00348 (
00349 const unsigned int uriId
00350 , const XMLCh* const baseName
00351 , const XMLCh* const qName
00352 , const LookupOpts options
00353 , bool& wasAdded
00354 ) const = 0;
00355
00356 /*
00357 * This method is identical to the previous one, except that it is a non-
00358 * const version.
00359 */
00360 virtual XMLElementDecl* findElemDecl
00361 (
00362 const unsigned int uriId
00363 , const XMLCh* const baseName
00364 , const XMLCh* const qName
00365 , const LookupOpts options
00366 , bool& wasAdded
00367 ) = 0;
00368
00382 virtual const XMLEntityDecl* findEntityDecl
00383 (
00384 const XMLCh* const entName
00385 , const bool isPE
00386 ) const = 0;
00387
00400 virtual XMLEntityDecl* findEntityDecl
00401 (
00402 const XMLCh* const entName
00403 , const bool isPE
00404 ) = 0;
00405
00413 virtual unsigned int findElemId
00414 (
00415 const unsigned int uriId
00416 , const XMLCh* const baseName
00417 , const XMLCh* const qName
00418 ) const = 0;
00419
00426 virtual const XMLNotationDecl* findNotationDecl
00427 (
00428 const XMLCh* const notName
00429 ) const = 0;
00430
00435 virtual XMLNotationDecl* findNotationDecl
00436 (
00437 const XMLCh* const notName
00438 ) = 0;
00439
00445 virtual unsigned int findNSId
00446 (
00447 const XMLCh* const nsName
00448 ) const = 0;
00449
00456 virtual const XMLElementDecl* getElemDecl
00457 (
00458 const unsigned int elemId
00459 ) const = 0;
00460
00465 virtual XMLElementDecl* getElemDecl
00466 (
00467 const unsigned int elemId
00468 ) = 0;
00469
00476 virtual bool getURIText
00477 (
00478 const unsigned int uriId
00479 , XMLBuffer& uriBufToFill
00480 ) const = 0;
00481
00489 virtual void postParseValidation() = 0;
00490
00496 virtual void reset() = 0;
00497
00504 virtual bool requiresNamespaces() const = 0;
00505
00516 virtual void validateAttrValue
00517 (
00518 const XMLAttDef& attDef
00519 , const XMLCh* const attrValue
00520 ) = 0;
00521
00522 //@}
00523
00524 // -----------------------------------------------------------------------
00525 // Virtual DTD handler interface. If handlesDTD() returns true, then
00526 // scanDTD() will be called when a DOCTYPE is seen.
00527 // -----------------------------------------------------------------------
00528
00530 //{@
00531
00536 virtual bool handlesDTD() const = 0;
00537
00551 virtual void scanDTD(const bool reuseValidator) = 0;
00552
00553 //@}
00554
00555
00556 // -----------------------------------------------------------------------
00557 // Error emitter methods
00558 // -----------------------------------------------------------------------
00559
00561 //{@
00562
00580 void emitError(const XMLValid::Codes toEmit);
00581 void emitError
00582 (
00583 const XMLValid::Codes toEmit
00584 , const XMLCh* const text1
00585 , const XMLCh* const text2 = 0
00586 , const XMLCh* const text3 = 0
00587 , const XMLCh* const text4 = 0
00588 );
00589 void emitError
00590 (
00591 const XMLValid::Codes toEmit
00592 , const char* const text1
00593 , const char* const text2 = 0
00594 , const char* const text3 = 0
00595 , const char* const text4 = 0
00596 );
00597
00598 //@}
00599
00600
00601 protected :
00602 // -----------------------------------------------------------------------
00603 // Hidden constructors
00604 // -----------------------------------------------------------------------
00605 XMLValidator
00606 (
00607 XMLErrorReporter* const errReporter = 0
00608 );
00609
00610
00611 // -----------------------------------------------------------------------
00612 // Protected getters
00613 // -----------------------------------------------------------------------
00614 const XMLBufferMgr* getBufMgr() const;
00615 XMLBufferMgr* getBufMgr();
00616 const ReaderMgr* getReaderMgr() const;
00617 ReaderMgr* getReaderMgr();
00618 const XMLScanner* getScanner() const;
00619 XMLScanner* getScanner();
00620
00621
00622 // -----------------------------------------------------------------------
00623 // Protected methods
00624 // -----------------------------------------------------------------------
00625 void setBaseFields
00626 (
00627 const unsigned int emptyNamespaceId
00628 , const unsigned int globalNamespaceId
00629 , const unsigned int unknownNamespaceId
00630 , const unsigned int xmlNamespaceId
00631 , const unsigned int xmlNSNamespaceId
00632 );
00633
00634
00635 private :
00636 // -----------------------------------------------------------------------
00637 // Unimplemented Constructors and Operators
00638 // -----------------------------------------------------------------------
00639 XMLValidator(const XMLValidator&);
00640 void operator=(const XMLValidator&);
00641
00642
00643 // -----------------------------------------------------------------------
00644 // Private data members
00645 //
00646 // fEmptyNamespaceId
00647 // This is the id of the empty namespace URI. This is a special one
00648 // because of the xmlns="" type of deal. We have to quickly sense
00649 // that its the empty namespace.
00650 //
00651 // fErrorReporter
00652 // The error reporter we are to use, if any.
00653 //
00654 // fGlobalNamespaceId
00655 // This is the id of the namespace URI which is assigned to the
00656 // global namespace. Its for debug purposes only, since there is no
00657 // real global namespace URI. Its set by the derived class.
00658 //
00659 // fUnknownNamespaceId
00660 // This is the id of the namespace URI which is assigned to the
00661 // global namespace. Its for debug purposes only, since there is no
00662 // real global namespace URI. Its set by the derived class.
00663 //
00664 // fXMLNamespaceId
00665 // fXMLNSNamespaceId
00666 // These are the ids of the namespace URIs which are assigned to the
00667 // 'xml' and 'xmlns' special prefixes. The former is officially
00668 // defined but the latter is not, so we just provide one for debug
00669 // purposes.
00670 // -----------------------------------------------------------------------
00671 XMLBufferMgr* fBufMgr;
00672 unsigned int fEmptyNamespaceId;
00673 XMLErrorReporter* fErrorReporter;
00674 unsigned int fGlobalNamespaceId;
00675 ReaderMgr* fReaderMgr;
00676 XMLScanner* fScanner;
00677 unsigned int fUnknownNamespaceId;
00678 unsigned int fXMLNamespaceId;
00679 unsigned int fXMLNSNamespaceId;
00680
00681 };
00682
00683
00684 // ---------------------------------------------------------------------------
00685 // XMLValidator: Getter methods
00686 // ---------------------------------------------------------------------------
00687 inline unsigned int XMLValidator::getEmptyNamespaceId() const
00688 {
00689 return fEmptyNamespaceId;
00690 }
00691
00692 inline unsigned int XMLValidator::getGlobalNamespaceId() const
00693 {
00694 return fGlobalNamespaceId;
00695 }
00696
00697 inline unsigned int XMLValidator::getUnknownNamespaceId() const
00698 {
00699 return fUnknownNamespaceId;
00700 }
00701
00702 inline unsigned int XMLValidator::getXMLNamespaceId() const
00703 {
00704 return fXMLNamespaceId;
00705 }
00706
00707 inline unsigned int XMLValidator::getXMLNSNamespaceId() const
00708 {
00709 return fXMLNSNamespaceId;
00710 }
00711
00712
00713 // -----------------------------------------------------------------------
00714 // Setter methods
00715 // -----------------------------------------------------------------------
00716 inline void
00717 XMLValidator::setScannerInfo(XMLScanner* const owningScanner
00718 , ReaderMgr* const readerMgr
00719 , XMLBufferMgr* const bufMgr)
00720 {
00721 // We don't own any of these, we just reference them
00722 fScanner = owningScanner;
00723 fReaderMgr = readerMgr;
00724 fBufMgr = bufMgr;
00725 }
00726
00727 inline void
00728 XMLValidator::setErrorReporter(XMLErrorReporter* const errorReporter)
00729 {
00730 fErrorReporter = errorReporter;
00731 }
00732
00733
00734 // ---------------------------------------------------------------------------
00735 // XMLValidator: Protected getter
00736 // ---------------------------------------------------------------------------
00737 inline const XMLBufferMgr* XMLValidator::getBufMgr() const
00738 {
00739 return fBufMgr;
00740 }
00741
00742 inline XMLBufferMgr* XMLValidator::getBufMgr()
00743 {
00744 return fBufMgr;
00745 }
00746
00747 inline const ReaderMgr* XMLValidator::getReaderMgr() const
00748 {
00749 return fReaderMgr;
00750 }
00751
00752 inline ReaderMgr* XMLValidator::getReaderMgr()
00753 {
00754 return fReaderMgr;
00755 }
00756
00757 inline const XMLScanner* XMLValidator::getScanner() const
00758 {
00759 return fScanner;
00760 }
00761
00762 inline XMLScanner* XMLValidator::getScanner()
00763 {
00764 return fScanner;
00765 }
00766
00767
00768 // ---------------------------------------------------------------------------
00769 // XMLValidator: Protected methods
00770 // ---------------------------------------------------------------------------
00771 inline void
00772 XMLValidator::setBaseFields(const unsigned int emptyNamespaceId
00773 , const unsigned int globalNamespaceId
00774 , const unsigned int unknownNamespaceId
00775 , const unsigned int xmlNamespaceId
00776 , const unsigned int xmlNSNamespaceId)
00777 {
00778 fEmptyNamespaceId = emptyNamespaceId;
00779 fGlobalNamespaceId = globalNamespaceId;
00780 fUnknownNamespaceId = unknownNamespaceId;
00781 fXMLNamespaceId = xmlNamespaceId;
00782 fXMLNSNamespaceId = xmlNSNamespaceId;
00783 }
00784
00785 #endif