Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:53

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018  /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLVALIDATOR_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLVALIDATOR_HPP
0024 
0025 #include <xercesc/framework/XMLAttr.hpp>
0026 #include <xercesc/framework/XMLValidityCodes.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 class ReaderMgr;
0031 class XMLBufferMgr;
0032 class XMLElementDecl;
0033 class XMLScanner;
0034 class Grammar;
0035 
0036 
0037 /**
0038  *  This abstract class provides the interface for all validators. This is
0039  *  the simple amount of API that all validators must honor, in order for
0040  *  the scanner to use them to do validation. All validators will actually
0041  *  contain much more functionality than is accessible via this common API,
0042  *  but that functionality requires that you know what type of validator you
0043  *  are dealing with.
0044  *
0045  *  Basically, at this level, the primary concern is to be able to query
0046  *  core information about elements and attributes. Adding decls to the
0047  *  validator requires that you go through the derived interface because they
0048  *  all have their own decl types. At this level, we can return information
0049  *  via the base decl classes, from which each validator derives its own
0050  *  decl classes.
0051  */
0052 class XMLPARSER_EXPORT XMLValidator : public XMemory
0053 {
0054 public:
0055     // -----------------------------------------------------------------------
0056     //  Constructors are hidden, just the virtual destructor is exposed
0057     // -----------------------------------------------------------------------
0058 
0059     /** @name Destructor */
0060     //@{
0061 
0062     /**
0063      *  The derived class should clean up its allocated data, then this class
0064      *  will do the same for data allocated at this level.
0065      */
0066     virtual ~XMLValidator()
0067     {
0068     }
0069     //@}
0070 
0071 
0072     // -----------------------------------------------------------------------
0073     //  The virtual validator interface
0074     // -----------------------------------------------------------------------
0075 
0076     /** @name Virtual validator interface */
0077     //@{
0078 
0079     /**
0080       * The derived class should look up its declaration of the passed element
0081       * from its element pool. It should then use the content model description
0082       * contained in that element declaration to validate that the passed list
0083       * of child elements are valid for that content model. The count can be
0084       * zero, indicating no child elements.
0085       *
0086       * Note that whitespace and text content are not validated here. Those are
0087       * handled by the scanner. So only element ids are provided here.
0088       *
0089       * @param  elemDecl    The element whose content is to be checked.
0090       *
0091       * @param  children    An array of element QName which represent the elements
0092       *                     found within the parent element, i.e. the content
0093       *                     to be validated.
0094       *
0095       * @param  childCount  The number of elements in the childIds array. It can
0096       *                     be zero if the element had none.
0097       *
0098       * @param  indexFailingChild  On return, it will contain the index of the 
0099       *                            children failing validation, if the retun value
0100       *                            is false
0101       *
0102       */
0103     virtual bool checkContent
0104     (
0105         XMLElementDecl* const   elemDecl
0106         , QName** const         children
0107         , XMLSize_t             childCount
0108         , XMLSize_t*            indexFailingChild
0109     ) = 0;
0110 
0111     /**
0112       * The derived class should fault in the passed XMLAttr value. It should
0113       * use the passeed attribute definition (which is passed via the base
0114       * type so it must often be downcast to the appropriate type for the
0115       * derived validator class), to fill in the passed attribute. This is done
0116       * as a performance enhancement since the derived class has more direct
0117       * access to the information.
0118       */
0119     virtual void faultInAttr
0120     (
0121                 XMLAttr&    toFill
0122         , const XMLAttDef&  attDef
0123     )   const = 0;
0124 
0125     /**
0126       * This method is called by the scanner after a Grammar is scanned.
0127       */
0128     virtual void preContentValidation(bool reuseGrammar,
0129                                       bool validateDefAttr = false) = 0;
0130 
0131     /**
0132       * This method is called by the scanner after the parse has completed. It
0133       * gives the validator a chance to check certain things that can only be
0134       * checked after the whole document has been parsed, such as referential
0135       * integrity of ID/IDREF pairs and so forth. The validator should just
0136       * issue errors for any problems it finds.
0137       */
0138     virtual void postParseValidation() = 0;
0139 
0140     /**
0141       * This method is called by the scanner before a new document is about
0142       * to start. It gives the validator a change to reset itself in preparation
0143       * for another validation pass.
0144       */
0145     virtual void reset() = 0;
0146 
0147     /**
0148       * The derived class should return a boolean that indicates whether it
0149       * requires namespace processing or not. Some do and some allow it to be
0150       * optional. This flag is used to control whether the client code's
0151       * requests to disable namespace processing can be honored or not.
0152       */
0153     virtual bool requiresNamespaces() const = 0;
0154 
0155     /**
0156       * The derived class should apply any rules to the passed attribute value
0157       * that are above and beyond those defined by XML 1.0. The scanner itself
0158       * will impose XML 1.0 rules, based on the type of the attribute. This
0159       * will generally be used to check things such as range checks and other
0160       * datatype related validation.
0161       *
0162       * If the value breaks any rules as defined by the derived class, it
0163       * should just issue errors as usual.
0164       */
0165     virtual void validateAttrValue
0166     (
0167         const   XMLAttDef*                  attDef
0168         , const XMLCh* const                attrValue
0169         , bool                              preValidation = false
0170         , const XMLElementDecl*             elemDecl = 0
0171     ) = 0;
0172 
0173     /**
0174       * The derived class should apply any rules to the passed element decl
0175       * that are above and beyond those defined by XML 1.0.
0176       *
0177       * If the value breaks any rules as defined by the derived class, it
0178       * should just issue errors as usual.
0179       */
0180     virtual void validateElement
0181     (
0182         const   XMLElementDecl*             elemDef
0183     ) = 0;
0184 
0185     /**
0186       * Retrieve the Grammar used
0187       */
0188     virtual Grammar* getGrammar() const =0;
0189 
0190     /**
0191       * Set the Grammar
0192       */
0193     virtual void setGrammar(Grammar* aGrammar) =0;
0194 
0195 
0196     //@}
0197 
0198     // -----------------------------------------------------------------------
0199     //  Virtual DTD handler interface.
0200     // -----------------------------------------------------------------------
0201 
0202     /** @name Virtual DTD handler interface */
0203     //@{
0204 
0205     /**
0206       * This method allows the scanner to ask the validator if it handles
0207       * DTDs or not.
0208       */
0209     virtual bool handlesDTD() const = 0;
0210 
0211     // -----------------------------------------------------------------------
0212     //  Virtual Schema handler interface.
0213     // -----------------------------------------------------------------------
0214 
0215     /** @name Virtual Schema handler interface */
0216 
0217     /**
0218       * This method allows the scanner to ask the validator if it handles
0219       * Schema or not.
0220       */
0221     virtual bool handlesSchema() const = 0;
0222 
0223     //@}
0224 
0225     // -----------------------------------------------------------------------
0226     //  Setter methods
0227     //
0228     //  setScannerInfo() is called by the scanner to tell the validator
0229     //  about the stuff it needs to have access to.
0230     // -----------------------------------------------------------------------
0231 
0232     /** @name Setter methods */
0233     //@{
0234 
0235     /**
0236       * @param  owningScanner   This is a pointer to the scanner to which the
0237       *                         validator belongs. The validator will often
0238       *                         need to query state data from the scanner.
0239       *
0240       * @param  readerMgr       This is a pointer to the reader manager that is
0241       *                         being used by the scanner.
0242       *
0243       * @param  bufMgr          This is the buffer manager of the scanner. This
0244       *                         is provided as a convenience so that the validator
0245       *                         doesn't have to create its own buffer manager
0246       *                         during the parse process.
0247       */
0248     void setScannerInfo
0249     (
0250         XMLScanner* const           owningScanner
0251         , ReaderMgr* const          readerMgr
0252         , XMLBufferMgr* const       bufMgr
0253     );
0254 
0255     /**
0256       * This method is called to set an error reporter on the validator via
0257       * which it will report any errors it sees during parsing or validation.
0258       * This is generally called by the owning scanner.
0259       *
0260       * @param  errorReporter   A pointer to the error reporter to use. This
0261       *                         is not adopted, just referenced so the caller
0262       *                         remains responsible for its cleanup, if any.
0263       */
0264     void setErrorReporter
0265     (
0266         XMLErrorReporter* const errorReporter
0267     );
0268 
0269     //@}
0270 
0271 
0272     // -----------------------------------------------------------------------
0273     //  Error emitter methods
0274     // -----------------------------------------------------------------------
0275 
0276     /** @name Error emittor methods */
0277     //@{
0278 
0279     /**
0280      *  This call is a convenience by which validators can emit errors. Most
0281      *  of the grunt work of loading the text, getting the current source
0282      *  location, ect... is handled here.
0283      *
0284      *  If the loaded text has replacement parameters, then text strings can be
0285      *  passed. These will be used to replace the tokens {0}, {1}, {2}, and {3}
0286      *  in the order passed. So text1 will replace {0}, text2 will replace {1},
0287      *  and so forth.
0288      *
0289      *  textX   Up to four replacement parameters. They can be provided
0290      *          as either XMLCh strings, or local code page strings which
0291      *          will be transcoded internally.
0292      *
0293      *  @param toEmit   The error code to emit. it must be one of the defined
0294      *                  validator error codes.
0295      *
0296      */
0297     void emitError(const XMLValid::Codes toEmit);
0298     void emitError
0299     (
0300         const   XMLValid::Codes toEmit
0301         , const XMLCh* const    text1
0302         , const XMLCh* const    text2 = 0
0303         , const XMLCh* const    text3 = 0
0304         , const XMLCh* const    text4 = 0
0305     );
0306     void emitError
0307     (
0308         const   XMLValid::Codes toEmit
0309         , const char* const     text1
0310         , const char* const     text2 = 0
0311         , const char* const     text3 = 0
0312         , const char* const     text4 = 0
0313     );
0314     void emitError
0315     (
0316         const   XMLValid::Codes toEmit
0317         , const XMLExcepts::Codes   originalErrorCode
0318         , const XMLCh* const        text1 = 0
0319         , const XMLCh* const        text2 = 0
0320         , const XMLCh* const        text3 = 0
0321         , const XMLCh* const        text4 = 0
0322 
0323     );
0324 
0325     //@}
0326 
0327 protected :
0328     // -----------------------------------------------------------------------
0329     //  Hidden constructors
0330     // -----------------------------------------------------------------------
0331     XMLValidator
0332     (
0333         XMLErrorReporter* const errReporter = 0
0334     );
0335 
0336 
0337     // -----------------------------------------------------------------------
0338     //  Protected getters
0339     // -----------------------------------------------------------------------
0340     const XMLBufferMgr* getBufMgr() const;
0341     XMLBufferMgr* getBufMgr();
0342     const ReaderMgr* getReaderMgr() const;
0343     ReaderMgr* getReaderMgr();
0344     const XMLScanner* getScanner() const;
0345     XMLScanner* getScanner();
0346 
0347 
0348 private :
0349     // -----------------------------------------------------------------------
0350     //  Unimplemented Constructors and Operators
0351     // -----------------------------------------------------------------------
0352     XMLValidator(const XMLValidator&);
0353     XMLValidator& operator=(const XMLValidator&);
0354 
0355 
0356     // -----------------------------------------------------------------------
0357     //  Private data members
0358     //
0359     //  fErrorReporter
0360     //      The error reporter we are to use, if any.
0361     //
0362     // -----------------------------------------------------------------------
0363     XMLBufferMgr*       fBufMgr;
0364     XMLErrorReporter*   fErrorReporter;
0365     ReaderMgr*          fReaderMgr;
0366     XMLScanner*         fScanner;
0367 };
0368 
0369 
0370 // -----------------------------------------------------------------------
0371 //  Setter methods
0372 // -----------------------------------------------------------------------
0373 inline void
0374 XMLValidator::setScannerInfo(XMLScanner* const      owningScanner
0375                             , ReaderMgr* const      readerMgr
0376                             , XMLBufferMgr* const   bufMgr)
0377 {
0378     // We don't own any of these, we just reference them
0379     fScanner = owningScanner;
0380     fReaderMgr = readerMgr;
0381     fBufMgr = bufMgr;
0382 }
0383 
0384 inline void
0385 XMLValidator::setErrorReporter(XMLErrorReporter* const errorReporter)
0386 {
0387     fErrorReporter = errorReporter;
0388 }
0389 
0390 
0391 // ---------------------------------------------------------------------------
0392 //  XMLValidator: Protected getter
0393 // ---------------------------------------------------------------------------
0394 inline const XMLBufferMgr* XMLValidator::getBufMgr() const
0395 {
0396     return fBufMgr;
0397 }
0398 
0399 inline XMLBufferMgr* XMLValidator::getBufMgr()
0400 {
0401     return fBufMgr;
0402 }
0403 
0404 inline const ReaderMgr* XMLValidator::getReaderMgr() const
0405 {
0406     return fReaderMgr;
0407 }
0408 
0409 inline ReaderMgr* XMLValidator::getReaderMgr()
0410 {
0411     return fReaderMgr;
0412 }
0413 
0414 inline const XMLScanner* XMLValidator::getScanner() const
0415 {
0416     return fScanner;
0417 }
0418 
0419 inline XMLScanner* XMLValidator::getScanner()
0420 {
0421     return fScanner;
0422 }
0423 
0424 XERCES_CPP_NAMESPACE_END
0425 
0426 #endif