Back to home page

EIC code displayed by LXR

 
 

    


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

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_SGXMLSCANNER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_SGXMLSCANNER_HPP
0024 
0025 #include <xercesc/internal/XMLScanner.hpp>
0026 #include <xercesc/util/KVStringPair.hpp>
0027 #include <xercesc/util/ValueHashTableOf.hpp>
0028 #include <xercesc/util/RefHash2KeysTableOf.hpp>
0029 #include <xercesc/util/RefHash3KeysIdPool.hpp>
0030 #include <xercesc/util/Hash2KeysSetOf.hpp>
0031 #include <xercesc/validators/common/Grammar.hpp>
0032 #include <xercesc/validators/schema/SchemaInfo.hpp>
0033 #include <xercesc/validators/schema/SchemaElementDecl.hpp>
0034 
0035 
0036 XERCES_CPP_NAMESPACE_BEGIN
0037 
0038 class SchemaGrammar;
0039 class SchemaValidator;
0040 class IdentityConstraintHandler;
0041 class IdentityConstraint;
0042 class ContentLeafNameTypeVector;
0043 class SchemaAttDef;
0044 class XMLContentModel;
0045 class XSModel;
0046 class PSVIAttributeList;
0047 class PSVIElement;
0048 
0049 //  This is a scanner class, which process XML Schema grammar.
0050 class XMLPARSER_EXPORT SGXMLScanner : public XMLScanner
0051 {
0052 public :
0053     // -----------------------------------------------------------------------
0054     //  Constructors and Destructor
0055     // -----------------------------------------------------------------------
0056     SGXMLScanner
0057     (
0058         XMLValidator* const       valToAdopt
0059         , GrammarResolver* const grammarResolver
0060         , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
0061     );
0062     SGXMLScanner
0063     (
0064         XMLDocumentHandler* const docHandler
0065         , DocTypeHandler* const   docTypeHandler
0066         , XMLEntityHandler* const entityHandler
0067         , XMLErrorReporter* const errReporter
0068         , XMLValidator* const     valToAdopt
0069         , GrammarResolver* const  grammarResolver
0070         , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
0071     );
0072     virtual ~SGXMLScanner();
0073 
0074     // -----------------------------------------------------------------------
0075     //  XMLScanner public virtual methods
0076     // -----------------------------------------------------------------------
0077     virtual const XMLCh* getName() const;
0078     virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
0079     virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
0080     virtual void scanDocument
0081     (
0082         const   InputSource&    src
0083     );
0084     virtual bool scanNext(XMLPScanToken& toFill);
0085     virtual Grammar* loadGrammar
0086     (
0087         const   InputSource&    src
0088         , const short           grammarType
0089         , const bool            toCache = false
0090     );
0091 
0092     virtual void resetCachedGrammar ();
0093     virtual Grammar::GrammarType getCurrentGrammarType() const;
0094 
0095 protected:
0096     // -----------------------------------------------------------------------
0097     //  XMLScanner virtual methods
0098     // -----------------------------------------------------------------------
0099     virtual void scanReset(const InputSource& src);
0100 
0101     // -----------------------------------------------------------------------
0102     //  SGXMLScanner virtual methods
0103     // -----------------------------------------------------------------------
0104     virtual bool scanStartTag(bool& gotData);
0105     virtual void scanEndTag(bool& gotData);
0106 
0107     // -----------------------------------------------------------------------
0108     //  Helper methods
0109     // -----------------------------------------------------------------------
0110     XMLSize_t buildAttList
0111     (
0112         const   RefVectorOf<KVStringPair>&  providedAttrs
0113         , const XMLSize_t                   attCount
0114         ,       XMLElementDecl*             elemDecl
0115         ,       RefVectorOf<XMLAttr>&       toFill
0116     );
0117     bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv,
0118                               const XMLContentModel* const cm,
0119                               const XMLSize_t parentElemDepth);
0120     XMLSize_t rawAttrScan
0121     (
0122         const   XMLCh* const                elemName
0123         ,       RefVectorOf<KVStringPair>&  toFill
0124         ,       bool&                       isEmpty
0125     );
0126     void updateNSMap
0127     (
0128         const   XMLCh* const    attrName
0129         , const XMLCh* const    attrValue
0130     );
0131     void resizeElemState();
0132 
0133     void updateNSMap
0134     (
0135         const   XMLCh* const    attrName
0136         , const XMLCh* const    attrValue
0137         , const int             colonPosition
0138     );
0139     void resizeRawAttrColonList();
0140     // -----------------------------------------------------------------------
0141     //  Data members
0142     //
0143     //  fRawAttrList
0144     //      During the initial scan of the attributes we can only do a raw
0145     //      scan for key/value pairs. So this vector is used to store them
0146     //      until they can be processed (and put into fAttrList.)
0147     //
0148     //  fSchemaValidator
0149     //      The Schema validator instance.
0150     //
0151     //  fSeeXsi
0152     //      This flag indicates a schema has been seen.
0153     //
0154     //  fElemState
0155     //  fElemLoopState
0156     //  fElemStateSize
0157     //      Stores an element next state from DFA content model - used for
0158     //      wildcard validation
0159     //
0160     // fElemNonDeclPool
0161     //      registry for elements without decls in the grammar
0162     // fElemCount
0163     //      count of the number of start tags seen so far (starts at 1).
0164     //      Used for duplicate attribute detection/processing of required/defaulted attributes
0165     // fAttDefRegistry
0166     //      mapping from XMLAttDef instances to the count of the last
0167     //      start tag where they were utilized.
0168     // fUndeclaredAttrRegistry
0169     //      set of namespaceId/localName pairs to detect duplicates
0170     // fPSVIAttrList
0171     //      PSVI attribute list implementation that needs to be
0172     //      filled when a PSVIHandler is registered
0173     // fSchemaInfoList
0174     //      Transient schema info list that is passed to TraverseSchema instances.
0175     // fCachedSchemaInfoList
0176     //      Cached Schema info list that is passed to TraverseSchema instances.
0177     //
0178     // -----------------------------------------------------------------------
0179     bool                                    fSeeXsi;
0180     Grammar::GrammarType                    fGrammarType;
0181     unsigned int                            fElemStateSize;
0182     unsigned int*                           fElemState;
0183     unsigned int*                           fElemLoopState;
0184     XMLBuffer                               fContent;
0185     ValueHashTableOf<XMLCh>*                fEntityTable;
0186     RefVectorOf<KVStringPair>*              fRawAttrList;
0187     unsigned int                            fRawAttrColonListSize;
0188     int*                                    fRawAttrColonList;
0189     SchemaGrammar*                          fSchemaGrammar;
0190     SchemaValidator*                        fSchemaValidator;
0191     IdentityConstraintHandler*              fICHandler;
0192     RefHash3KeysIdPool<SchemaElementDecl>*  fElemNonDeclPool;
0193     unsigned int                            fElemCount;
0194     RefHashTableOf<unsigned int, PtrHasher>*fAttDefRegistry;
0195     Hash2KeysSetOf<StringHasher>*           fUndeclaredAttrRegistry;
0196     PSVIAttributeList *                     fPSVIAttrList;
0197     XSModel*                                fModel;
0198     PSVIElement*                            fPSVIElement;
0199     ValueStackOf<bool>*                     fErrorStack;
0200     PSVIElemContext                         fPSVIElemContext;
0201     RefHash2KeysTableOf<SchemaInfo>*        fSchemaInfoList;
0202     RefHash2KeysTableOf<SchemaInfo>*        fCachedSchemaInfoList;
0203 
0204 private :
0205     // -----------------------------------------------------------------------
0206     //  Unimplemented constructors and operators
0207     // -----------------------------------------------------------------------
0208     SGXMLScanner();
0209     SGXMLScanner(const SGXMLScanner&);
0210     SGXMLScanner& operator=(const SGXMLScanner&);
0211 
0212     // -----------------------------------------------------------------------
0213     //  XMLScanner virtual methods
0214     // -----------------------------------------------------------------------
0215     virtual void scanCDSection();
0216     virtual void scanCharData(XMLBuffer& toToUse);
0217     virtual EntityExpRes scanEntityRef
0218     (
0219         const   bool    inAttVal
0220         ,       XMLCh&  firstCh
0221         ,       XMLCh&  secondCh
0222         ,       bool&   escaped
0223     );
0224     virtual void scanDocTypeDecl();
0225     virtual void sendCharData(XMLBuffer& toSend);
0226     virtual InputSource* resolveSystemId(const XMLCh* const sysId
0227                                         ,const XMLCh* const pubId);
0228 
0229     // -----------------------------------------------------------------------
0230     //  Private helper methods
0231     // -----------------------------------------------------------------------
0232     void commonInit();
0233     void cleanUp();
0234 
0235     bool normalizeAttValue
0236     (
0237         const   XMLAttDef* const    attDef
0238         , const XMLCh* const        attrName
0239         , const XMLCh* const        value
0240         ,       XMLBuffer&          toFill
0241     );
0242     bool normalizeAttRawValue
0243     (
0244         const   XMLCh* const        attrName
0245         , const XMLCh* const        value
0246         ,       XMLBuffer&          toFill
0247     );
0248     void scanRawAttrListforNameSpaces(XMLSize_t attCount);
0249     void parseSchemaLocation(const XMLCh* const schemaLocationStr, bool ignoreLoadSchema = false);
0250     void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri, bool ignoreLoadSchema = false);
0251     bool switchGrammar(const XMLCh* const newGrammarNameSpace);
0252     bool anyAttributeValidation(SchemaAttDef* attWildCard,
0253                                 unsigned int uriId,
0254                                 bool& skipThisOne,
0255                                 bool& laxThisOne);
0256 
0257     // -----------------------------------------------------------------------
0258     //  Private scanning methods
0259     // -----------------------------------------------------------------------
0260     bool basicAttrValueScan
0261     (
0262         const   XMLCh* const    attrName
0263         ,       XMLBuffer&      toFill
0264     );
0265     bool scanAttValue
0266     (
0267         const   XMLAttDef* const    attDef
0268         ,       XMLBuffer&          toFill
0269     );
0270     bool scanContent();
0271 
0272     // -----------------------------------------------------------------------
0273     //  IdentityConstraints Activation methods
0274     // -----------------------------------------------------------------------
0275     inline bool toCheckIdentityConstraint()  const;
0276 
0277     // -----------------------------------------------------------------------
0278     //  Grammar preparsing methods
0279     // -----------------------------------------------------------------------
0280     Grammar* loadXMLSchemaGrammar(const InputSource& src, const bool toCache = false);
0281 
0282     // -----------------------------------------------------------------------
0283     //  PSVI handling methods
0284     // -----------------------------------------------------------------------
0285     void endElementPSVI(SchemaElementDecl* const elemDecl,
0286                         DatatypeValidator* const memberDV);
0287     void resetPSVIElemContext();
0288 };
0289 
0290 inline const XMLCh* SGXMLScanner::getName() const
0291 {
0292     return XMLUni::fgSGXMLScanner;
0293 }
0294 
0295 inline bool SGXMLScanner::toCheckIdentityConstraint()  const
0296 {
0297     return fValidate && fIdentityConstraintChecking && fICHandler;
0298 }
0299 
0300 inline Grammar::GrammarType SGXMLScanner::getCurrentGrammarType() const
0301 {
0302     return fGrammarType;
0303 }
0304 
0305 XERCES_CPP_NAMESPACE_END
0306 
0307 #endif