source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/internal/SGXMLScanner.hpp @ 2674

Revision 2674, 11.9 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: SGXMLScanner.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#if !defined(SGXMLSCANNER_HPP)
24#define SGXMLSCANNER_HPP
25
26#include <xercesc/internal/XMLScanner.hpp>
27#include <xercesc/util/KVStringPair.hpp>
28#include <xercesc/util/ValueHashTableOf.hpp>
29#include <xercesc/util/RefHash3KeysIdPool.hpp>
30#include <xercesc/validators/common/Grammar.hpp>
31#include <xercesc/validators/schema/SchemaElementDecl.hpp>
32
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36class SchemaGrammar;
37class SchemaValidator;
38class IdentityConstraintHandler;
39class IdentityConstraint;
40class ContentLeafNameTypeVector;
41class SchemaAttDef;
42class XMLContentModel;
43class XSModel;
44class PSVIAttributeList;
45class PSVIElement;
46
47//  This is a scanner class, which process XML Schema grammar.
48class XMLPARSER_EXPORT SGXMLScanner : public XMLScanner
49{
50public :
51    // -----------------------------------------------------------------------
52    //  Constructors and Destructor
53    // -----------------------------------------------------------------------
54    SGXMLScanner
55    (
56        XMLValidator* const       valToAdopt
57        , GrammarResolver* const grammarResolver
58        , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
59    );
60    SGXMLScanner
61    (
62        XMLDocumentHandler* const docHandler
63        , DocTypeHandler* const   docTypeHandler
64        , XMLEntityHandler* const entityHandler
65        , XMLErrorReporter* const errReporter
66        , XMLValidator* const     valToAdopt
67        , GrammarResolver* const  grammarResolver
68        , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
69    );
70    virtual ~SGXMLScanner();
71
72    // -----------------------------------------------------------------------
73    //  XMLScanner public virtual methods
74    // -----------------------------------------------------------------------
75    virtual const XMLCh* getName() const;
76    virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
77    virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
78    virtual unsigned int resolveQName
79    (
80        const   XMLCh* const        qName
81        ,       XMLBuffer&          prefixBufToFill
82        , const short               mode
83        ,       int&                prefixColonPos
84    );
85    virtual void scanDocument
86    (
87        const   InputSource&    src
88    );
89    virtual bool scanNext(XMLPScanToken& toFill);
90    virtual Grammar* loadGrammar
91    (
92        const   InputSource&    src
93        , const short           grammarType
94        , const bool            toCache = false
95    );
96    virtual Grammar::GrammarType getCurrentGrammarType() const;
97
98protected:
99    // -----------------------------------------------------------------------
100    //  XMLScanner virtual methods
101    // -----------------------------------------------------------------------
102    virtual void scanReset(const InputSource& src);
103
104    // -----------------------------------------------------------------------
105    //  SGXMLScanner virtual methods
106    // -----------------------------------------------------------------------
107    virtual bool scanStartTag(bool& gotData);
108    virtual void scanEndTag(bool& gotData);
109
110    // -----------------------------------------------------------------------
111    //  Helper methods
112    // -----------------------------------------------------------------------
113    unsigned int buildAttList
114    (
115        const   RefVectorOf<KVStringPair>&  providedAttrs
116        , const unsigned int                attCount
117        ,       XMLElementDecl*             elemDecl
118        ,       RefVectorOf<XMLAttr>&       toFill
119    );
120    bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv,
121                              const XMLContentModel* const cm,
122                              const unsigned int parentElemDepth);
123    unsigned int rawAttrScan
124    (
125        const   XMLCh* const                elemName
126        ,       RefVectorOf<KVStringPair>&  toFill
127        ,       bool&                       isEmpty
128    );
129    void updateNSMap
130    (
131        const   XMLCh* const    attrName
132        , const XMLCh* const    attrValue
133    );
134    unsigned int resolvePrefix
135    (
136        const   XMLCh* const        prefix
137        , const ElemStack::MapModes mode
138    );
139    void resizeElemState();
140
141    void updateNSMap
142    (
143        const   XMLCh* const    attrName
144        , const XMLCh* const    attrValue
145        , const int             colonPosition
146    );
147    void resizeRawAttrColonList();
148    unsigned int resolveQNameWithColon
149    (
150        const   XMLCh* const        qName
151        ,       XMLBuffer&          prefixBufToFill
152        , const short               mode
153        , const int                 prefixColonPos
154    );
155    // -----------------------------------------------------------------------
156    //  Data members
157    //
158    //  fRawAttrList
159    //      During the initial scan of the attributes we can only do a raw
160    //      scan for key/value pairs. So this vector is used to store them
161    //      until they can be processed (and put into fAttrList.)
162    //
163    //  fSchemaValidator
164    //      The Schema validator instance.
165    //
166    //  fSeeXsi
167    //      This flag indicates a schema has been seen.
168    //
169    //  fElemState
170    //  fElemStateSize
171    //      Stores an element next state from DFA content model - used for
172    //      wildcard validation
173    //
174    // fElemNonDeclPool
175    //      registry for elements without decls in the grammar
176    // fElemCount
177    //      count of the number of start tags seen so far (starts at 1).
178    //      Used for duplicate attribute detection/processing of required/defaulted attributes
179    // fAttDefRegistry
180    //      mapping from XMLAttDef instances to the count of the last
181    //      start tag where they were utilized.
182    // fUndeclaredAttrRegistryNS
183    //      mapping of namespaceId/localName pairs to the count of the last
184    //      start tag in which they occurred.
185    //  fPSVIAttrList
186    //      PSVI attribute list implementation that needs to be
187    //      filled when a PSVIHandler is registered
188    //
189    // -----------------------------------------------------------------------
190    bool                                    fSeeXsi;
191    Grammar::GrammarType                    fGrammarType;
192    unsigned int                            fElemStateSize;
193    unsigned int*                           fElemState;
194    XMLBuffer                               fContent;
195    ValueHashTableOf<XMLCh>*                fEntityTable;
196    RefVectorOf<KVStringPair>*              fRawAttrList;
197    unsigned int                            fRawAttrColonListSize;
198    int*                                    fRawAttrColonList;
199    SchemaGrammar*                          fSchemaGrammar;
200    SchemaValidator*                        fSchemaValidator;
201    IdentityConstraintHandler*              fICHandler;
202    RefHash3KeysIdPool<SchemaElementDecl>*  fElemNonDeclPool;
203    unsigned int                            fElemCount;
204    RefHashTableOf<unsigned int>*           fAttDefRegistry;
205    RefHash2KeysTableOf<unsigned int>*      fUndeclaredAttrRegistryNS;
206    PSVIAttributeList *                     fPSVIAttrList;
207    XSModel*                                fModel;
208    PSVIElement*                            fPSVIElement;
209    ValueStackOf<bool>*                     fErrorStack;
210    PSVIElemContext                         fPSVIElemContext;
211
212private :
213    // -----------------------------------------------------------------------
214    //  Unimplemented constructors and operators
215    // -----------------------------------------------------------------------
216    SGXMLScanner();
217    SGXMLScanner(const SGXMLScanner&);
218    SGXMLScanner& operator=(const SGXMLScanner&);
219
220    // -----------------------------------------------------------------------
221    //  XMLScanner virtual methods
222    // -----------------------------------------------------------------------
223    virtual void scanCDSection();
224    virtual void scanCharData(XMLBuffer& toToUse);
225    virtual EntityExpRes scanEntityRef
226    (
227        const   bool    inAttVal
228        ,       XMLCh&  firstCh
229        ,       XMLCh&  secondCh
230        ,       bool&   escaped
231    );
232    virtual void scanDocTypeDecl();
233    virtual void sendCharData(XMLBuffer& toSend);
234    virtual InputSource* resolveSystemId(const XMLCh* const sysId
235                                        ,const XMLCh* const pubId);
236
237    // -----------------------------------------------------------------------
238    //  Private helper methods
239    // -----------------------------------------------------------------------
240    void commonInit();
241    void cleanUp();
242
243    bool normalizeAttValue
244    (
245        const   XMLAttDef* const    attDef
246        , const XMLCh* const        attrName
247        , const XMLCh* const        value
248        ,       XMLBuffer&          toFill
249    );
250    bool normalizeAttRawValue
251    (
252        const   XMLCh* const        attrName
253        , const XMLCh* const        value
254        ,       XMLBuffer&          toFill
255    );
256    unsigned int resolvePrefix
257    (
258        const   XMLCh* const        prefix
259        ,       XMLBuffer&          uriBufToFill
260        , const ElemStack::MapModes mode
261    );
262    void scanRawAttrListforNameSpaces(int attCount);
263    void parseSchemaLocation(const XMLCh* const schemaLocationStr);
264    void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri);
265    bool switchGrammar(const XMLCh* const newGrammarNameSpace);
266    bool anyAttributeValidation(SchemaAttDef* attWildCard,
267                                unsigned int uriId,
268                                bool& skipThisOne,
269                                bool& laxThisOne);
270
271    // -----------------------------------------------------------------------
272    //  Private scanning methods
273    // -----------------------------------------------------------------------
274    bool basicAttrValueScan
275    (
276        const   XMLCh* const    attrName
277        ,       XMLBuffer&      toFill
278    );
279    bool scanAttValue
280    (
281        const   XMLAttDef* const    attDef
282        ,       XMLBuffer&          toFill
283    );
284    bool scanContent();
285
286    // -----------------------------------------------------------------------
287    //  IdentityConstraints Activation methods
288    // -----------------------------------------------------------------------
289    inline bool toCheckIdentityConstraint()  const;
290
291    // -----------------------------------------------------------------------
292    //  Grammar preparsing methods
293    // -----------------------------------------------------------------------
294    Grammar* loadXMLSchemaGrammar(const InputSource& src, const bool toCache = false);
295
296    // -----------------------------------------------------------------------
297    //  PSVI handling methods
298    // -----------------------------------------------------------------------
299    void endElementPSVI(SchemaElementDecl* const elemDecl,
300                        DatatypeValidator* const memberDV);
301    void resetPSVIElemContext();
302};
303
304inline const XMLCh* SGXMLScanner::getName() const
305{
306    return XMLUni::fgSGXMLScanner;
307}
308
309inline bool SGXMLScanner::toCheckIdentityConstraint()  const
310{
311    return fValidate && fIdentityConstraintChecking && fICHandler;
312}
313
314inline Grammar::GrammarType SGXMLScanner::getCurrentGrammarType() const
315{
316    return fGrammarType;
317}
318
319XERCES_CPP_NAMESPACE_END
320
321#endif
Note: See TracBrowser for help on using the repository browser.