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