1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 2002 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Log: DGXMLScanner.hpp,v $
|
---|
59 | * Revision 1.12 2004/01/29 11:46:30 cargilld
|
---|
60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
61 | *
|
---|
62 | * Revision 1.11 2003/11/24 05:09:39 neilg
|
---|
63 | * implement new, statless, method for detecting duplicate attributes
|
---|
64 | *
|
---|
65 | * Revision 1.10 2003/10/22 20:22:30 knoaman
|
---|
66 | * Prepare for annotation support.
|
---|
67 | *
|
---|
68 | * Revision 1.9 2003/09/22 19:51:41 neilg
|
---|
69 | * 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.
|
---|
70 | *
|
---|
71 | * Revision 1.8 2003/07/24 09:19:09 gareth
|
---|
72 | * Patch for bug #20530 - Attributes which have the same expanded name are not considered duplicates. Patch by cargilld.
|
---|
73 | *
|
---|
74 | * Revision 1.7 2003/07/10 19:47:23 peiyongz
|
---|
75 | * Stateless Grammar: Initialize scanner with grammarResolver,
|
---|
76 | * creating grammar through grammarPool
|
---|
77 | *
|
---|
78 | * Revision 1.6 2003/05/22 02:10:51 knoaman
|
---|
79 | * Default the memory manager.
|
---|
80 | *
|
---|
81 | * Revision 1.5 2003/05/15 18:26:29 knoaman
|
---|
82 | * Partial implementation of the configurable memory manager.
|
---|
83 | *
|
---|
84 | * Revision 1.4 2003/03/07 18:08:58 tng
|
---|
85 | * Return a reference instead of void for operator=
|
---|
86 | *
|
---|
87 | * Revision 1.3 2003/01/15 15:49:49 knoaman
|
---|
88 | * Change constant declaration name to match its value.
|
---|
89 | *
|
---|
90 | * Revision 1.2 2003/01/13 18:29:41 knoaman
|
---|
91 | * Return proper scanner name.
|
---|
92 | *
|
---|
93 | * Revision 1.1 2002/12/09 15:45:13 knoaman
|
---|
94 | * Initial check-in.
|
---|
95 | *
|
---|
96 | */
|
---|
97 |
|
---|
98 |
|
---|
99 | #if !defined(DGXMLSCANNER_HPP)
|
---|
100 | #define DGXMLSCANNER_HPP
|
---|
101 |
|
---|
102 | #include <xercesc/internal/XMLScanner.hpp>
|
---|
103 | #include <xercesc/util/ValueVectorOf.hpp>
|
---|
104 | #include <xercesc/util/NameIdPool.hpp>
|
---|
105 | #include <xercesc/validators/common/Grammar.hpp>
|
---|
106 |
|
---|
107 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
108 |
|
---|
109 | class DTDElementDecl;
|
---|
110 | class DTDGrammar;
|
---|
111 | class DTDValidator;
|
---|
112 |
|
---|
113 | // This is an integrated scanner class, which does DTD/XML Schema grammar
|
---|
114 | // processing.
|
---|
115 | class XMLPARSER_EXPORT DGXMLScanner : public XMLScanner
|
---|
116 | {
|
---|
117 | public :
|
---|
118 | // -----------------------------------------------------------------------
|
---|
119 | // Constructors and Destructor
|
---|
120 | // -----------------------------------------------------------------------
|
---|
121 | DGXMLScanner
|
---|
122 | (
|
---|
123 | XMLValidator* const valToAdopt
|
---|
124 | , GrammarResolver* const grammarResolver
|
---|
125 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
126 | );
|
---|
127 | DGXMLScanner
|
---|
128 | (
|
---|
129 | XMLDocumentHandler* const docHandler
|
---|
130 | , DocTypeHandler* const docTypeHandler
|
---|
131 | , XMLEntityHandler* const entityHandler
|
---|
132 | , XMLErrorReporter* const errReporter
|
---|
133 | , XMLValidator* const valToAdopt
|
---|
134 | , GrammarResolver* const grammarResolver
|
---|
135 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
136 | );
|
---|
137 | virtual ~DGXMLScanner();
|
---|
138 |
|
---|
139 | // -----------------------------------------------------------------------
|
---|
140 | // XMLScanner public virtual methods
|
---|
141 | // -----------------------------------------------------------------------
|
---|
142 | virtual const XMLCh* getName() const;
|
---|
143 | virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
|
---|
144 | virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
|
---|
145 | virtual unsigned int resolveQName
|
---|
146 | (
|
---|
147 | const XMLCh* const qName
|
---|
148 | , XMLBuffer& prefixBufToFill
|
---|
149 | , const short mode
|
---|
150 | , int& prefixColonPos
|
---|
151 | );
|
---|
152 | virtual void scanDocument
|
---|
153 | (
|
---|
154 | const InputSource& src
|
---|
155 | );
|
---|
156 | virtual bool scanNext(XMLPScanToken& toFill);
|
---|
157 | virtual Grammar* loadGrammar
|
---|
158 | (
|
---|
159 | const InputSource& src
|
---|
160 | , const short grammarType
|
---|
161 | , const bool toCache = false
|
---|
162 | );
|
---|
163 |
|
---|
164 | private :
|
---|
165 | // -----------------------------------------------------------------------
|
---|
166 | // Unimplemented constructors and operators
|
---|
167 | // -----------------------------------------------------------------------
|
---|
168 | DGXMLScanner();
|
---|
169 | DGXMLScanner(const DGXMLScanner&);
|
---|
170 | DGXMLScanner& operator=(const DGXMLScanner&);
|
---|
171 |
|
---|
172 | // -----------------------------------------------------------------------
|
---|
173 | // XMLScanner virtual methods
|
---|
174 | // -----------------------------------------------------------------------
|
---|
175 | virtual void scanCDSection();
|
---|
176 | virtual void scanCharData(XMLBuffer& toToUse);
|
---|
177 | virtual EntityExpRes scanEntityRef
|
---|
178 | (
|
---|
179 | const bool inAttVal
|
---|
180 | , XMLCh& firstCh
|
---|
181 | , XMLCh& secondCh
|
---|
182 | , bool& escaped
|
---|
183 | );
|
---|
184 | virtual void scanDocTypeDecl();
|
---|
185 | virtual void scanReset(const InputSource& src);
|
---|
186 | virtual void sendCharData(XMLBuffer& toSend);
|
---|
187 |
|
---|
188 | // -----------------------------------------------------------------------
|
---|
189 | // Private helper methods
|
---|
190 | // -----------------------------------------------------------------------
|
---|
191 | void commonInit();
|
---|
192 | void cleanUp();
|
---|
193 | InputSource* resolveSystemId(const XMLCh* const sysId); // return owned by caller
|
---|
194 | unsigned int buildAttList
|
---|
195 | (
|
---|
196 | const unsigned int attCount
|
---|
197 | , XMLElementDecl* elemDecl
|
---|
198 | , RefVectorOf<XMLAttr>& toFill
|
---|
199 | );
|
---|
200 | unsigned int resolvePrefix
|
---|
201 | (
|
---|
202 | const XMLCh* const prefix
|
---|
203 | , const ElemStack::MapModes mode
|
---|
204 | );
|
---|
205 | void updateNSMap
|
---|
206 | (
|
---|
207 | const XMLCh* const attrPrefix
|
---|
208 | , const XMLCh* const attrLocalName
|
---|
209 | , const XMLCh* const attrValue
|
---|
210 | );
|
---|
211 | void scanAttrListforNameSpaces(RefVectorOf<XMLAttr>* theAttrList, int attCount, XMLElementDecl* elemDecl);
|
---|
212 |
|
---|
213 | // -----------------------------------------------------------------------
|
---|
214 | // Private scanning methods
|
---|
215 | // -----------------------------------------------------------------------
|
---|
216 | bool scanAttValue
|
---|
217 | (
|
---|
218 | const XMLAttDef* const attDef
|
---|
219 | , const XMLCh *const attrName
|
---|
220 | , XMLBuffer& toFill
|
---|
221 | );
|
---|
222 | bool scanContent();
|
---|
223 | void scanEndTag(bool& gotData);
|
---|
224 | bool scanStartTag(bool& gotData);
|
---|
225 | bool scanStartTagNS(bool& gotData);
|
---|
226 |
|
---|
227 | // -----------------------------------------------------------------------
|
---|
228 | // Grammar preparsing methods
|
---|
229 | // -----------------------------------------------------------------------
|
---|
230 | Grammar* loadDTDGrammar(const InputSource& src, const bool toCache = false);
|
---|
231 |
|
---|
232 | // -----------------------------------------------------------------------
|
---|
233 | // Data members
|
---|
234 | //
|
---|
235 | // fRawAttrList
|
---|
236 | // During the initial scan of the attributes we can only do a raw
|
---|
237 | // scan for key/value pairs. So this vector is used to store them
|
---|
238 | // until they can be processed (and put into fAttrList.)
|
---|
239 | //
|
---|
240 | // fDTDValidator
|
---|
241 | // The DTD validator instance.
|
---|
242 | //
|
---|
243 | // fElemState
|
---|
244 | // fElemStateSize
|
---|
245 | // Stores an element next state from DFA content model - used for
|
---|
246 | // wildcard validation
|
---|
247 | //
|
---|
248 | // fDTDElemNonDeclPool
|
---|
249 | // registry of "faulted-in" DTD element decls
|
---|
250 | // fElemCount
|
---|
251 | // count of the number of start tags seen so far (starts at 1).
|
---|
252 | // Used for duplicate attribute detection/processing of required/defaulted attributes
|
---|
253 | // fAttDefRegistry
|
---|
254 | // mapping from XMLAttDef instances to the count of the last
|
---|
255 | // start tag where they were utilized.
|
---|
256 | // fUndeclaredAttrRegistry
|
---|
257 | // mapping of attr QNames to the count of the last start tag in which they occurred
|
---|
258 | //
|
---|
259 | // -----------------------------------------------------------------------
|
---|
260 | ValueVectorOf<XMLAttr*>* fAttrNSList;
|
---|
261 | DTDValidator* fDTDValidator;
|
---|
262 | DTDGrammar* fDTDGrammar;
|
---|
263 | NameIdPool<DTDElementDecl>* fDTDElemNonDeclPool;
|
---|
264 | unsigned int fElemCount;
|
---|
265 | RefHashTableOf<unsigned int>* fAttDefRegistry;
|
---|
266 | RefHashTableOf<unsigned int>* fUndeclaredAttrRegistry;
|
---|
267 | };
|
---|
268 |
|
---|
269 | inline const XMLCh* DGXMLScanner::getName() const
|
---|
270 | {
|
---|
271 | return XMLUni::fgDGXMLScanner;
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | XERCES_CPP_NAMESPACE_END
|
---|
276 |
|
---|
277 | #endif
|
---|