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: DGXMLScanner.hpp,v $
|
---|
19 | * Revision 1.14 2004/09/08 13:56:13 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.13 2004/04/07 14:14:08 peiyongz
|
---|
23 | * make resolveSystemId virutal
|
---|
24 | *
|
---|
25 | * Revision 1.12 2004/01/29 11:46:30 cargilld
|
---|
26 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
27 | *
|
---|
28 | * Revision 1.11 2003/11/24 05:09:39 neilg
|
---|
29 | * implement new, statless, method for detecting duplicate attributes
|
---|
30 | *
|
---|
31 | * Revision 1.10 2003/10/22 20:22:30 knoaman
|
---|
32 | * Prepare for annotation support.
|
---|
33 | *
|
---|
34 | * Revision 1.9 2003/09/22 19:51:41 neilg
|
---|
35 | * 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.
|
---|
36 | *
|
---|
37 | * Revision 1.8 2003/07/24 09:19:09 gareth
|
---|
38 | * Patch for bug #20530 - Attributes which have the same expanded name are not considered duplicates. Patch by cargilld.
|
---|
39 | *
|
---|
40 | * Revision 1.7 2003/07/10 19:47:23 peiyongz
|
---|
41 | * Stateless Grammar: Initialize scanner with grammarResolver,
|
---|
42 | * creating grammar through grammarPool
|
---|
43 | *
|
---|
44 | * Revision 1.6 2003/05/22 02:10:51 knoaman
|
---|
45 | * Default the memory manager.
|
---|
46 | *
|
---|
47 | * Revision 1.5 2003/05/15 18:26:29 knoaman
|
---|
48 | * Partial implementation of the configurable memory manager.
|
---|
49 | *
|
---|
50 | * Revision 1.4 2003/03/07 18:08:58 tng
|
---|
51 | * Return a reference instead of void for operator=
|
---|
52 | *
|
---|
53 | * Revision 1.3 2003/01/15 15:49:49 knoaman
|
---|
54 | * Change constant declaration name to match its value.
|
---|
55 | *
|
---|
56 | * Revision 1.2 2003/01/13 18:29:41 knoaman
|
---|
57 | * Return proper scanner name.
|
---|
58 | *
|
---|
59 | * Revision 1.1 2002/12/09 15:45:13 knoaman
|
---|
60 | * Initial check-in.
|
---|
61 | *
|
---|
62 | */
|
---|
63 |
|
---|
64 |
|
---|
65 | #if !defined(DGXMLSCANNER_HPP)
|
---|
66 | #define DGXMLSCANNER_HPP
|
---|
67 |
|
---|
68 | #include <xercesc/internal/XMLScanner.hpp>
|
---|
69 | #include <xercesc/util/ValueVectorOf.hpp>
|
---|
70 | #include <xercesc/util/NameIdPool.hpp>
|
---|
71 | #include <xercesc/validators/common/Grammar.hpp>
|
---|
72 |
|
---|
73 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
74 |
|
---|
75 | class DTDElementDecl;
|
---|
76 | class DTDGrammar;
|
---|
77 | class DTDValidator;
|
---|
78 |
|
---|
79 | // This is an integrated scanner class, which does DTD/XML Schema grammar
|
---|
80 | // processing.
|
---|
81 | class XMLPARSER_EXPORT DGXMLScanner : public XMLScanner
|
---|
82 | {
|
---|
83 | public :
|
---|
84 | // -----------------------------------------------------------------------
|
---|
85 | // Constructors and Destructor
|
---|
86 | // -----------------------------------------------------------------------
|
---|
87 | DGXMLScanner
|
---|
88 | (
|
---|
89 | XMLValidator* const valToAdopt
|
---|
90 | , GrammarResolver* const grammarResolver
|
---|
91 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
92 | );
|
---|
93 | DGXMLScanner
|
---|
94 | (
|
---|
95 | XMLDocumentHandler* const docHandler
|
---|
96 | , DocTypeHandler* const docTypeHandler
|
---|
97 | , XMLEntityHandler* const entityHandler
|
---|
98 | , XMLErrorReporter* const errReporter
|
---|
99 | , XMLValidator* const valToAdopt
|
---|
100 | , GrammarResolver* const grammarResolver
|
---|
101 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
102 | );
|
---|
103 | virtual ~DGXMLScanner();
|
---|
104 |
|
---|
105 | // -----------------------------------------------------------------------
|
---|
106 | // XMLScanner public virtual methods
|
---|
107 | // -----------------------------------------------------------------------
|
---|
108 | virtual const XMLCh* getName() const;
|
---|
109 | virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
|
---|
110 | virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
|
---|
111 | virtual unsigned int resolveQName
|
---|
112 | (
|
---|
113 | const XMLCh* const qName
|
---|
114 | , XMLBuffer& prefixBufToFill
|
---|
115 | , const short mode
|
---|
116 | , int& prefixColonPos
|
---|
117 | );
|
---|
118 | virtual void scanDocument
|
---|
119 | (
|
---|
120 | const InputSource& src
|
---|
121 | );
|
---|
122 | virtual bool scanNext(XMLPScanToken& toFill);
|
---|
123 | virtual Grammar* loadGrammar
|
---|
124 | (
|
---|
125 | const InputSource& src
|
---|
126 | , const short grammarType
|
---|
127 | , const bool toCache = false
|
---|
128 | );
|
---|
129 |
|
---|
130 | private :
|
---|
131 | // -----------------------------------------------------------------------
|
---|
132 | // Unimplemented constructors and operators
|
---|
133 | // -----------------------------------------------------------------------
|
---|
134 | DGXMLScanner();
|
---|
135 | DGXMLScanner(const DGXMLScanner&);
|
---|
136 | DGXMLScanner& operator=(const DGXMLScanner&);
|
---|
137 |
|
---|
138 | // -----------------------------------------------------------------------
|
---|
139 | // XMLScanner virtual methods
|
---|
140 | // -----------------------------------------------------------------------
|
---|
141 | virtual void scanCDSection();
|
---|
142 | virtual void scanCharData(XMLBuffer& toToUse);
|
---|
143 | virtual EntityExpRes scanEntityRef
|
---|
144 | (
|
---|
145 | const bool inAttVal
|
---|
146 | , XMLCh& firstCh
|
---|
147 | , XMLCh& secondCh
|
---|
148 | , bool& escaped
|
---|
149 | );
|
---|
150 | virtual void scanDocTypeDecl();
|
---|
151 | virtual void scanReset(const InputSource& src);
|
---|
152 | virtual void sendCharData(XMLBuffer& toSend);
|
---|
153 | virtual InputSource* resolveSystemId(const XMLCh* const sysId);
|
---|
154 |
|
---|
155 | // -----------------------------------------------------------------------
|
---|
156 | // Private helper methods
|
---|
157 | // -----------------------------------------------------------------------
|
---|
158 | void commonInit();
|
---|
159 | void cleanUp();
|
---|
160 |
|
---|
161 | unsigned int buildAttList
|
---|
162 | (
|
---|
163 | const unsigned int attCount
|
---|
164 | , XMLElementDecl* elemDecl
|
---|
165 | , RefVectorOf<XMLAttr>& toFill
|
---|
166 | );
|
---|
167 | unsigned int resolvePrefix
|
---|
168 | (
|
---|
169 | const XMLCh* const prefix
|
---|
170 | , const ElemStack::MapModes mode
|
---|
171 | );
|
---|
172 | void updateNSMap
|
---|
173 | (
|
---|
174 | const XMLCh* const attrPrefix
|
---|
175 | , const XMLCh* const attrLocalName
|
---|
176 | , const XMLCh* const attrValue
|
---|
177 | );
|
---|
178 | void scanAttrListforNameSpaces(RefVectorOf<XMLAttr>* theAttrList, int attCount, XMLElementDecl* elemDecl);
|
---|
179 |
|
---|
180 | // -----------------------------------------------------------------------
|
---|
181 | // Private scanning methods
|
---|
182 | // -----------------------------------------------------------------------
|
---|
183 | bool scanAttValue
|
---|
184 | (
|
---|
185 | const XMLAttDef* const attDef
|
---|
186 | , const XMLCh *const attrName
|
---|
187 | , XMLBuffer& toFill
|
---|
188 | );
|
---|
189 | bool scanContent();
|
---|
190 | void scanEndTag(bool& gotData);
|
---|
191 | bool scanStartTag(bool& gotData);
|
---|
192 | bool scanStartTagNS(bool& gotData);
|
---|
193 |
|
---|
194 | // -----------------------------------------------------------------------
|
---|
195 | // Grammar preparsing methods
|
---|
196 | // -----------------------------------------------------------------------
|
---|
197 | Grammar* loadDTDGrammar(const InputSource& src, const bool toCache = false);
|
---|
198 |
|
---|
199 | // -----------------------------------------------------------------------
|
---|
200 | // Data members
|
---|
201 | //
|
---|
202 | // fRawAttrList
|
---|
203 | // During the initial scan of the attributes we can only do a raw
|
---|
204 | // scan for key/value pairs. So this vector is used to store them
|
---|
205 | // until they can be processed (and put into fAttrList.)
|
---|
206 | //
|
---|
207 | // fDTDValidator
|
---|
208 | // The DTD validator instance.
|
---|
209 | //
|
---|
210 | // fElemState
|
---|
211 | // fElemStateSize
|
---|
212 | // Stores an element next state from DFA content model - used for
|
---|
213 | // wildcard validation
|
---|
214 | //
|
---|
215 | // fDTDElemNonDeclPool
|
---|
216 | // registry of "faulted-in" DTD element decls
|
---|
217 | // fElemCount
|
---|
218 | // count of the number of start tags seen so far (starts at 1).
|
---|
219 | // Used for duplicate attribute detection/processing of required/defaulted attributes
|
---|
220 | // fAttDefRegistry
|
---|
221 | // mapping from XMLAttDef instances to the count of the last
|
---|
222 | // start tag where they were utilized.
|
---|
223 | // fUndeclaredAttrRegistry
|
---|
224 | // mapping of attr QNames to the count of the last start tag in which they occurred
|
---|
225 | //
|
---|
226 | // -----------------------------------------------------------------------
|
---|
227 | ValueVectorOf<XMLAttr*>* fAttrNSList;
|
---|
228 | DTDValidator* fDTDValidator;
|
---|
229 | DTDGrammar* fDTDGrammar;
|
---|
230 | NameIdPool<DTDElementDecl>* fDTDElemNonDeclPool;
|
---|
231 | unsigned int fElemCount;
|
---|
232 | RefHashTableOf<unsigned int>* fAttDefRegistry;
|
---|
233 | RefHashTableOf<unsigned int>* fUndeclaredAttrRegistry;
|
---|
234 | };
|
---|
235 |
|
---|
236 | inline const XMLCh* DGXMLScanner::getName() const
|
---|
237 | {
|
---|
238 | return XMLUni::fgDGXMLScanner;
|
---|
239 | }
|
---|
240 |
|
---|
241 |
|
---|
242 | XERCES_CPP_NAMESPACE_END
|
---|
243 |
|
---|
244 | #endif
|
---|