/src/xerces-c/src/xercesc/parsers/SAXParser.cpp
Line | Count | Source (jump to first uncovered 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: SAXParser.cpp 882548 2009-11-20 13:44:14Z borisk $ |
20 | | */ |
21 | | |
22 | | |
23 | | // --------------------------------------------------------------------------- |
24 | | // Includes |
25 | | // --------------------------------------------------------------------------- |
26 | | #include <xercesc/parsers/SAXParser.hpp> |
27 | | #include <xercesc/internal/XMLScannerResolver.hpp> |
28 | | #include <xercesc/framework/XMLValidator.hpp> |
29 | | #include <xercesc/util/IOException.hpp> |
30 | | #include <xercesc/sax/DocumentHandler.hpp> |
31 | | #include <xercesc/sax/DTDHandler.hpp> |
32 | | #include <xercesc/sax/ErrorHandler.hpp> |
33 | | #include <xercesc/sax/EntityResolver.hpp> |
34 | | #include <xercesc/sax/SAXParseException.hpp> |
35 | | #include <xercesc/validators/common/GrammarResolver.hpp> |
36 | | #include <xercesc/framework/XMLGrammarPool.hpp> |
37 | | #include <xercesc/framework/XMLSchemaDescription.hpp> |
38 | | #include <xercesc/util/Janitor.hpp> |
39 | | #include <xercesc/util/OutOfMemoryException.hpp> |
40 | | #include <xercesc/util/XMLEntityResolver.hpp> |
41 | | #include <string.h> |
42 | | |
43 | | XERCES_CPP_NAMESPACE_BEGIN |
44 | | |
45 | | |
46 | | // --------------------------------------------------------------------------- |
47 | | // SAXParser: Constructors and Destructor |
48 | | // --------------------------------------------------------------------------- |
49 | | |
50 | | |
51 | | typedef JanitorMemFunCall<SAXParser> CleanupType; |
52 | | typedef JanitorMemFunCall<SAXParser> ResetInProgressType; |
53 | | |
54 | | |
55 | | SAXParser::SAXParser( XMLValidator* const valToAdopt |
56 | | , MemoryManager* const manager |
57 | | , XMLGrammarPool* const gramPool): |
58 | | |
59 | | fParseInProgress(false) |
60 | | , fElemDepth(0) |
61 | | , fAdvDHCount(0) |
62 | | , fAdvDHListSize(32) |
63 | | , fDocHandler(0) |
64 | | , fDTDHandler(0) |
65 | | , fEntityResolver(0) |
66 | | , fXMLEntityResolver(0) |
67 | | , fErrorHandler(0) |
68 | | , fPSVIHandler(0) |
69 | | , fAdvDHList(0) |
70 | | , fScanner(0) |
71 | | , fGrammarResolver(0) |
72 | | , fURIStringPool(0) |
73 | | , fValidator(valToAdopt) |
74 | | , fMemoryManager(manager) |
75 | | , fGrammarPool(gramPool) |
76 | | , fElemQNameBuf(1023, manager) |
77 | 18.1k | { |
78 | 18.1k | CleanupType cleanup(this, &SAXParser::cleanUp); |
79 | | |
80 | 18.1k | try |
81 | 18.1k | { |
82 | 18.1k | initialize(); |
83 | 18.1k | } |
84 | 18.1k | catch(const OutOfMemoryException&) |
85 | 18.1k | { |
86 | | // Don't cleanup when out of memory, since executing the |
87 | | // code can cause problems. |
88 | 0 | cleanup.release(); |
89 | |
|
90 | 0 | throw; |
91 | 0 | } |
92 | | |
93 | 18.1k | cleanup.release(); |
94 | 18.1k | } |
95 | | |
96 | | |
97 | | SAXParser::~SAXParser() |
98 | 18.1k | { |
99 | 18.1k | cleanUp(); |
100 | 18.1k | } |
101 | | |
102 | | // --------------------------------------------------------------------------- |
103 | | // SAXParser: Initialize/CleanUp methods |
104 | | // --------------------------------------------------------------------------- |
105 | | void SAXParser::initialize() |
106 | 18.1k | { |
107 | | // Create grammar resolver and string pool to pass to scanner |
108 | 18.1k | fGrammarResolver = new (fMemoryManager) GrammarResolver(fGrammarPool, fMemoryManager); |
109 | 18.1k | fURIStringPool = fGrammarResolver->getStringPool(); |
110 | | |
111 | | // Create our scanner and tell it what validator to use |
112 | 18.1k | fScanner = XMLScannerResolver::getDefaultScanner(fValidator, fGrammarResolver, fMemoryManager); |
113 | 18.1k | fScanner->setURIStringPool(fURIStringPool); |
114 | | |
115 | | // Create the initial advanced handler list array and zero it out |
116 | 18.1k | fAdvDHList = (XMLDocumentHandler**) fMemoryManager->allocate |
117 | 18.1k | ( |
118 | 18.1k | fAdvDHListSize * sizeof(XMLDocumentHandler*) |
119 | 18.1k | );//new XMLDocumentHandler*[fAdvDHListSize]; |
120 | 18.1k | memset(fAdvDHList, 0, sizeof(void*) * fAdvDHListSize); |
121 | 18.1k | } |
122 | | |
123 | | void SAXParser::cleanUp() |
124 | 18.1k | { |
125 | 18.1k | fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList; |
126 | 18.1k | delete fScanner; |
127 | 18.1k | delete fGrammarResolver; |
128 | | // grammar pool must do this |
129 | | //delete fURIStringPool; |
130 | | |
131 | 18.1k | if (fValidator) |
132 | 0 | delete fValidator; |
133 | 18.1k | } |
134 | | |
135 | | |
136 | | // --------------------------------------------------------------------------- |
137 | | // SAXParser: Advanced document handler list maintenance methods |
138 | | // --------------------------------------------------------------------------- |
139 | | void SAXParser::installAdvDocHandler(XMLDocumentHandler* const toInstall) |
140 | 0 | { |
141 | | // See if we need to expand and do so now if needed |
142 | 0 | if (fAdvDHCount == fAdvDHListSize) |
143 | 0 | { |
144 | | // Calc a new size and allocate the new temp buffer |
145 | 0 | const XMLSize_t newSize = (XMLSize_t)(fAdvDHListSize * 1.5); |
146 | 0 | XMLDocumentHandler** newList = (XMLDocumentHandler**) fMemoryManager->allocate |
147 | 0 | ( |
148 | 0 | newSize * sizeof(XMLDocumentHandler*) |
149 | 0 | );//new XMLDocumentHandler*[newSize]; |
150 | | |
151 | | // Copy over the old data to the new list and zero out the rest |
152 | 0 | memcpy(newList, fAdvDHList, sizeof(void*) * fAdvDHListSize); |
153 | 0 | memset |
154 | 0 | ( |
155 | 0 | &newList[fAdvDHListSize] |
156 | 0 | , 0 |
157 | 0 | , sizeof(void*) * (newSize - fAdvDHListSize) |
158 | 0 | ); |
159 | | |
160 | | // And now clean up the old array and store the new stuff |
161 | 0 | fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList; |
162 | 0 | fAdvDHList = newList; |
163 | 0 | fAdvDHListSize = newSize; |
164 | 0 | } |
165 | | |
166 | | // Add this new guy into the empty slot |
167 | 0 | fAdvDHList[fAdvDHCount++] = toInstall; |
168 | | |
169 | | // |
170 | | // Install ourself as the document handler with the scanner. We might |
171 | | // already be, but its not worth checking, just do it. |
172 | | // |
173 | 0 | fScanner->setDocHandler(this); |
174 | 0 | } |
175 | | |
176 | | |
177 | | bool SAXParser::removeAdvDocHandler(XMLDocumentHandler* const toRemove) |
178 | 0 | { |
179 | | // If our count is zero, can't be any installed |
180 | 0 | if (!fAdvDHCount) |
181 | 0 | return false; |
182 | | |
183 | | // |
184 | | // Search the array until we find this handler. If we find a null entry |
185 | | // first, we can stop there before the list is kept contiguous. |
186 | | // |
187 | 0 | XMLSize_t index; |
188 | 0 | for (index = 0; index < fAdvDHCount; index++) |
189 | 0 | { |
190 | | // |
191 | | // We found it. We have to keep the list contiguous, so we have to |
192 | | // copy down any used elements after this one. |
193 | | // |
194 | 0 | if (fAdvDHList[index] == toRemove) |
195 | 0 | { |
196 | | // |
197 | | // Optimize if only one entry (pretty common). Otherwise, we |
198 | | // have to copy them down to compact them. |
199 | | // |
200 | 0 | if (fAdvDHCount > 1) |
201 | 0 | { |
202 | 0 | index++; |
203 | 0 | while (index < fAdvDHCount) |
204 | 0 | fAdvDHList[index - 1] = fAdvDHList[index]; |
205 | 0 | } |
206 | | |
207 | | // Bump down the count and zero out the last one |
208 | 0 | fAdvDHCount--; |
209 | 0 | fAdvDHList[fAdvDHCount] = 0; |
210 | | |
211 | | // |
212 | | // If this leaves us with no advanced handlers and there is |
213 | | // no SAX doc handler installed on us, then remove us from the |
214 | | // scanner as the document handler. |
215 | | // |
216 | 0 | if (!fAdvDHCount && !fDocHandler) |
217 | 0 | fScanner->setDocHandler(0); |
218 | |
|
219 | 0 | return true; |
220 | 0 | } |
221 | 0 | } |
222 | | |
223 | | // Never found it |
224 | 0 | return false; |
225 | 0 | } |
226 | | |
227 | | |
228 | | // --------------------------------------------------------------------------- |
229 | | // SAXParser: Getter methods |
230 | | // --------------------------------------------------------------------------- |
231 | | const XMLValidator& SAXParser::getValidator() const |
232 | 0 | { |
233 | 0 | return *fScanner->getValidator(); |
234 | 0 | } |
235 | | |
236 | | |
237 | | bool SAXParser::getDoNamespaces() const |
238 | 0 | { |
239 | 0 | return fScanner->getDoNamespaces(); |
240 | 0 | } |
241 | | |
242 | | bool SAXParser::getGenerateSyntheticAnnotations() const |
243 | 0 | { |
244 | 0 | return fScanner->getGenerateSyntheticAnnotations(); |
245 | 0 | } |
246 | | |
247 | | bool SAXParser::getValidateAnnotations() const |
248 | 0 | { |
249 | 0 | return fScanner->getValidateAnnotations(); |
250 | 0 | } |
251 | | |
252 | | bool SAXParser::getExitOnFirstFatalError() const |
253 | 0 | { |
254 | 0 | return fScanner->getExitOnFirstFatal(); |
255 | 0 | } |
256 | | |
257 | | bool SAXParser::getValidationConstraintFatal() const |
258 | 0 | { |
259 | 0 | return fScanner->getValidationConstraintFatal(); |
260 | 0 | } |
261 | | |
262 | | |
263 | | SAXParser::ValSchemes SAXParser::getValidationScheme() const |
264 | 0 | { |
265 | 0 | const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); |
266 | |
|
267 | 0 | if (scheme == XMLScanner::Val_Always) |
268 | 0 | return Val_Always; |
269 | 0 | else if (scheme == XMLScanner::Val_Never) |
270 | 0 | return Val_Never; |
271 | | |
272 | 0 | return Val_Auto; |
273 | 0 | } |
274 | | |
275 | | bool SAXParser::getDoSchema() const |
276 | 0 | { |
277 | 0 | return fScanner->getDoSchema(); |
278 | 0 | } |
279 | | |
280 | | bool SAXParser::getValidationSchemaFullChecking() const |
281 | 0 | { |
282 | 0 | return fScanner->getValidationSchemaFullChecking(); |
283 | 0 | } |
284 | | |
285 | | bool SAXParser::getIdentityConstraintChecking() const |
286 | 0 | { |
287 | 0 | return fScanner->getIdentityConstraintChecking(); |
288 | 0 | } |
289 | | |
290 | | int SAXParser::getErrorCount() const |
291 | 0 | { |
292 | 0 | return fScanner->getErrorCount(); |
293 | 0 | } |
294 | | |
295 | | XMLCh* SAXParser::getExternalSchemaLocation() const |
296 | 0 | { |
297 | 0 | return fScanner->getExternalSchemaLocation(); |
298 | 0 | } |
299 | | |
300 | | XMLCh* SAXParser::getExternalNoNamespaceSchemaLocation() const |
301 | 0 | { |
302 | 0 | return fScanner->getExternalNoNamespaceSchemaLocation(); |
303 | 0 | } |
304 | | |
305 | | SecurityManager* SAXParser::getSecurityManager() const |
306 | 0 | { |
307 | 0 | return fScanner->getSecurityManager(); |
308 | 0 | } |
309 | | |
310 | | XMLSize_t SAXParser::getLowWaterMark() const |
311 | 0 | { |
312 | 0 | return fScanner->getLowWaterMark(); |
313 | 0 | } |
314 | | |
315 | | bool SAXParser::getLoadExternalDTD() const |
316 | 0 | { |
317 | 0 | return fScanner->getLoadExternalDTD(); |
318 | 0 | } |
319 | | |
320 | | bool SAXParser::getLoadSchema() const |
321 | 0 | { |
322 | 0 | return fScanner->getLoadSchema(); |
323 | 0 | } |
324 | | |
325 | | bool SAXParser::isCachingGrammarFromParse() const |
326 | 0 | { |
327 | 0 | return fScanner->isCachingGrammarFromParse(); |
328 | 0 | } |
329 | | |
330 | | bool SAXParser::isUsingCachedGrammarInParse() const |
331 | 0 | { |
332 | 0 | return fScanner->isUsingCachedGrammarInParse(); |
333 | 0 | } |
334 | | |
335 | | bool SAXParser::getCalculateSrcOfs() const |
336 | 0 | { |
337 | 0 | return fScanner->getCalculateSrcOfs(); |
338 | 0 | } |
339 | | |
340 | | bool SAXParser::getStandardUriConformant() const |
341 | 0 | { |
342 | 0 | return fScanner->getStandardUriConformant(); |
343 | 0 | } |
344 | | |
345 | | Grammar* SAXParser::getGrammar(const XMLCh* const nameSpaceKey) |
346 | 0 | { |
347 | 0 | return fGrammarResolver->getGrammar(nameSpaceKey); |
348 | 0 | } |
349 | | |
350 | | Grammar* SAXParser::getRootGrammar() |
351 | 0 | { |
352 | 0 | return fScanner->getRootGrammar(); |
353 | 0 | } |
354 | | |
355 | | const XMLCh* SAXParser::getURIText(unsigned int uriId) const |
356 | 0 | { |
357 | 0 | return fScanner->getURIText(uriId); |
358 | 0 | } |
359 | | |
360 | | XMLFilePos SAXParser::getSrcOffset() const |
361 | 0 | { |
362 | 0 | return fScanner->getSrcOffset(); |
363 | 0 | } |
364 | | |
365 | | bool SAXParser::getIgnoreCachedDTD() const |
366 | 0 | { |
367 | 0 | return fScanner->getIgnoreCachedDTD(); |
368 | 0 | } |
369 | | |
370 | | bool SAXParser::getIgnoreAnnotations() const |
371 | 0 | { |
372 | 0 | return fScanner->getIgnoreAnnotations(); |
373 | 0 | } |
374 | | |
375 | | bool SAXParser::getDisableDefaultEntityResolution() const |
376 | 0 | { |
377 | 0 | return fScanner->getDisableDefaultEntityResolution(); |
378 | 0 | } |
379 | | |
380 | | bool SAXParser::getSkipDTDValidation() const |
381 | 0 | { |
382 | 0 | return fScanner->getSkipDTDValidation(); |
383 | 0 | } |
384 | | |
385 | | bool SAXParser::getHandleMultipleImports() const |
386 | 0 | { |
387 | 0 | return fScanner->getHandleMultipleImports(); |
388 | 0 | } |
389 | | |
390 | | // --------------------------------------------------------------------------- |
391 | | // SAXParser: Setter methods |
392 | | // --------------------------------------------------------------------------- |
393 | | void SAXParser::setDoNamespaces(const bool newState) |
394 | 18.1k | { |
395 | 18.1k | fScanner->setDoNamespaces(newState); |
396 | 18.1k | } |
397 | | |
398 | | void SAXParser::setGenerateSyntheticAnnotations(const bool newState) |
399 | 0 | { |
400 | 0 | fScanner->setGenerateSyntheticAnnotations(newState); |
401 | 0 | } |
402 | | |
403 | | void SAXParser::setValidateAnnotations(const bool newState) |
404 | 0 | { |
405 | 0 | fScanner->setValidateAnnotations(newState); |
406 | 0 | } |
407 | | |
408 | | void SAXParser::setExitOnFirstFatalError(const bool newState) |
409 | 0 | { |
410 | 0 | fScanner->setExitOnFirstFatal(newState); |
411 | 0 | } |
412 | | |
413 | | |
414 | | void SAXParser::setValidationConstraintFatal(const bool newState) |
415 | 0 | { |
416 | 0 | fScanner->setValidationConstraintFatal(newState); |
417 | 0 | } |
418 | | |
419 | | |
420 | | void SAXParser::setValidationScheme(const ValSchemes newScheme) |
421 | 18.1k | { |
422 | 18.1k | if (newScheme == Val_Never) |
423 | 0 | fScanner->setValidationScheme(XMLScanner::Val_Never); |
424 | 18.1k | else if (newScheme == Val_Always) |
425 | 0 | fScanner->setValidationScheme(XMLScanner::Val_Always); |
426 | 18.1k | else |
427 | 18.1k | fScanner->setValidationScheme(XMLScanner::Val_Auto); |
428 | 18.1k | } |
429 | | |
430 | | void SAXParser::setDoSchema(const bool newState) |
431 | 18.1k | { |
432 | 18.1k | fScanner->setDoSchema(newState); |
433 | 18.1k | } |
434 | | |
435 | | void SAXParser::setValidationSchemaFullChecking(const bool schemaFullChecking) |
436 | 18.1k | { |
437 | 18.1k | fScanner->setValidationSchemaFullChecking(schemaFullChecking); |
438 | 18.1k | } |
439 | | |
440 | | void SAXParser::setIdentityConstraintChecking(const bool identityConstraintChecking) |
441 | 0 | { |
442 | 0 | fScanner->setIdentityConstraintChecking(identityConstraintChecking); |
443 | 0 | } |
444 | | |
445 | | void SAXParser::setExternalSchemaLocation(const XMLCh* const schemaLocation) |
446 | 0 | { |
447 | 0 | fScanner->setExternalSchemaLocation(schemaLocation); |
448 | 0 | } |
449 | | void SAXParser::setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation) |
450 | 0 | { |
451 | 0 | fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); |
452 | 0 | } |
453 | | |
454 | | void SAXParser::setExternalSchemaLocation(const char* const schemaLocation) |
455 | 0 | { |
456 | 0 | fScanner->setExternalSchemaLocation(schemaLocation); |
457 | 0 | } |
458 | | void SAXParser::setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation) |
459 | 0 | { |
460 | 0 | fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); |
461 | 0 | } |
462 | | |
463 | | void SAXParser::setSecurityManager(SecurityManager* const securityManager) |
464 | 0 | { |
465 | | // since this could impact various components, don't permit it to change |
466 | | // during a parse |
467 | 0 | if (fParseInProgress) |
468 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
469 | | |
470 | 0 | fScanner->setSecurityManager(securityManager); |
471 | 0 | } |
472 | | |
473 | | void SAXParser::setLowWaterMark(XMLSize_t lwm) |
474 | 0 | { |
475 | 0 | fScanner->setLowWaterMark(lwm); |
476 | 0 | } |
477 | | |
478 | | void SAXParser::setLoadExternalDTD(const bool newState) |
479 | 0 | { |
480 | 0 | fScanner->setLoadExternalDTD(newState); |
481 | 0 | } |
482 | | |
483 | | void SAXParser::setLoadSchema(const bool newState) |
484 | 0 | { |
485 | 0 | fScanner->setLoadSchema(newState); |
486 | 0 | } |
487 | | |
488 | | void SAXParser::cacheGrammarFromParse(const bool newState) |
489 | 0 | { |
490 | 0 | fScanner->cacheGrammarFromParse(newState); |
491 | |
|
492 | 0 | if (newState) |
493 | 0 | fScanner->useCachedGrammarInParse(newState); |
494 | 0 | } |
495 | | |
496 | | void SAXParser::useCachedGrammarInParse(const bool newState) |
497 | 0 | { |
498 | 0 | if (newState || !fScanner->isCachingGrammarFromParse()) |
499 | 0 | fScanner->useCachedGrammarInParse(newState); |
500 | 0 | } |
501 | | |
502 | | void SAXParser::setCalculateSrcOfs(const bool newState) |
503 | 0 | { |
504 | 0 | fScanner->setCalculateSrcOfs(newState); |
505 | 0 | } |
506 | | |
507 | | void SAXParser::setStandardUriConformant(const bool newState) |
508 | 0 | { |
509 | 0 | fScanner->setStandardUriConformant(newState); |
510 | 0 | } |
511 | | |
512 | | void SAXParser::useScanner(const XMLCh* const scannerName) |
513 | 0 | { |
514 | 0 | XMLScanner* tempScanner = XMLScannerResolver::resolveScanner |
515 | 0 | ( |
516 | 0 | scannerName |
517 | 0 | , fValidator |
518 | 0 | , fGrammarResolver |
519 | 0 | , fMemoryManager |
520 | 0 | ); |
521 | |
|
522 | 0 | if (tempScanner) { |
523 | |
|
524 | 0 | tempScanner->setParseSettings(fScanner); |
525 | 0 | tempScanner->setURIStringPool(fURIStringPool); |
526 | 0 | delete fScanner; |
527 | 0 | fScanner = tempScanner; |
528 | 0 | } |
529 | 0 | } |
530 | | |
531 | | void SAXParser::setInputBufferSize(const XMLSize_t bufferSize) |
532 | 0 | { |
533 | 0 | fScanner->setInputBufferSize(bufferSize); |
534 | 0 | } |
535 | | |
536 | | void SAXParser::setIgnoreCachedDTD(const bool newValue) |
537 | 0 | { |
538 | 0 | fScanner->setIgnoredCachedDTD(newValue); |
539 | 0 | } |
540 | | |
541 | | void SAXParser::setIgnoreAnnotations(const bool newValue) |
542 | 0 | { |
543 | 0 | fScanner->setIgnoreAnnotations(newValue); |
544 | 0 | } |
545 | | |
546 | | void SAXParser::setDisableDefaultEntityResolution(const bool newValue) |
547 | 0 | { |
548 | 0 | fScanner->setDisableDefaultEntityResolution(newValue); |
549 | 0 | } |
550 | | |
551 | | void SAXParser::setSkipDTDValidation(const bool newValue) |
552 | 0 | { |
553 | 0 | fScanner->setSkipDTDValidation(newValue); |
554 | 0 | } |
555 | | |
556 | | void SAXParser::setHandleMultipleImports(const bool newValue) |
557 | 18.1k | { |
558 | 18.1k | fScanner->setHandleMultipleImports(newValue); |
559 | 18.1k | } |
560 | | |
561 | | // --------------------------------------------------------------------------- |
562 | | // SAXParser: Overrides of the SAX Parser interface |
563 | | // --------------------------------------------------------------------------- |
564 | | void SAXParser::parse(const InputSource& source) |
565 | 18.1k | { |
566 | | // Avoid multiple entrance |
567 | 18.1k | if (fParseInProgress) |
568 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
569 | | |
570 | 18.1k | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
571 | | |
572 | 18.1k | try |
573 | 18.1k | { |
574 | 18.1k | fParseInProgress = true; |
575 | 18.1k | fScanner->scanDocument(source); |
576 | 18.1k | } |
577 | 18.1k | catch(const OutOfMemoryException&) |
578 | 18.1k | { |
579 | 0 | resetInProgress.release(); |
580 | |
|
581 | 0 | throw; |
582 | 0 | } |
583 | 18.1k | } |
584 | | |
585 | | void SAXParser::parse(const XMLCh* const systemId) |
586 | 0 | { |
587 | | // Avoid multiple entrance |
588 | 0 | if (fParseInProgress) |
589 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
590 | | |
591 | 0 | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
592 | |
|
593 | 0 | try |
594 | 0 | { |
595 | 0 | fParseInProgress = true; |
596 | 0 | fScanner->scanDocument(systemId); |
597 | 0 | } |
598 | 0 | catch(const OutOfMemoryException&) |
599 | 0 | { |
600 | 0 | resetInProgress.release(); |
601 | |
|
602 | 0 | throw; |
603 | 0 | } |
604 | 0 | } |
605 | | |
606 | | void SAXParser::parse(const char* const systemId) |
607 | 0 | { |
608 | | // Avoid multiple entrance |
609 | 0 | if (fParseInProgress) |
610 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
611 | | |
612 | 0 | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
613 | |
|
614 | 0 | try |
615 | 0 | { |
616 | 0 | fParseInProgress = true; |
617 | 0 | fScanner->scanDocument(systemId); |
618 | 0 | } |
619 | 0 | catch(const OutOfMemoryException&) |
620 | 0 | { |
621 | 0 | resetInProgress.release(); |
622 | |
|
623 | 0 | throw; |
624 | 0 | } |
625 | 0 | } |
626 | | |
627 | | void SAXParser::setDocumentHandler(DocumentHandler* const handler) |
628 | 0 | { |
629 | 0 | fDocHandler = handler; |
630 | 0 | if (fDocHandler) |
631 | 0 | { |
632 | | // |
633 | | // Make sure we are set as the document handler with the scanner. |
634 | | // We may already be (if advanced handlers are installed), but its |
635 | | // not worthing checking, just do it. |
636 | | // |
637 | 0 | fScanner->setDocHandler(this); |
638 | 0 | } |
639 | 0 | else |
640 | 0 | { |
641 | | // |
642 | | // If we don't have any advanced handlers either, then deinstall us |
643 | | // from the scanner because we don't need document events anymore. |
644 | | // |
645 | 0 | if (!fAdvDHCount) |
646 | 0 | fScanner->setDocHandler(0); |
647 | 0 | } |
648 | 0 | } |
649 | | |
650 | | |
651 | | void SAXParser::setDTDHandler(DTDHandler* const handler) |
652 | 0 | { |
653 | 0 | fDTDHandler = handler; |
654 | 0 | if (fDTDHandler) |
655 | 0 | fScanner->setDocTypeHandler(this); |
656 | 0 | else |
657 | 0 | fScanner->setDocTypeHandler(0); |
658 | 0 | } |
659 | | |
660 | | |
661 | | void SAXParser::setErrorHandler(ErrorHandler* const handler) |
662 | 0 | { |
663 | | // |
664 | | // Store the handler. Then either install or deinstall us as the |
665 | | // error reporter on the scanner. |
666 | | // |
667 | 0 | fErrorHandler = handler; |
668 | 0 | if (fErrorHandler) { |
669 | 0 | fScanner->setErrorReporter(this); |
670 | 0 | fScanner->setErrorHandler(fErrorHandler); |
671 | 0 | } |
672 | 0 | else { |
673 | 0 | fScanner->setErrorReporter(0); |
674 | 0 | fScanner->setErrorHandler(0); |
675 | 0 | } |
676 | 0 | } |
677 | | |
678 | | |
679 | | void SAXParser::setPSVIHandler(PSVIHandler* const handler) |
680 | 0 | { |
681 | 0 | fPSVIHandler = handler; |
682 | 0 | if (fPSVIHandler) { |
683 | 0 | fScanner->setPSVIHandler(fPSVIHandler); |
684 | 0 | } |
685 | 0 | else { |
686 | 0 | fScanner->setPSVIHandler(0); |
687 | 0 | } |
688 | 0 | } |
689 | | |
690 | | void SAXParser::setEntityResolver(EntityResolver* const resolver) |
691 | 0 | { |
692 | 0 | fEntityResolver = resolver; |
693 | 0 | if (fEntityResolver) { |
694 | 0 | fScanner->setEntityHandler(this); |
695 | 0 | fXMLEntityResolver = 0; |
696 | 0 | } |
697 | 0 | else { |
698 | 0 | fScanner->setEntityHandler(0); |
699 | 0 | } |
700 | 0 | } |
701 | | |
702 | | void SAXParser::setXMLEntityResolver(XMLEntityResolver* const resolver) |
703 | 0 | { |
704 | 0 | fXMLEntityResolver = resolver; |
705 | 0 | if (fXMLEntityResolver) { |
706 | 0 | fScanner->setEntityHandler(this); |
707 | 0 | fEntityResolver = 0; |
708 | 0 | } |
709 | 0 | else { |
710 | 0 | fScanner->setEntityHandler(0); |
711 | 0 | } |
712 | 0 | } |
713 | | |
714 | | // --------------------------------------------------------------------------- |
715 | | // SAXParser: Progressive parse methods |
716 | | // --------------------------------------------------------------------------- |
717 | | bool SAXParser::parseFirst( const XMLCh* const systemId |
718 | | , XMLPScanToken& toFill) |
719 | 0 | { |
720 | | // |
721 | | // Avoid multiple entrance. We cannot enter here while a regular parse |
722 | | // is in progress. |
723 | | // |
724 | 0 | if (fParseInProgress) |
725 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
726 | | |
727 | 0 | return fScanner->scanFirst(systemId, toFill); |
728 | 0 | } |
729 | | |
730 | | bool SAXParser::parseFirst( const char* const systemId |
731 | | , XMLPScanToken& toFill) |
732 | 0 | { |
733 | | // |
734 | | // Avoid multiple entrance. We cannot enter here while a regular parse |
735 | | // is in progress. |
736 | | // |
737 | 0 | if (fParseInProgress) |
738 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
739 | | |
740 | 0 | return fScanner->scanFirst(systemId, toFill); |
741 | 0 | } |
742 | | |
743 | | bool SAXParser::parseFirst( const InputSource& source |
744 | | , XMLPScanToken& toFill) |
745 | 0 | { |
746 | | // |
747 | | // Avoid multiple entrance. We cannot enter here while a regular parse |
748 | | // is in progress. |
749 | | // |
750 | 0 | if (fParseInProgress) |
751 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
752 | | |
753 | 0 | return fScanner->scanFirst(source, toFill); |
754 | 0 | } |
755 | | |
756 | | bool SAXParser::parseNext(XMLPScanToken& token) |
757 | 0 | { |
758 | 0 | return fScanner->scanNext(token); |
759 | 0 | } |
760 | | |
761 | | void SAXParser::parseReset(XMLPScanToken& token) |
762 | 0 | { |
763 | | // Reset the scanner |
764 | 0 | fScanner->scanReset(token); |
765 | 0 | } |
766 | | |
767 | | |
768 | | // --------------------------------------------------------------------------- |
769 | | // SAXParser: Overrides of the XMLDocumentHandler interface |
770 | | // --------------------------------------------------------------------------- |
771 | | void SAXParser::docCharacters( const XMLCh* const chars |
772 | | , const XMLSize_t length |
773 | | , const bool cdataSection) |
774 | 0 | { |
775 | | // Suppress the chars before the root element. |
776 | 0 | if (fElemDepth) |
777 | 0 | { |
778 | | // Just map to the SAX document handler |
779 | 0 | if (fDocHandler) |
780 | 0 | fDocHandler->characters(chars, length); |
781 | 0 | } |
782 | | |
783 | | // |
784 | | // If there are any installed advanced handlers, then lets call them |
785 | | // with this info. |
786 | | // |
787 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
788 | 0 | fAdvDHList[index]->docCharacters(chars, length, cdataSection); |
789 | 0 | } |
790 | | |
791 | | |
792 | | void SAXParser::docComment(const XMLCh* const commentText) |
793 | 0 | { |
794 | | // |
795 | | // SAX has no way to report this. But, if there are any installed |
796 | | // advanced handlers, then lets call them with this info. |
797 | | // |
798 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
799 | 0 | fAdvDHList[index]->docComment(commentText); |
800 | 0 | } |
801 | | |
802 | | |
803 | | void SAXParser::XMLDecl( const XMLCh* const versionStr |
804 | | , const XMLCh* const encodingStr |
805 | | , const XMLCh* const standaloneStr |
806 | | , const XMLCh* const actualEncodingStr |
807 | | ) |
808 | 0 | { |
809 | | // |
810 | | // SAX has no way to report this. But, if there are any installed |
811 | | // advanced handlers, then lets call them with this info. |
812 | | // |
813 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
814 | 0 | fAdvDHList[index]->XMLDecl( versionStr, |
815 | 0 | encodingStr, |
816 | 0 | standaloneStr, |
817 | 0 | actualEncodingStr ); |
818 | 0 | } |
819 | | |
820 | | |
821 | | void SAXParser::docPI( const XMLCh* const target |
822 | | , const XMLCh* const data) |
823 | 0 | { |
824 | | // Just map to the SAX document handler |
825 | 0 | if (fDocHandler) |
826 | 0 | fDocHandler->processingInstruction(target, data); |
827 | | |
828 | | // |
829 | | // If there are any installed advanced handlers, then lets call them |
830 | | // with this info. |
831 | | // |
832 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
833 | 0 | fAdvDHList[index]->docPI(target, data); |
834 | 0 | } |
835 | | |
836 | | |
837 | | void SAXParser::endDocument() |
838 | 0 | { |
839 | 0 | if (fDocHandler) |
840 | 0 | fDocHandler->endDocument(); |
841 | | |
842 | | // |
843 | | // If there are any installed advanced handlers, then lets call them |
844 | | // with this info. |
845 | | // |
846 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
847 | 0 | fAdvDHList[index]->endDocument(); |
848 | 0 | } |
849 | | |
850 | | |
851 | | void SAXParser::endElement( const XMLElementDecl& elemDecl |
852 | | , const unsigned int uriId |
853 | | , const bool isRoot |
854 | | , const XMLCh* const elemPrefix) |
855 | 0 | { |
856 | | // Just map to the SAX document handler |
857 | 0 | if (fDocHandler) { |
858 | 0 | if (fScanner->getDoNamespaces()) { |
859 | |
|
860 | 0 | if (elemPrefix && *elemPrefix) { |
861 | |
|
862 | 0 | fElemQNameBuf.set(elemPrefix); |
863 | 0 | fElemQNameBuf.append(chColon); |
864 | 0 | fElemQNameBuf.append(elemDecl.getBaseName()); |
865 | 0 | fDocHandler->endElement(fElemQNameBuf.getRawBuffer()); |
866 | 0 | } |
867 | 0 | else { |
868 | 0 | fDocHandler->endElement(elemDecl.getBaseName()); |
869 | 0 | } |
870 | 0 | } |
871 | 0 | else |
872 | 0 | fDocHandler->endElement(elemDecl.getFullName()); |
873 | |
|
874 | 0 | } |
875 | | |
876 | | // |
877 | | // If there are any installed advanced handlers, then lets call them |
878 | | // with this info. |
879 | | // |
880 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
881 | 0 | fAdvDHList[index]->endElement(elemDecl, uriId, isRoot, elemPrefix); |
882 | | |
883 | | // |
884 | | // Dump the element depth down again. Don't let it underflow in case |
885 | | // of malformed XML. |
886 | | // |
887 | 0 | if (fElemDepth) |
888 | 0 | fElemDepth--; |
889 | 0 | } |
890 | | |
891 | | |
892 | | void SAXParser::endEntityReference(const XMLEntityDecl& entityDecl) |
893 | 0 | { |
894 | | // |
895 | | // SAX has no way to report this event. But, if there are any installed |
896 | | // advanced handlers, then lets call them with this info. |
897 | | // |
898 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
899 | 0 | fAdvDHList[index]->endEntityReference(entityDecl); |
900 | 0 | } |
901 | | |
902 | | |
903 | | void SAXParser::ignorableWhitespace(const XMLCh* const chars |
904 | | , const XMLSize_t length |
905 | | , const bool cdataSection) |
906 | 0 | { |
907 | | // Do not report the whitespace before the root element. |
908 | 0 | if (!fElemDepth) |
909 | 0 | return; |
910 | | |
911 | | // Just map to the SAX document handler |
912 | 0 | if (fDocHandler) |
913 | 0 | fDocHandler->ignorableWhitespace(chars, length); |
914 | | |
915 | | // |
916 | | // If there are any installed advanced handlers, then lets call them |
917 | | // with this info. |
918 | | // |
919 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
920 | 0 | fAdvDHList[index]->ignorableWhitespace(chars, length, cdataSection); |
921 | 0 | } |
922 | | |
923 | | |
924 | | void SAXParser::resetDocument() |
925 | 0 | { |
926 | | // Just map to the SAX document handler |
927 | 0 | if (fDocHandler) |
928 | 0 | fDocHandler->resetDocument(); |
929 | | |
930 | | // |
931 | | // If there are any installed advanced handlers, then lets call them |
932 | | // with this info. |
933 | | // |
934 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
935 | 0 | fAdvDHList[index]->resetDocument(); |
936 | | |
937 | | // Make sure our element depth flag gets set back to zero |
938 | 0 | fElemDepth = 0; |
939 | 0 | } |
940 | | |
941 | | |
942 | | void SAXParser::startDocument() |
943 | 0 | { |
944 | | // Just map to the SAX document handler |
945 | 0 | if (fDocHandler) |
946 | 0 | fDocHandler->setDocumentLocator(fScanner->getLocator()); |
947 | 0 | if(fDocHandler) |
948 | 0 | fDocHandler->startDocument(); |
949 | | |
950 | | // |
951 | | // If there are any installed advanced handlers, then lets call them |
952 | | // with this info. |
953 | | // |
954 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
955 | 0 | fAdvDHList[index]->startDocument(); |
956 | 0 | } |
957 | | |
958 | | |
959 | | void SAXParser:: |
960 | | startElement( const XMLElementDecl& elemDecl |
961 | | , const unsigned int elemURLId |
962 | | , const XMLCh* const elemPrefix |
963 | | , const RefVectorOf<XMLAttr>& attrList |
964 | | , const XMLSize_t attrCount |
965 | | , const bool isEmpty |
966 | | , const bool isRoot) |
967 | 0 | { |
968 | | // Bump the element depth counter if not empty |
969 | 0 | if (!isEmpty) |
970 | 0 | fElemDepth++; |
971 | |
|
972 | 0 | if (fDocHandler) |
973 | 0 | { |
974 | 0 | fAttrList.setVector(&attrList, attrCount); |
975 | 0 | if (fScanner->getDoNamespaces()) { |
976 | |
|
977 | 0 | if (elemPrefix && *elemPrefix) { |
978 | |
|
979 | 0 | fElemQNameBuf.set(elemPrefix); |
980 | 0 | fElemQNameBuf.append(chColon); |
981 | 0 | fElemQNameBuf.append(elemDecl.getBaseName()); |
982 | 0 | fDocHandler->startElement(fElemQNameBuf.getRawBuffer(), fAttrList); |
983 | | |
984 | | // If its empty, send the end tag event now |
985 | 0 | if (isEmpty && fDocHandler) |
986 | 0 | fDocHandler->endElement(fElemQNameBuf.getRawBuffer()); |
987 | 0 | } |
988 | 0 | else { |
989 | |
|
990 | 0 | fDocHandler->startElement(elemDecl.getBaseName(), fAttrList); |
991 | | |
992 | | // If its empty, send the end tag event now |
993 | 0 | if (isEmpty && fDocHandler) |
994 | 0 | fDocHandler->endElement(elemDecl.getBaseName()); |
995 | 0 | } |
996 | 0 | } |
997 | 0 | else { |
998 | 0 | fDocHandler->startElement(elemDecl.getFullName(), fAttrList); |
999 | | |
1000 | | // If its empty, send the end tag event now |
1001 | 0 | if (isEmpty && fDocHandler) |
1002 | 0 | fDocHandler->endElement(elemDecl.getFullName()); |
1003 | 0 | } |
1004 | 0 | } |
1005 | | |
1006 | | // |
1007 | | // If there are any installed advanced handlers, then lets call them |
1008 | | // with this info. |
1009 | | // |
1010 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
1011 | 0 | { |
1012 | 0 | fAdvDHList[index]->startElement |
1013 | 0 | ( |
1014 | 0 | elemDecl |
1015 | 0 | , elemURLId |
1016 | 0 | , elemPrefix |
1017 | 0 | , attrList |
1018 | 0 | , attrCount |
1019 | 0 | , isEmpty |
1020 | 0 | , isRoot |
1021 | 0 | ); |
1022 | 0 | } |
1023 | 0 | } |
1024 | | |
1025 | | |
1026 | | void SAXParser::startEntityReference(const XMLEntityDecl& entityDecl) |
1027 | 0 | { |
1028 | | // |
1029 | | // SAX has no way to report this. But, If there are any installed |
1030 | | // advanced handlers, then lets call them with this info. |
1031 | | // |
1032 | 0 | for (XMLSize_t index = 0; index < fAdvDHCount; index++) |
1033 | 0 | fAdvDHList[index]->startEntityReference(entityDecl); |
1034 | 0 | } |
1035 | | |
1036 | | |
1037 | | |
1038 | | // --------------------------------------------------------------------------- |
1039 | | // SAXParser: Overrides of the DocTypeHandler interface |
1040 | | // --------------------------------------------------------------------------- |
1041 | | void SAXParser::attDef( const DTDElementDecl& |
1042 | | , const DTDAttDef& |
1043 | | , const bool) |
1044 | 0 | { |
1045 | | // Unused by SAX DTDHandler interface at this time |
1046 | 0 | } |
1047 | | |
1048 | | |
1049 | | void SAXParser::doctypeComment(const XMLCh* const) |
1050 | 0 | { |
1051 | | // Unused by SAX DTDHandler interface at this time |
1052 | 0 | } |
1053 | | |
1054 | | |
1055 | | void SAXParser::doctypeDecl(const DTDElementDecl& |
1056 | | , const XMLCh* const |
1057 | | , const XMLCh* const |
1058 | | , const bool |
1059 | | , const bool) |
1060 | 0 | { |
1061 | | // Unused by SAX DTDHandler interface at this time |
1062 | 0 | } |
1063 | | |
1064 | | |
1065 | | void SAXParser::doctypePI( const XMLCh* const |
1066 | | , const XMLCh* const) |
1067 | 0 | { |
1068 | | // Unused by SAX DTDHandler interface at this time |
1069 | 0 | } |
1070 | | |
1071 | | |
1072 | | void SAXParser::doctypeWhitespace( const XMLCh* const |
1073 | | , const XMLSize_t) |
1074 | 0 | { |
1075 | | // Unused by SAX DTDHandler interface at this time |
1076 | 0 | } |
1077 | | |
1078 | | |
1079 | | void SAXParser::elementDecl(const DTDElementDecl&, const bool) |
1080 | 0 | { |
1081 | | // Unused by SAX DTDHandler interface at this time |
1082 | 0 | } |
1083 | | |
1084 | | |
1085 | | void SAXParser::endAttList(const DTDElementDecl&) |
1086 | 0 | { |
1087 | | // Unused by SAX DTDHandler interface at this time |
1088 | 0 | } |
1089 | | |
1090 | | |
1091 | | void SAXParser::endIntSubset() |
1092 | 0 | { |
1093 | | // Unused by SAX DTDHandler interface at this time |
1094 | 0 | } |
1095 | | |
1096 | | |
1097 | | void SAXParser::endExtSubset() |
1098 | 0 | { |
1099 | | // Unused by SAX DTDHandler interface at this time |
1100 | 0 | } |
1101 | | |
1102 | | |
1103 | | void SAXParser::entityDecl( const DTDEntityDecl& entityDecl |
1104 | | , const bool |
1105 | | , const bool isIgnored) |
1106 | 0 | { |
1107 | | // |
1108 | | // If we have a DTD handler, and this entity is not ignored, and |
1109 | | // its an unparsed entity, then send this one. |
1110 | | // |
1111 | 0 | if (fDTDHandler && !isIgnored) |
1112 | 0 | { |
1113 | 0 | if (entityDecl.isUnparsed()) |
1114 | 0 | { |
1115 | 0 | fDTDHandler->unparsedEntityDecl |
1116 | 0 | ( |
1117 | 0 | entityDecl.getName() |
1118 | 0 | , entityDecl.getPublicId() |
1119 | 0 | , entityDecl.getSystemId() |
1120 | 0 | , entityDecl.getNotationName() |
1121 | 0 | ); |
1122 | 0 | } |
1123 | 0 | } |
1124 | 0 | } |
1125 | | |
1126 | | |
1127 | | void SAXParser::resetDocType() |
1128 | 0 | { |
1129 | | // Just map to the DTD handler |
1130 | 0 | if (fDTDHandler) |
1131 | 0 | fDTDHandler->resetDocType(); |
1132 | 0 | } |
1133 | | |
1134 | | |
1135 | | void SAXParser::notationDecl( const XMLNotationDecl& notDecl |
1136 | | , const bool isIgnored) |
1137 | 0 | { |
1138 | 0 | if (fDTDHandler && !isIgnored) |
1139 | 0 | { |
1140 | 0 | fDTDHandler->notationDecl |
1141 | 0 | ( |
1142 | 0 | notDecl.getName() |
1143 | 0 | , notDecl.getPublicId() |
1144 | 0 | , notDecl.getSystemId() |
1145 | 0 | ); |
1146 | 0 | } |
1147 | 0 | } |
1148 | | |
1149 | | |
1150 | | void SAXParser::startAttList(const DTDElementDecl&) |
1151 | 0 | { |
1152 | | // Unused by SAX DTDHandler interface at this time |
1153 | 0 | } |
1154 | | |
1155 | | |
1156 | | void SAXParser::startIntSubset() |
1157 | 0 | { |
1158 | | // Unused by SAX DTDHandler interface at this time |
1159 | 0 | } |
1160 | | |
1161 | | |
1162 | | void SAXParser::startExtSubset() |
1163 | 0 | { |
1164 | | // Unused by SAX DTDHandler interface at this time |
1165 | 0 | } |
1166 | | |
1167 | | |
1168 | | void SAXParser::TextDecl( const XMLCh* const |
1169 | | , const XMLCh* const) |
1170 | 0 | { |
1171 | | // Unused by SAX DTDHandler interface at this time |
1172 | 0 | } |
1173 | | |
1174 | | |
1175 | | // --------------------------------------------------------------------------- |
1176 | | // SAXParser: Overrides of the XMLErrorReporter interface |
1177 | | // --------------------------------------------------------------------------- |
1178 | | void SAXParser::resetErrors() |
1179 | 0 | { |
1180 | 0 | if (fErrorHandler) |
1181 | 0 | fErrorHandler->resetErrors(); |
1182 | 0 | } |
1183 | | |
1184 | | |
1185 | | void SAXParser::error( const unsigned int |
1186 | | , const XMLCh* const |
1187 | | , const XMLErrorReporter::ErrTypes errType |
1188 | | , const XMLCh* const errorText |
1189 | | , const XMLCh* const systemId |
1190 | | , const XMLCh* const publicId |
1191 | | , const XMLFileLoc lineNum |
1192 | | , const XMLFileLoc colNum) |
1193 | 0 | { |
1194 | 0 | SAXParseException toThrow = SAXParseException |
1195 | 0 | ( |
1196 | 0 | errorText |
1197 | 0 | , publicId |
1198 | 0 | , systemId |
1199 | 0 | , lineNum |
1200 | 0 | , colNum |
1201 | 0 | , fMemoryManager |
1202 | 0 | ); |
1203 | |
|
1204 | 0 | if (!fErrorHandler) |
1205 | 0 | { |
1206 | 0 | if (errType == XMLErrorReporter::ErrType_Fatal) |
1207 | 0 | throw toThrow; |
1208 | 0 | else |
1209 | 0 | return; |
1210 | 0 | } |
1211 | | |
1212 | 0 | if (errType == XMLErrorReporter::ErrType_Warning) |
1213 | 0 | fErrorHandler->warning(toThrow); |
1214 | 0 | else if (errType == XMLErrorReporter::ErrType_Fatal) |
1215 | 0 | fErrorHandler->fatalError(toThrow); |
1216 | 0 | else |
1217 | 0 | fErrorHandler->error(toThrow); |
1218 | 0 | } |
1219 | | |
1220 | | |
1221 | | |
1222 | | // --------------------------------------------------------------------------- |
1223 | | // SAXParser: Handlers for the XMLEntityHandler interface |
1224 | | // --------------------------------------------------------------------------- |
1225 | | void SAXParser::endInputSource(const InputSource&) |
1226 | 0 | { |
1227 | 0 | } |
1228 | | |
1229 | | bool SAXParser::expandSystemId(const XMLCh* const, XMLBuffer&) |
1230 | 0 | { |
1231 | 0 | return false; |
1232 | 0 | } |
1233 | | |
1234 | | |
1235 | | void SAXParser::resetEntities() |
1236 | 0 | { |
1237 | | // Nothing to do for this one |
1238 | 0 | } |
1239 | | |
1240 | | InputSource* |
1241 | | SAXParser::resolveEntity( XMLResourceIdentifier* resourceIdentifier ) |
1242 | 0 | { |
1243 | | // Just map to the SAX entity resolver handler |
1244 | 0 | if (fEntityResolver) |
1245 | 0 | return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(), |
1246 | 0 | resourceIdentifier->getSystemId()); |
1247 | 0 | if (fXMLEntityResolver) |
1248 | 0 | return fXMLEntityResolver->resolveEntity(resourceIdentifier); |
1249 | 0 | return 0; |
1250 | 0 | } |
1251 | | |
1252 | | |
1253 | | void SAXParser::startInputSource(const InputSource&) |
1254 | 0 | { |
1255 | | // Nothing to do for this one |
1256 | 0 | } |
1257 | | |
1258 | | |
1259 | | // --------------------------------------------------------------------------- |
1260 | | // SAXParser: Grammar preparsing methods |
1261 | | // --------------------------------------------------------------------------- |
1262 | | Grammar* SAXParser::loadGrammar(const char* const systemId, |
1263 | | const Grammar::GrammarType grammarType, |
1264 | | const bool toCache) |
1265 | 0 | { |
1266 | | // Avoid multiple entrance |
1267 | 0 | if (fParseInProgress) |
1268 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
1269 | | |
1270 | 0 | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
1271 | |
|
1272 | 0 | Grammar* grammar = 0; |
1273 | 0 | try |
1274 | 0 | { |
1275 | 0 | fParseInProgress = true; |
1276 | 0 | grammar = fScanner->loadGrammar(systemId, grammarType, toCache); |
1277 | 0 | } |
1278 | 0 | catch(const OutOfMemoryException&) |
1279 | 0 | { |
1280 | 0 | resetInProgress.release(); |
1281 | |
|
1282 | 0 | throw; |
1283 | 0 | } |
1284 | | |
1285 | 0 | return grammar; |
1286 | 0 | } |
1287 | | |
1288 | | Grammar* SAXParser::loadGrammar(const XMLCh* const systemId, |
1289 | | const Grammar::GrammarType grammarType, |
1290 | | const bool toCache) |
1291 | 0 | { |
1292 | | // Avoid multiple entrance |
1293 | 0 | if (fParseInProgress) |
1294 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
1295 | | |
1296 | 0 | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
1297 | |
|
1298 | 0 | Grammar* grammar = 0; |
1299 | 0 | try |
1300 | 0 | { |
1301 | 0 | fParseInProgress = true; |
1302 | 0 | grammar = fScanner->loadGrammar(systemId, grammarType, toCache); |
1303 | 0 | } |
1304 | 0 | catch(const OutOfMemoryException&) |
1305 | 0 | { |
1306 | 0 | resetInProgress.release(); |
1307 | |
|
1308 | 0 | throw; |
1309 | 0 | } |
1310 | | |
1311 | 0 | return grammar; |
1312 | 0 | } |
1313 | | |
1314 | | Grammar* SAXParser::loadGrammar(const InputSource& source, |
1315 | | const Grammar::GrammarType grammarType, |
1316 | | const bool toCache) |
1317 | 0 | { |
1318 | | // Avoid multiple entrance |
1319 | 0 | if (fParseInProgress) |
1320 | 0 | ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); |
1321 | | |
1322 | 0 | ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); |
1323 | |
|
1324 | 0 | Grammar* grammar = 0; |
1325 | 0 | try |
1326 | 0 | { |
1327 | 0 | fParseInProgress = true; |
1328 | 0 | grammar = fScanner->loadGrammar(source, grammarType, toCache); |
1329 | 0 | } |
1330 | 0 | catch(const OutOfMemoryException&) |
1331 | 0 | { |
1332 | 0 | resetInProgress.release(); |
1333 | |
|
1334 | 0 | throw; |
1335 | 0 | } |
1336 | | |
1337 | 0 | return grammar; |
1338 | 0 | } |
1339 | | |
1340 | | void SAXParser::resetInProgress() |
1341 | 18.1k | { |
1342 | 18.1k | fParseInProgress = false; |
1343 | 18.1k | } |
1344 | | |
1345 | | void SAXParser::resetCachedGrammarPool() |
1346 | 0 | { |
1347 | 0 | fGrammarResolver->resetCachedGrammar(); |
1348 | 0 | fScanner->resetCachedGrammar(); |
1349 | 0 | } |
1350 | | |
1351 | | XERCES_CPP_NAMESPACE_END |