source: NonGTP/Xerces/xerces/include/xercesc/internal/IGXMLScanner.hpp @ 358

Revision 358, 14.0 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Log: IGXMLScanner.hpp,v $
19 * Revision 1.23  2004/09/08 13:56:13  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.22  2004/05/25 18:09:50  peiyongz
23 * XML1.0 3rd: 4.2.2 ...Since escaping is not always a fully reversible process,
24 * it must be performed only when absolutely necessary and as late as possible
25 * in a processing chain...
26 *
27 * Revision 1.21  2004/04/13 17:00:23  peiyongz
28 * IdentityConstraintHandler
29 *
30 * Revision 1.19  2004/04/07 14:14:08  peiyongz
31 * make resolveSystemId virutal
32 *
33 * Revision 1.18  2004/01/29 11:46:30  cargilld
34 * Code cleanup changes to get rid of various compiler diagnostic messages.
35 *
36 * Revision 1.17  2003/11/28 19:54:31  knoaman
37 * PSVIElement update
38 *
39 * Revision 1.16  2003/11/28 05:13:29  neilg
40 * Fix state-ful duplicate attribute detection when the integrated
41 * scanner is in use and namespaces are off.  Also, implement
42 * change to PSVIHandler interface to remove prefix passing.
43 *
44 * Revision 1.15  2003/11/27 22:52:37  knoaman
45 * PSVIElement implementation
46 *
47 * Revision 1.14  2003/11/27 06:10:31  neilg
48 * PSVIAttribute implementation
49 *
50 * Revision 1.13  2003/11/26 16:20:00  knoaman
51 * Store XSModel.
52 *
53 * Revision 1.12  2003/11/24 05:09:38  neilg
54 * implement new, statless, method for detecting duplicate attributes
55 *
56 * Revision 1.11  2003/10/22 20:22:30  knoaman
57 * Prepare for annotation support.
58 *
59 * Revision 1.10  2003/09/22 19:51:41  neilg
60 * scanners should maintain their own pools of undeclared elements, rather than requiring grammars to do this.  This makes grammar objects stateless with regard to validation.
61 *
62 * Revision 1.9  2003/08/14 02:56:41  knoaman
63 * Code refactoring to improve performance of validation.
64 *
65 * Revision 1.8  2003/07/10 19:47:23  peiyongz
66 * Stateless Grammar: Initialize scanner with grammarResolver,
67 *                                creating grammar through grammarPool
68 *
69 * Revision 1.7  2003/05/22 02:10:51  knoaman
70 * Default the memory manager.
71 *
72 * Revision 1.6  2003/05/15 18:26:29  knoaman
73 * Partial implementation of the configurable memory manager.
74 *
75 * Revision 1.5  2003/03/07 18:08:58  tng
76 * Return a reference instead of void for operator=
77 *
78 * Revision 1.4  2003/01/29 19:59:35  gareth
79 * we now detect when elements and attributes are validated/ the result of the validation and store that information.
80 *
81 * Revision 1.3  2003/01/15 15:49:49  knoaman
82 * Change constant declaration name to match its value.
83 *
84 * Revision 1.2  2003/01/13 16:30:18  knoaman
85 * [Bug 14469] Validator doesn't enforce xsd:key.
86 *
87 * Revision 1.1  2002/12/04 02:05:25  knoaman
88 * Initial checkin.
89 *
90 */
91
92
93#if !defined(IGXMLSCANNER_HPP)
94#define IGXMLSCANNER_HPP
95
96#include <xercesc/internal/XMLScanner.hpp>
97#include <xercesc/util/KVStringPair.hpp>
98#include <xercesc/util/NameIdPool.hpp>
99#include <xercesc/util/RefHash3KeysIdPool.hpp>
100#include <xercesc/validators/common/Grammar.hpp>
101#include <xercesc/validators/schema/SchemaElementDecl.hpp>
102
103XERCES_CPP_NAMESPACE_BEGIN
104
105class DTDElementDecl;
106class DTDGrammar;
107class DTDValidator;
108class SchemaValidator;
109class IdentityConstraintHandler;
110class IdentityConstraint;
111class ContentLeafNameTypeVector;
112class SchemaAttDef;
113class XMLContentModel;
114class XSModel;
115class PSVIAttributeList;
116class PSVIElement;
117
118//  This is an integrated scanner class, which does DTD/XML Schema grammar
119//  processing.
120class XMLPARSER_EXPORT IGXMLScanner : public XMLScanner
121{
122public :
123    // -----------------------------------------------------------------------
124    //  Constructors and Destructor
125    // -----------------------------------------------------------------------
126    IGXMLScanner
127    (
128        XMLValidator* const valToAdopt
129        , GrammarResolver* const grammarResolver
130        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
131    );
132    IGXMLScanner
133    (
134          XMLDocumentHandler* const docHandler
135        , DocTypeHandler* const     docTypeHandler
136        , XMLEntityHandler* const   entityHandler
137        , XMLErrorReporter* const   errReporter
138        , XMLValidator* const       valToAdopt
139        , GrammarResolver* const    grammarResolver
140        , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
141    );
142    virtual ~IGXMLScanner();
143
144    // -----------------------------------------------------------------------
145    //  XMLScanner public virtual methods
146    // -----------------------------------------------------------------------
147    virtual const XMLCh* getName() const;
148    virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
149    virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
150    virtual unsigned int resolveQName
151    (
152        const   XMLCh* const        qName
153        ,       XMLBuffer&          prefixBufToFill
154        , const short               mode
155        ,       int&                prefixColonPos
156    );
157    virtual void scanDocument
158    (
159        const   InputSource&    src
160    );
161    virtual bool scanNext(XMLPScanToken& toFill);
162    virtual Grammar* loadGrammar
163    (
164        const   InputSource&    src
165        , const short           grammarType
166        , const bool            toCache = false
167    );
168
169private :
170    // -----------------------------------------------------------------------
171    //  Unimplemented constructors and operators
172    // -----------------------------------------------------------------------
173    IGXMLScanner();
174    IGXMLScanner(const IGXMLScanner&);
175    IGXMLScanner& operator=(const IGXMLScanner&);
176
177    // -----------------------------------------------------------------------
178    //  XMLScanner virtual methods
179    // -----------------------------------------------------------------------
180    virtual void scanCDSection();
181    virtual void scanCharData(XMLBuffer& toToUse);
182    virtual EntityExpRes scanEntityRef
183    (
184        const   bool    inAttVal
185        ,       XMLCh&  firstCh
186        ,       XMLCh&  secondCh
187        ,       bool&   escaped
188    );
189    virtual void scanDocTypeDecl();
190    virtual void scanReset(const InputSource& src);
191    virtual void sendCharData(XMLBuffer& toSend);
192    virtual InputSource* resolveSystemId(const XMLCh* const sysId);
193
194    // -----------------------------------------------------------------------
195    //  Private helper methods
196    // -----------------------------------------------------------------------
197    void commonInit();
198    void cleanUp();
199
200    unsigned int buildAttList
201    (
202        const   RefVectorOf<KVStringPair>&  providedAttrs
203        , const unsigned int                attCount
204        ,       XMLElementDecl*             elemDecl
205        ,       RefVectorOf<XMLAttr>&       toFill
206    );
207    bool normalizeAttValue
208    (
209        const   XMLAttDef* const    attDef
210        , const XMLCh* const       name
211        , const XMLCh* const        value
212        ,       XMLBuffer&          toFill
213    );
214    bool normalizeAttRawValue
215    (
216        const   XMLCh* const        attrName
217        , const XMLCh* const        value
218        ,       XMLBuffer&          toFill
219    );
220    unsigned int resolvePrefix
221    (
222        const   XMLCh* const        prefix
223        , const ElemStack::MapModes mode
224    );
225    unsigned int resolvePrefix
226    (
227        const   XMLCh* const        prefix
228        ,       XMLBuffer&          uriBufToFill
229        , const ElemStack::MapModes mode
230    );
231    void updateNSMap
232    (
233        const   XMLCh* const    attrName
234        , const XMLCh* const    attrValue
235    );
236    void scanRawAttrListforNameSpaces(int attCount);
237    void parseSchemaLocation(const XMLCh* const schemaLocationStr);
238    void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri);
239    bool switchGrammar(const XMLCh* const newGrammarNameSpace);
240    bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv,
241                              const XMLContentModel* const cm,
242                              const unsigned int parentElemDepth);
243    bool anyAttributeValidation(SchemaAttDef* attWildCard,
244                                unsigned int uriId,
245                                bool& skipThisOne,
246                                bool& laxThisOne);
247    void resizeElemState();
248    void processSchemaLocation(XMLCh* const schemaLoc);
249
250    // -----------------------------------------------------------------------
251    //  Private scanning methods
252    // -----------------------------------------------------------------------
253    bool basicAttrValueScan
254    (
255        const   XMLCh* const    attrName
256        ,       XMLBuffer&      toFill
257    );
258    unsigned int rawAttrScan
259    (
260        const   XMLCh* const                elemName
261        ,       RefVectorOf<KVStringPair>&  toFill
262        ,       bool&                       isEmpty
263    );
264    bool scanAttValue
265    (
266        const   XMLAttDef* const    attDef
267        , const   XMLCh* const      attrName
268        ,       XMLBuffer&          toFill
269    );
270    bool scanContent();
271    void scanEndTag(bool& gotData);
272    bool scanStartTag(bool& gotData);
273    bool scanStartTagNS(bool& gotData);
274
275    // -----------------------------------------------------------------------
276    //  IdentityConstraints Activation methods
277    // -----------------------------------------------------------------------
278    inline bool toCheckIdentityConstraint()  const;
279
280    // -----------------------------------------------------------------------
281    //  Grammar preparsing methods
282    // -----------------------------------------------------------------------
283    Grammar* loadXMLSchemaGrammar(const InputSource& src, const bool toCache = false);
284    Grammar* loadDTDGrammar(const InputSource& src, const bool toCache = false);
285
286    // -----------------------------------------------------------------------
287    //  PSVI handling methods
288    // -----------------------------------------------------------------------
289    void endElementPSVI(SchemaElementDecl* const elemDecl,
290                        DatatypeValidator* const memberDV);
291    void resetPSVIElemContext();
292
293    // -----------------------------------------------------------------------
294    //  Data members
295    //
296    //  fRawAttrList
297    //      During the initial scan of the attributes we can only do a raw
298    //      scan for key/value pairs. So this vector is used to store them
299    //      until they can be processed (and put into fAttrList.)
300    //
301    //  fDTDValidator
302    //      The DTD validator instance.
303    //
304    //  fSchemaValidator
305    //      The Schema validator instance.
306    //
307    //  fSeeXsi
308    //      This flag indicates a schema has been seen.
309    //
310    //  fElemState
311    //  fElemStateSize
312    //      Stores an element next state from DFA content model - used for
313    //      wildcard validation
314    //
315    // fDTDElemNonDeclPool
316    //      registry of "faulted-in" DTD element decls
317    // fSchemaElemNonDeclPool
318    //      registry for elements without decls in the grammar
319    // fElemCount
320    //      count of the number of start tags seen so far (starts at 1).
321    //      Used for duplicate attribute detection/processing of required/defaulted attributes
322    // fAttDefRegistry
323    //      mapping from XMLAttDef instances to the count of the last
324    //      start tag where they were utilized.
325    // fUndeclaredAttrRegistry
326    //      mapping of attr QNames to the count of the last start tag in which they occurred
327    // fUndeclaredAttrRegistryNS
328    //      mapping of namespaceId/localName pairs to the count of the last
329    //      start tag in which they occurred.
330    //  fPSVIAttrList
331    //      PSVI attribute list implementation that needs to be
332    //      filled when a PSVIHandler is registered
333    //
334    // -----------------------------------------------------------------------
335    bool                                    fSeeXsi;
336    Grammar::GrammarType                    fGrammarType;
337    unsigned int                            fElemStateSize;
338    unsigned int*                           fElemState;
339    XMLBuffer                               fContent;
340    RefVectorOf<KVStringPair>*              fRawAttrList;
341    DTDValidator*                           fDTDValidator;
342    SchemaValidator*                        fSchemaValidator;
343    DTDGrammar*                             fDTDGrammar;
344    IdentityConstraintHandler*              fICHandler;
345    ValueVectorOf<XMLCh*>*                  fLocationPairs;
346    NameIdPool<DTDElementDecl>*             fDTDElemNonDeclPool;
347    RefHash3KeysIdPool<SchemaElementDecl>*  fSchemaElemNonDeclPool;
348    unsigned int                            fElemCount;
349    RefHashTableOf<unsigned int>*           fAttDefRegistry;
350    RefHashTableOf<unsigned int>*           fUndeclaredAttrRegistry;
351    RefHash2KeysTableOf<unsigned int>*      fUndeclaredAttrRegistryNS;
352    PSVIAttributeList *                     fPSVIAttrList;
353    XSModel*                                fModel;
354    PSVIElement*                            fPSVIElement;
355    ValueStackOf<bool>*                     fErrorStack;
356    PSVIElemContext                         fPSVIElemContext;
357};
358
359inline const XMLCh* IGXMLScanner::getName() const
360{
361    return XMLUni::fgIGXMLScanner;
362}
363
364inline bool IGXMLScanner::toCheckIdentityConstraint()  const
365{
366    return fValidate && fIdentityConstraintChecking && fICHandler;
367}
368
369XERCES_CPP_NAMESPACE_END
370
371#endif
Note: See TracBrowser for help on using the repository browser.