PageRenderTime 29ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ATF2/control-software/epics-3.14.8/extensions/src/ChannelArchiver/ThirdParty/xerces-c-src2_4_0/src/xercesc/parsers/SAXParser.cpp

http://atf2flightsim.googlecode.com/
C++ | 1535 lines | 853 code | 213 blank | 469 comment | 102 complexity | 282be1657649bc5182f137b6168d022c MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999-2003 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. * $Log: SAXParser.cpp,v $
  58. * Revision 1.1.1.1 2009/03/14 06:42:53 whitegr
  59. * epics channel archiver
  60. *
  61. * Revision 1.29 2003/11/21 22:38:50 neilg
  62. * Enable grammar pools and grammar resolvers to manufacture
  63. * XSModels. This also cleans up handling in the
  64. * parser classes by eliminating the need to tell
  65. * the grammar pool that schema compoments need to be produced.
  66. * Thanks to David Cargill.
  67. *
  68. * Revision 1.28 2003/11/06 15:30:07 neilg
  69. * first part of PSVI/schema component model implementation, thanks to David Cargill. This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse.
  70. *
  71. * Revision 1.27 2003/10/30 21:37:31 knoaman
  72. * Enhanced Entity Resolver Support. Thanks to David Cargill.
  73. *
  74. * Revision 1.26 2003/10/01 16:32:38 neilg
  75. * improve handling of out of memory conditions, bug #23415. Thanks to David Cargill.
  76. *
  77. * Revision 1.25 2003/09/16 18:30:54 neilg
  78. * make Grammar pool be responsible for creating and owning URI string pools. This is one more step towards having grammars be independent of the parsers involved in their creation
  79. *
  80. * Revision 1.24 2003/08/13 15:43:24 knoaman
  81. * Use memory manager when creating SAX exceptions.
  82. *
  83. * Revision 1.23 2003/07/31 17:05:48 peiyongz
  84. * using getGrammar(URI)
  85. *
  86. * Revision 1.22 2003/07/10 19:48:24 peiyongz
  87. * Stateless Grammar: Initialize scanner with grammarResolver,
  88. *
  89. * Revision 1.21 2003/06/25 22:36:46 peiyongz
  90. * to use new GrammarResolver::getGrammar()
  91. *
  92. * Revision 1.20 2003/06/20 18:55:54 peiyongz
  93. * Stateless Grammar Pool :: Part I
  94. *
  95. * Revision 1.19 2003/05/18 14:02:05 knoaman
  96. * Memory manager implementation: pass per instance manager.
  97. *
  98. * Revision 1.18 2003/05/16 21:36:59 knoaman
  99. * Memory manager implementation: Modify constructors to pass in the memory manager.
  100. *
  101. * Revision 1.17 2003/05/15 18:26:50 knoaman
  102. * Partial implementation of the configurable memory manager.
  103. *
  104. * Revision 1.16 2003/04/17 21:58:50 neilg
  105. * Adding a new property,
  106. * http://apache.org/xml/properties/security-manager, with
  107. * appropriate getSecurityManager/setSecurityManager methods on DOM
  108. * and SAX parsers. Also adding a new SecurityManager class.
  109. *
  110. * The purpose of these modifications is to permit applications a
  111. * means to have the parser reject documents whose processing would
  112. * otherwise consume large amounts of system resources. Malicious
  113. * use of such documents could be used to launch a denial-of-service
  114. * attack against a system running the parser. Initially, the
  115. * SecurityManager only knows about attacks that can result from
  116. * exponential entity expansion; this is the only known attack that
  117. * involves processing a single XML document. Other, simlar attacks
  118. * can be launched if arbitrary schemas may be parsed; there already
  119. * exist means (via use of the EntityResolver interface) by which
  120. * applications can deny processing of untrusted schemas. In future,
  121. * the SecurityManager will be expanded to take these other exploits
  122. * into account.
  123. *
  124. * add security manager
  125. *
  126. * Revision 1.15 2003/02/04 19:27:43 knoaman
  127. * Performance: use global buffer to eliminate repetitive memory creation/deletion.
  128. *
  129. * Revision 1.14 2003/01/09 19:07:08 tng
  130. * [Bug 15802] Add "const" qualifier to getURIText.
  131. *
  132. * Revision 1.13 2003/01/03 20:09:36 tng
  133. * New feature StandardUriConformant to force strict standard uri conformance.
  134. *
  135. * Revision 1.12 2002/12/27 16:16:51 knoaman
  136. * Set scanner options and handlers.
  137. *
  138. * Revision 1.11 2002/12/23 15:23:18 knoaman
  139. * Added a public api to various parsers to return the src offset within the input
  140. * source.
  141. *
  142. * Revision 1.10 2002/12/04 01:57:09 knoaman
  143. * Scanner re-organization.
  144. *
  145. * Revision 1.9 2002/11/04 14:57:03 tng
  146. * C++ Namespace Support.
  147. *
  148. * Revision 1.8 2002/08/14 15:20:38 knoaman
  149. * [Bug 3111] Problem with LexicalHandler::startDTD() and LexicalHandler::endDTD().
  150. *
  151. * Revision 1.7 2002/07/11 18:27:04 knoaman
  152. * Grammar caching/preparsing - initial implementation.
  153. *
  154. * Revision 1.6 2002/05/30 16:20:09 tng
  155. * Add feature to optionally ignore external DTD.
  156. *
  157. * Revision 1.5 2002/05/29 21:37:47 knoaman
  158. * Add baseURI to resolveEntity to support DOMInputSource.
  159. *
  160. * Revision 1.4 2002/05/28 20:44:14 tng
  161. * [Bug 9104] prefixes dissapearing when schema validation turned on.
  162. *
  163. * Revision 1.3 2002/05/27 18:39:21 tng
  164. * To get ready for 64 bit large file, use XMLSSize_t to represent line and column number.
  165. *
  166. * Revision 1.2 2002/05/22 20:53:41 knoaman
  167. * Prepare for DOM L3 :
  168. * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using
  169. * EntityHandler/ErrorHandler directly.
  170. * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser
  171. * and DOMBuilder.
  172. *
  173. * Revision 1.1.1.1 2002/02/01 22:22:07 peiyongz
  174. * sane_include
  175. *
  176. * Revision 1.23 2001/11/20 18:51:44 tng
  177. * Schema: schemaLocation and noNamespaceSchemaLocation to be specified outside the instance document. New methods setExternalSchemaLocation and setExternalNoNamespaceSchemaLocation are added (for SAX2, two new properties are added).
  178. *
  179. * Revision 1.22 2001/10/25 19:46:15 tng
  180. * Comment outside root element should also be reported.
  181. *
  182. * Revision 1.21 2001/08/01 19:11:02 tng
  183. * Add full schema constraint checking flag to the samples and the parser.
  184. *
  185. * Revision 1.20 2001/06/03 19:26:20 jberry
  186. * Add support for querying error count following parse; enables simple parse without requiring error handler.
  187. *
  188. * Revision 1.19 2001/05/11 13:26:22 tng
  189. * Copyright update.
  190. *
  191. * Revision 1.18 2001/05/03 19:09:23 knoaman
  192. * Support Warning/Error/FatalError messaging.
  193. * Validity constraints errors are treated as errors, with the ability by user to set
  194. * validity constraints as fatal errors.
  195. *
  196. * Revision 1.17 2001/03/30 16:46:57 tng
  197. * Schema: Use setDoSchema instead of setSchemaValidation which makes more sense.
  198. *
  199. * Revision 1.16 2001/03/21 21:56:08 tng
  200. * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  201. *
  202. * Revision 1.15 2001/02/15 15:56:29 tng
  203. * Schema: Add setSchemaValidation and getSchemaValidation for DOMParser and SAXParser.
  204. * Add feature "http://apache.org/xml/features/validation/schema" for SAX2XMLReader.
  205. * New data field fSchemaValidation in XMLScanner as the flag.
  206. *
  207. * Revision 1.14 2000/09/05 23:38:26 andyh
  208. * Added advanced callback support for XMLDecl()
  209. *
  210. * Revision 1.13 2000/06/19 18:12:56 rahulj
  211. * Suppress the comments, characters, ignoreableWhitespaces before
  212. * root element. Only allow the PI's to get through. Still need to come
  213. * to a consensus on this.
  214. *
  215. * Revision 1.12 2000/06/17 02:00:55 rahulj
  216. * Also pass any PI's, comment's, character's occuring before root
  217. * element to the registered document Handler. Defect identified
  218. * by John Smirl and Rich Taylor.
  219. *
  220. * Revision 1.11 2000/05/15 22:31:18 andyh
  221. * Replace #include<memory.h> with <string.h> everywhere.
  222. *
  223. * Revision 1.10 2000/04/12 22:58:30 roddey
  224. * Added support for 'auto validate' mode.
  225. *
  226. * Revision 1.9 2000/04/11 19:17:58 roddey
  227. * If a SAX error handler is installed, then the resetErrors() event handler
  228. * should call the one on the installed SAX error handler.
  229. *
  230. * Revision 1.8 2000/04/05 18:56:17 roddey
  231. * Init the fDTDHandler member. Enable installation of DTDHandler
  232. * on SAX parser.
  233. *
  234. * Revision 1.7 2000/03/03 01:29:34 roddey
  235. * Added a scanReset()/parseReset() method to the scanner and
  236. * parsers, to allow for reset after early exit from a progressive parse.
  237. * Added calls to new Terminate() call to all of the samples. Improved
  238. * documentation in SAX and DOM parsers.
  239. *
  240. * Revision 1.6 2000/03/02 19:54:33 roddey
  241. * This checkin includes many changes done while waiting for the
  242. * 1.1.0 code to be finished. I can't list them all here, but a list is
  243. * available elsewhere.
  244. *
  245. * Revision 1.5 2000/02/17 03:54:26 rahulj
  246. * Added some new getters to query the parser state and
  247. * clarified the documentation.
  248. *
  249. * Revision 1.4 2000/02/06 07:47:56 rahulj
  250. * Year 2K copyright swat.
  251. *
  252. * Revision 1.3 2000/01/12 00:15:22 roddey
  253. * Changes to deal with multiply nested, relative pathed, entities and to deal
  254. * with the new URL class changes.
  255. *
  256. * Revision 1.2 1999/12/15 19:57:48 roddey
  257. * Got rid of redundant 'const' on boolean return value. Some compilers choke
  258. * on this and its useless.
  259. *
  260. * Revision 1.1.1.1 1999/11/09 01:07:50 twl
  261. * Initial checkin
  262. *
  263. * Revision 1.6 1999/11/08 20:44:53 rahul
  264. * Swat for adding in Product name and CVS comment log variable.
  265. *
  266. */
  267. // ---------------------------------------------------------------------------
  268. // Includes
  269. // ---------------------------------------------------------------------------
  270. #include <xercesc/parsers/SAXParser.hpp>
  271. #include <xercesc/internal/XMLScannerResolver.hpp>
  272. #include <xercesc/framework/XMLValidator.hpp>
  273. #include <xercesc/util/IOException.hpp>
  274. #include <xercesc/sax/DocumentHandler.hpp>
  275. #include <xercesc/sax/DTDHandler.hpp>
  276. #include <xercesc/sax/ErrorHandler.hpp>
  277. #include <xercesc/sax/EntityResolver.hpp>
  278. #include <xercesc/sax/SAXParseException.hpp>
  279. #include <xercesc/validators/common/GrammarResolver.hpp>
  280. #include <xercesc/framework/XMLGrammarPool.hpp>
  281. #include <xercesc/framework/XMLSchemaDescription.hpp>
  282. #include <xercesc/util/Janitor.hpp>
  283. #include <xercesc/util/OutOfMemoryException.hpp>
  284. #include <xercesc/util/XMLEntityResolver.hpp>
  285. #include <string.h>
  286. XERCES_CPP_NAMESPACE_BEGIN
  287. // ---------------------------------------------------------------------------
  288. // SAXParser: Constructors and Destructor
  289. // ---------------------------------------------------------------------------
  290. SAXParser::SAXParser( XMLValidator* const valToAdopt
  291. , MemoryManager* const manager
  292. , XMLGrammarPool* const gramPool):
  293. fParseInProgress(false)
  294. , fElemDepth(0)
  295. , fAdvDHCount(0)
  296. , fAdvDHListSize(32)
  297. , fDocHandler(0)
  298. , fDTDHandler(0)
  299. , fEntityResolver(0)
  300. , fXMLEntityResolver(0)
  301. , fErrorHandler(0)
  302. , fPSVIHandler(0)
  303. , fAdvDHList(0)
  304. , fScanner(0)
  305. , fGrammarResolver(0)
  306. , fURIStringPool(0)
  307. , fValidator(valToAdopt)
  308. , fMemoryManager(manager)
  309. , fGrammarPool(gramPool)
  310. , fElemQNameBuf(1023, manager)
  311. {
  312. try
  313. {
  314. initialize();
  315. }
  316. catch(const OutOfMemoryException&)
  317. {
  318. throw;
  319. }
  320. catch(...)
  321. {
  322. cleanUp();
  323. throw;
  324. }
  325. }
  326. SAXParser::~SAXParser()
  327. {
  328. cleanUp();
  329. }
  330. // ---------------------------------------------------------------------------
  331. // SAXParser: Initialize/CleanUp methods
  332. // ---------------------------------------------------------------------------
  333. void SAXParser::initialize()
  334. {
  335. // Create grammar resolver and string pool to pass to scanner
  336. fGrammarResolver = new (fMemoryManager) GrammarResolver(fGrammarPool, fMemoryManager);
  337. fURIStringPool = fGrammarResolver->getStringPool();
  338. // Create our scanner and tell it what validator to use
  339. fScanner = XMLScannerResolver::getDefaultScanner(fValidator, fGrammarResolver, fMemoryManager);
  340. fScanner->setURIStringPool(fURIStringPool);
  341. // Create the initial advanced handler list array and zero it out
  342. fAdvDHList = (XMLDocumentHandler**) fMemoryManager->allocate
  343. (
  344. fAdvDHListSize * sizeof(XMLDocumentHandler*)
  345. );//new XMLDocumentHandler*[fAdvDHListSize];
  346. memset(fAdvDHList, 0, sizeof(void*) * fAdvDHListSize);
  347. }
  348. void SAXParser::cleanUp()
  349. {
  350. fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList;
  351. delete fScanner;
  352. delete fGrammarResolver;
  353. // grammar pool must do this
  354. //delete fURIStringPool;
  355. if (fValidator)
  356. delete fValidator;
  357. }
  358. // ---------------------------------------------------------------------------
  359. // SAXParser: Advanced document handler list maintenance methods
  360. // ---------------------------------------------------------------------------
  361. void SAXParser::installAdvDocHandler(XMLDocumentHandler* const toInstall)
  362. {
  363. // See if we need to expand and do so now if needed
  364. if (fAdvDHCount == fAdvDHListSize)
  365. {
  366. // Calc a new size and allocate the new temp buffer
  367. const unsigned int newSize = (unsigned int)(fAdvDHListSize * 1.5);
  368. XMLDocumentHandler** newList = (XMLDocumentHandler**) fMemoryManager->allocate
  369. (
  370. newSize * sizeof(XMLDocumentHandler*)
  371. );//new XMLDocumentHandler*[newSize];
  372. // Copy over the old data to the new list and zero out the rest
  373. memcpy(newList, fAdvDHList, sizeof(void*) * fAdvDHListSize);
  374. memset
  375. (
  376. &newList[fAdvDHListSize]
  377. , 0
  378. , sizeof(void*) * (newSize - fAdvDHListSize)
  379. );
  380. // And now clean up the old array and store the new stuff
  381. fMemoryManager->deallocate(fAdvDHList);//delete [] fAdvDHList;
  382. fAdvDHList = newList;
  383. fAdvDHListSize = newSize;
  384. }
  385. // Add this new guy into the empty slot
  386. fAdvDHList[fAdvDHCount++] = toInstall;
  387. //
  388. // Install ourself as the document handler with the scanner. We might
  389. // already be, but its not worth checking, just do it.
  390. //
  391. fScanner->setDocHandler(this);
  392. }
  393. bool SAXParser::removeAdvDocHandler(XMLDocumentHandler* const toRemove)
  394. {
  395. // If our count is zero, can't be any installed
  396. if (!fAdvDHCount)
  397. return false;
  398. //
  399. // Search the array until we find this handler. If we find a null entry
  400. // first, we can stop there before the list is kept contiguous.
  401. //
  402. unsigned int index;
  403. for (index = 0; index < fAdvDHCount; index++)
  404. {
  405. //
  406. // We found it. We have to keep the list contiguous, so we have to
  407. // copy down any used elements after this one.
  408. //
  409. if (fAdvDHList[index] == toRemove)
  410. {
  411. //
  412. // Optimize if only one entry (pretty common). Otherwise, we
  413. // have to copy them down to compact them.
  414. //
  415. if (fAdvDHCount > 1)
  416. {
  417. index++;
  418. while (index < fAdvDHCount)
  419. fAdvDHList[index - 1] = fAdvDHList[index];
  420. }
  421. // Bump down the count and zero out the last one
  422. fAdvDHCount--;
  423. fAdvDHList[fAdvDHCount] = 0;
  424. //
  425. // If this leaves us with no advanced handlers and there is
  426. // no SAX doc handler installed on us, then remove us from the
  427. // scanner as the document handler.
  428. //
  429. if (!fAdvDHCount && !fDocHandler)
  430. fScanner->setDocHandler(0);
  431. return true;
  432. }
  433. }
  434. // Never found it
  435. return false;
  436. }
  437. // ---------------------------------------------------------------------------
  438. // SAXParser: Getter methods
  439. // ---------------------------------------------------------------------------
  440. const XMLValidator& SAXParser::getValidator() const
  441. {
  442. return *fScanner->getValidator();
  443. }
  444. bool SAXParser::getDoNamespaces() const
  445. {
  446. return fScanner->getDoNamespaces();
  447. }
  448. bool SAXParser::getExitOnFirstFatalError() const
  449. {
  450. return fScanner->getExitOnFirstFatal();
  451. }
  452. bool SAXParser::getValidationConstraintFatal() const
  453. {
  454. return fScanner->getValidationConstraintFatal();
  455. }
  456. SAXParser::ValSchemes SAXParser::getValidationScheme() const
  457. {
  458. const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme();
  459. if (scheme == XMLScanner::Val_Always)
  460. return Val_Always;
  461. else if (scheme == XMLScanner::Val_Never)
  462. return Val_Never;
  463. return Val_Auto;
  464. }
  465. bool SAXParser::getDoSchema() const
  466. {
  467. return fScanner->getDoSchema();
  468. }
  469. bool SAXParser::getValidationSchemaFullChecking() const
  470. {
  471. return fScanner->getValidationSchemaFullChecking();
  472. }
  473. int SAXParser::getErrorCount() const
  474. {
  475. return fScanner->getErrorCount();
  476. }
  477. XMLCh* SAXParser::getExternalSchemaLocation() const
  478. {
  479. return fScanner->getExternalSchemaLocation();
  480. }
  481. XMLCh* SAXParser::getExternalNoNamespaceSchemaLocation() const
  482. {
  483. return fScanner->getExternalNoNamespaceSchemaLocation();
  484. }
  485. SecurityManager* SAXParser::getSecurityManager() const
  486. {
  487. return fScanner->getSecurityManager();
  488. }
  489. bool SAXParser::getLoadExternalDTD() const
  490. {
  491. return fScanner->getLoadExternalDTD();
  492. }
  493. bool SAXParser::isCachingGrammarFromParse() const
  494. {
  495. return fScanner->isCachingGrammarFromParse();
  496. }
  497. bool SAXParser::isUsingCachedGrammarInParse() const
  498. {
  499. return fScanner->isUsingCachedGrammarInParse();
  500. }
  501. bool SAXParser::getCalculateSrcOfs() const
  502. {
  503. return fScanner->getCalculateSrcOfs();
  504. }
  505. bool SAXParser::getStandardUriConformant() const
  506. {
  507. return fScanner->getStandardUriConformant();
  508. }
  509. Grammar* SAXParser::getGrammar(const XMLCh* const nameSpaceKey)
  510. {
  511. return fGrammarResolver->getGrammar(nameSpaceKey);
  512. }
  513. Grammar* SAXParser::getRootGrammar()
  514. {
  515. return fScanner->getRootGrammar();
  516. }
  517. const XMLCh* SAXParser::getURIText(unsigned int uriId) const
  518. {
  519. return fScanner->getURIText(uriId);
  520. }
  521. unsigned int SAXParser::getSrcOffset() const
  522. {
  523. return fScanner->getSrcOffset();
  524. }
  525. // ---------------------------------------------------------------------------
  526. // SAXParser: Setter methods
  527. // ---------------------------------------------------------------------------
  528. void SAXParser::setDoNamespaces(const bool newState)
  529. {
  530. fScanner->setDoNamespaces(newState);
  531. }
  532. void SAXParser::setExitOnFirstFatalError(const bool newState)
  533. {
  534. fScanner->setExitOnFirstFatal(newState);
  535. }
  536. void SAXParser::setValidationConstraintFatal(const bool newState)
  537. {
  538. fScanner->setValidationConstraintFatal(newState);
  539. }
  540. void SAXParser::setValidationScheme(const ValSchemes newScheme)
  541. {
  542. if (newScheme == Val_Never)
  543. fScanner->setValidationScheme(XMLScanner::Val_Never);
  544. else if (newScheme == Val_Always)
  545. fScanner->setValidationScheme(XMLScanner::Val_Always);
  546. else
  547. fScanner->setValidationScheme(XMLScanner::Val_Auto);
  548. }
  549. void SAXParser::setDoSchema(const bool newState)
  550. {
  551. fScanner->setDoSchema(newState);
  552. }
  553. void SAXParser::setValidationSchemaFullChecking(const bool schemaFullChecking)
  554. {
  555. fScanner->setValidationSchemaFullChecking(schemaFullChecking);
  556. }
  557. void SAXParser::setExternalSchemaLocation(const XMLCh* const schemaLocation)
  558. {
  559. fScanner->setExternalSchemaLocation(schemaLocation);
  560. }
  561. void SAXParser::setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation)
  562. {
  563. fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation);
  564. }
  565. void SAXParser::setExternalSchemaLocation(const char* const schemaLocation)
  566. {
  567. fScanner->setExternalSchemaLocation(schemaLocation);
  568. }
  569. void SAXParser::setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation)
  570. {
  571. fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation);
  572. }
  573. void SAXParser::setSecurityManager(SecurityManager* const securityManager)
  574. {
  575. // since this could impact various components, don't permit it to change
  576. // during a parse
  577. if (fParseInProgress)
  578. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  579. fScanner->setSecurityManager(securityManager);
  580. }
  581. void SAXParser::setLoadExternalDTD(const bool newState)
  582. {
  583. fScanner->setLoadExternalDTD(newState);
  584. }
  585. void SAXParser::cacheGrammarFromParse(const bool newState)
  586. {
  587. fScanner->cacheGrammarFromParse(newState);
  588. if (newState)
  589. fScanner->useCachedGrammarInParse(newState);
  590. }
  591. void SAXParser::useCachedGrammarInParse(const bool newState)
  592. {
  593. if (newState || !fScanner->isCachingGrammarFromParse())
  594. fScanner->useCachedGrammarInParse(newState);
  595. }
  596. void SAXParser::setCalculateSrcOfs(const bool newState)
  597. {
  598. fScanner->setCalculateSrcOfs(newState);
  599. }
  600. void SAXParser::setStandardUriConformant(const bool newState)
  601. {
  602. fScanner->setStandardUriConformant(newState);
  603. }
  604. void SAXParser::useScanner(const XMLCh* const scannerName)
  605. {
  606. XMLScanner* tempScanner = XMLScannerResolver::resolveScanner
  607. (
  608. scannerName
  609. , fValidator
  610. , fGrammarResolver
  611. , fMemoryManager
  612. );
  613. if (tempScanner) {
  614. tempScanner->setParseSettings(fScanner);
  615. tempScanner->setURIStringPool(fURIStringPool);
  616. delete fScanner;
  617. fScanner = tempScanner;
  618. }
  619. }
  620. // ---------------------------------------------------------------------------
  621. // SAXParser: Overrides of the SAX Parser interface
  622. // ---------------------------------------------------------------------------
  623. void SAXParser::parse(const InputSource& source)
  624. {
  625. // Avoid multiple entrance
  626. if (fParseInProgress)
  627. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  628. try
  629. {
  630. fParseInProgress = true;
  631. fScanner->scanDocument(source);
  632. fParseInProgress = false;
  633. }
  634. catch(const OutOfMemoryException&)
  635. {
  636. throw;
  637. }
  638. catch (...)
  639. {
  640. fParseInProgress = false;
  641. throw;
  642. }
  643. }
  644. void SAXParser::parse(const XMLCh* const systemId)
  645. {
  646. // Avoid multiple entrance
  647. if (fParseInProgress)
  648. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  649. try
  650. {
  651. fParseInProgress = true;
  652. fScanner->scanDocument(systemId);
  653. fParseInProgress = false;
  654. }
  655. catch(const OutOfMemoryException&)
  656. {
  657. throw;
  658. }
  659. catch (...)
  660. {
  661. fParseInProgress = false;
  662. throw;
  663. }
  664. }
  665. void SAXParser::parse(const char* const systemId)
  666. {
  667. // Avoid multiple entrance
  668. if (fParseInProgress)
  669. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  670. try
  671. {
  672. fParseInProgress = true;
  673. fScanner->scanDocument(systemId);
  674. fParseInProgress = false;
  675. }
  676. catch(const OutOfMemoryException&)
  677. {
  678. throw;
  679. }
  680. catch (...)
  681. {
  682. fParseInProgress = false;
  683. throw;
  684. }
  685. }
  686. void SAXParser::setDocumentHandler(DocumentHandler* const handler)
  687. {
  688. fDocHandler = handler;
  689. if (fDocHandler)
  690. {
  691. //
  692. // Make sure we are set as the document handler with the scanner.
  693. // We may already be (if advanced handlers are installed), but its
  694. // not worthing checking, just do it.
  695. //
  696. fScanner->setDocHandler(this);
  697. }
  698. else
  699. {
  700. //
  701. // If we don't have any advanced handlers either, then deinstall us
  702. // from the scanner because we don't need document events anymore.
  703. //
  704. if (!fAdvDHCount)
  705. fScanner->setDocHandler(0);
  706. }
  707. }
  708. void SAXParser::setDTDHandler(DTDHandler* const handler)
  709. {
  710. fDTDHandler = handler;
  711. if (fDTDHandler)
  712. fScanner->setDocTypeHandler(this);
  713. else
  714. fScanner->setDocTypeHandler(0);
  715. }
  716. void SAXParser::setErrorHandler(ErrorHandler* const handler)
  717. {
  718. //
  719. // Store the handler. Then either install or deinstall us as the
  720. // error reporter on the scanner.
  721. //
  722. fErrorHandler = handler;
  723. if (fErrorHandler) {
  724. fScanner->setErrorReporter(this);
  725. fScanner->setErrorHandler(fErrorHandler);
  726. }
  727. else {
  728. fScanner->setErrorReporter(0);
  729. fScanner->setErrorHandler(0);
  730. }
  731. }
  732. void SAXParser::setPSVIHandler(PSVIHandler* const handler)
  733. {
  734. fPSVIHandler = handler;
  735. if (fPSVIHandler) {
  736. fScanner->setPSVIHandler(fPSVIHandler);
  737. }
  738. else {
  739. fScanner->setPSVIHandler(0);
  740. }
  741. }
  742. void SAXParser::setEntityResolver(EntityResolver* const resolver)
  743. {
  744. fEntityResolver = resolver;
  745. if (fEntityResolver) {
  746. fScanner->setEntityHandler(this);
  747. fXMLEntityResolver = 0;
  748. }
  749. else {
  750. fScanner->setEntityHandler(0);
  751. }
  752. }
  753. void SAXParser::setXMLEntityResolver(XMLEntityResolver* const resolver)
  754. {
  755. fXMLEntityResolver = resolver;
  756. if (fXMLEntityResolver) {
  757. fScanner->setEntityHandler(this);
  758. fEntityResolver = 0;
  759. }
  760. else {
  761. fScanner->setEntityHandler(0);
  762. }
  763. }
  764. // ---------------------------------------------------------------------------
  765. // SAXParser: Progressive parse methods
  766. // ---------------------------------------------------------------------------
  767. bool SAXParser::parseFirst( const XMLCh* const systemId
  768. , XMLPScanToken& toFill)
  769. {
  770. //
  771. // Avoid multiple entrance. We cannot enter here while a regular parse
  772. // is in progress.
  773. //
  774. if (fParseInProgress)
  775. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  776. return fScanner->scanFirst(systemId, toFill);
  777. }
  778. bool SAXParser::parseFirst( const char* const systemId
  779. , XMLPScanToken& toFill)
  780. {
  781. //
  782. // Avoid multiple entrance. We cannot enter here while a regular parse
  783. // is in progress.
  784. //
  785. if (fParseInProgress)
  786. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  787. return fScanner->scanFirst(systemId, toFill);
  788. }
  789. bool SAXParser::parseFirst( const InputSource& source
  790. , XMLPScanToken& toFill)
  791. {
  792. //
  793. // Avoid multiple entrance. We cannot enter here while a regular parse
  794. // is in progress.
  795. //
  796. if (fParseInProgress)
  797. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  798. return fScanner->scanFirst(source, toFill);
  799. }
  800. bool SAXParser::parseNext(XMLPScanToken& token)
  801. {
  802. return fScanner->scanNext(token);
  803. }
  804. void SAXParser::parseReset(XMLPScanToken& token)
  805. {
  806. // Reset the scanner
  807. fScanner->scanReset(token);
  808. }
  809. // ---------------------------------------------------------------------------
  810. // SAXParser: Overrides of the XMLDocumentHandler interface
  811. // ---------------------------------------------------------------------------
  812. void SAXParser::docCharacters( const XMLCh* const chars
  813. , const unsigned int length
  814. , const bool cdataSection)
  815. {
  816. // Suppress the chars before the root element.
  817. if (!fElemDepth)
  818. return;
  819. // Just map to the SAX document handler
  820. if (fDocHandler)
  821. fDocHandler->characters(chars, length);
  822. //
  823. // If there are any installed advanced handlers, then lets call them
  824. // with this info.
  825. //
  826. for (unsigned int index = 0; index < fAdvDHCount; index++)
  827. fAdvDHList[index]->docCharacters(chars, length, cdataSection);
  828. }
  829. void SAXParser::docComment(const XMLCh* const commentText)
  830. {
  831. //
  832. // SAX has no way to report this. But, if there are any installed
  833. // advanced handlers, then lets call them with this info.
  834. //
  835. for (unsigned int index = 0; index < fAdvDHCount; index++)
  836. fAdvDHList[index]->docComment(commentText);
  837. }
  838. void SAXParser::XMLDecl( const XMLCh* const versionStr
  839. , const XMLCh* const encodingStr
  840. , const XMLCh* const standaloneStr
  841. , const XMLCh* const actualEncodingStr
  842. )
  843. {
  844. //
  845. // SAX has no way to report this. But, if there are any installed
  846. // advanced handlers, then lets call them with this info.
  847. //
  848. for (unsigned int index = 0; index < fAdvDHCount; index++)
  849. fAdvDHList[index]->XMLDecl( versionStr,
  850. encodingStr,
  851. standaloneStr,
  852. actualEncodingStr );
  853. }
  854. void SAXParser::docPI( const XMLCh* const target
  855. , const XMLCh* const data)
  856. {
  857. // Just map to the SAX document handler
  858. if (fDocHandler)
  859. fDocHandler->processingInstruction(target, data);
  860. //
  861. // If there are any installed advanced handlers, then lets call them
  862. // with this info.
  863. //
  864. for (unsigned int index = 0; index < fAdvDHCount; index++)
  865. fAdvDHList[index]->docPI(target, data);
  866. }
  867. void SAXParser::endDocument()
  868. {
  869. if (fDocHandler)
  870. fDocHandler->endDocument();
  871. //
  872. // If there are any installed advanced handlers, then lets call them
  873. // with this info.
  874. //
  875. for (unsigned int index = 0; index < fAdvDHCount; index++)
  876. fAdvDHList[index]->endDocument();
  877. }
  878. void SAXParser::endElement( const XMLElementDecl& elemDecl
  879. , const unsigned int uriId
  880. , const bool isRoot
  881. , const XMLCh* const elemPrefix)
  882. {
  883. // Just map to the SAX document handler
  884. if (fDocHandler) {
  885. if (fScanner->getDoNamespaces()) {
  886. if (elemPrefix && *elemPrefix) {
  887. fElemQNameBuf.set(elemPrefix);
  888. fElemQNameBuf.append(chColon);
  889. fElemQNameBuf.append(elemDecl.getBaseName());
  890. fDocHandler->endElement(fElemQNameBuf.getRawBuffer());
  891. }
  892. else {
  893. fDocHandler->endElement(elemDecl.getBaseName());
  894. }
  895. }
  896. else
  897. fDocHandler->endElement(elemDecl.getFullName());
  898. }
  899. //
  900. // If there are any installed advanced handlers, then lets call them
  901. // with this info.
  902. //
  903. for (unsigned int index = 0; index < fAdvDHCount; index++)
  904. fAdvDHList[index]->endElement(elemDecl, uriId, isRoot, elemPrefix);
  905. //
  906. // Dump the element depth down again. Don't let it underflow in case
  907. // of malformed XML.
  908. //
  909. if (fElemDepth)
  910. fElemDepth--;
  911. }
  912. void SAXParser::endEntityReference(const XMLEntityDecl& entityDecl)
  913. {
  914. //
  915. // SAX has no way to report this event. But, if there are any installed
  916. // advanced handlers, then lets call them with this info.
  917. //
  918. for (unsigned int index = 0; index < fAdvDHCount; index++)
  919. fAdvDHList[index]->endEntityReference(entityDecl);
  920. }
  921. void SAXParser::ignorableWhitespace(const XMLCh* const chars
  922. , const unsigned int length
  923. , const bool cdataSection)
  924. {
  925. // Do not report the whitespace before the root element.
  926. if (!fElemDepth)
  927. return;
  928. // Just map to the SAX document handler
  929. if (fDocHandler)
  930. fDocHandler->ignorableWhitespace(chars, length);
  931. //
  932. // If there are any installed advanced handlers, then lets call them
  933. // with this info.
  934. //
  935. for (unsigned int index = 0; index < fAdvDHCount; index++)
  936. fAdvDHList[index]->ignorableWhitespace(chars, length, cdataSection);
  937. }
  938. void SAXParser::resetDocument()
  939. {
  940. // Just map to the SAX document handler
  941. if (fDocHandler)
  942. fDocHandler->resetDocument();
  943. //
  944. // If there are any installed advanced handlers, then lets call them
  945. // with this info.
  946. //
  947. for (unsigned int index = 0; index < fAdvDHCount; index++)
  948. fAdvDHList[index]->resetDocument();
  949. // Make sure our element depth flag gets set back to zero
  950. fElemDepth = 0;
  951. }
  952. void SAXParser::startDocument()
  953. {
  954. // Just map to the SAX document handler
  955. if (fDocHandler)
  956. {
  957. fDocHandler->setDocumentLocator(fScanner->getLocator());
  958. fDocHandler->startDocument();
  959. }
  960. //
  961. // If there are any installed advanced handlers, then lets call them
  962. // with this info.
  963. //
  964. for (unsigned int index = 0; index < fAdvDHCount; index++)
  965. fAdvDHList[index]->startDocument();
  966. }
  967. void SAXParser::
  968. startElement( const XMLElementDecl& elemDecl
  969. , const unsigned int elemURLId
  970. , const XMLCh* const elemPrefix
  971. , const RefVectorOf<XMLAttr>& attrList
  972. , const unsigned int attrCount
  973. , const bool isEmpty
  974. , const bool isRoot)
  975. {
  976. // Bump the element depth counter if not empty
  977. if (!isEmpty)
  978. fElemDepth++;
  979. if (fDocHandler)
  980. {
  981. fAttrList.setVector(&attrList, attrCount);
  982. if (fScanner->getDoNamespaces()) {
  983. if (elemPrefix && *elemPrefix) {
  984. fElemQNameBuf.set(elemPrefix);
  985. fElemQNameBuf.append(chColon);
  986. fElemQNameBuf.append(elemDecl.getBaseName());
  987. fDocHandler->startElement(fElemQNameBuf.getRawBuffer(), fAttrList);
  988. // If its empty, send the end tag event now
  989. if (isEmpty)
  990. fDocHandler->endElement(fElemQNameBuf.getRawBuffer());
  991. }
  992. else {
  993. fDocHandler->startElement(elemDecl.getBaseName(), fAttrList);
  994. // If its empty, send the end tag event now
  995. if (isEmpty)
  996. fDocHandler->endElement(elemDecl.getBaseName());
  997. }
  998. }
  999. else {
  1000. fDocHandler->startElement(elemDecl.getFullName(), fAttrList);
  1001. // If its empty, send the end tag event now
  1002. if (isEmpty)
  1003. fDocHandler->endElement(elemDecl.getFullName());
  1004. }
  1005. }
  1006. //
  1007. // If there are any installed advanced handlers, then lets call them
  1008. // with this info.
  1009. //
  1010. for (unsigned int index = 0; index < fAdvDHCount; index++)
  1011. {
  1012. fAdvDHList[index]->startElement
  1013. (
  1014. elemDecl
  1015. , elemURLId
  1016. , elemPrefix
  1017. , attrList
  1018. , attrCount
  1019. , isEmpty
  1020. , isRoot
  1021. );
  1022. }
  1023. }
  1024. void SAXParser::startEntityReference(const XMLEntityDecl& entityDecl)
  1025. {
  1026. //
  1027. // SAX has no way to report this. But, If there are any installed
  1028. // advanced handlers, then lets call them with this info.
  1029. //
  1030. for (unsigned int index = 0; index < fAdvDHCount; index++)
  1031. fAdvDHList[index]->startEntityReference(entityDecl);
  1032. }
  1033. // ---------------------------------------------------------------------------
  1034. // SAXParser: Overrides of the DocTypeHandler interface
  1035. // ---------------------------------------------------------------------------
  1036. void SAXParser::attDef( const DTDElementDecl& elemDecl
  1037. , const DTDAttDef& attDef
  1038. , const bool ignoring)
  1039. {
  1040. // Unused by SAX DTDHandler interface at this time
  1041. }
  1042. void SAXParser::doctypeComment(const XMLCh* const)
  1043. {
  1044. // Unused by SAX DTDHandler interface at this time
  1045. }
  1046. void SAXParser::doctypeDecl(const DTDElementDecl& elemDecl
  1047. , const XMLCh* const publicId
  1048. , const XMLCh* const systemId
  1049. , const bool hasIntSubset
  1050. , const bool hasExtSubset)
  1051. {
  1052. // Unused by SAX DTDHandler interface at this time
  1053. }
  1054. void SAXParser::doctypePI( const XMLCh* const
  1055. , const XMLCh* const)
  1056. {
  1057. // Unused by SAX DTDHandler interface at this time
  1058. }
  1059. void SAXParser::doctypeWhitespace( const XMLCh* const chars
  1060. , const unsigned int length)
  1061. {
  1062. // Unused by SAX DTDHandler interface at this time
  1063. }
  1064. void SAXParser::elementDecl(const DTDElementDecl&, const bool)
  1065. {
  1066. // Unused by SAX DTDHandler interface at this time
  1067. }
  1068. void SAXParser::endAttList(const DTDElementDecl&)
  1069. {
  1070. // Unused by SAX DTDHandler interface at this time
  1071. }
  1072. void SAXParser::endIntSubset()
  1073. {
  1074. // Unused by SAX DTDHandler interface at this time
  1075. }
  1076. void SAXParser::endExtSubset()
  1077. {
  1078. // Unused by SAX DTDHandler interface at this time
  1079. }
  1080. void SAXParser::entityDecl( const DTDEntityDecl& entityDecl
  1081. , const bool isPEDecl
  1082. , const bool isIgnored)
  1083. {
  1084. //
  1085. // If we have a DTD handler, and this entity is not ignored, and
  1086. // its an unparsed entity, then send this one.
  1087. //
  1088. if (fDTDHandler && !isIgnored)
  1089. {
  1090. if (entityDecl.isUnparsed())
  1091. {
  1092. fDTDHandler->unparsedEntityDecl
  1093. (
  1094. entityDecl.getName()
  1095. , entityDecl.getPublicId()
  1096. , entityDecl.getSystemId()
  1097. , entityDecl.getNotationName()
  1098. );
  1099. }
  1100. }
  1101. }
  1102. void SAXParser::resetDocType()
  1103. {
  1104. // Just map to the DTD handler
  1105. if (fDTDHandler)
  1106. fDTDHandler->resetDocType();
  1107. }
  1108. void SAXParser::notationDecl( const XMLNotationDecl& notDecl
  1109. , const bool isIgnored)
  1110. {
  1111. if (fDTDHandler && !isIgnored)
  1112. {
  1113. fDTDHandler->notationDecl
  1114. (
  1115. notDecl.getName()
  1116. , notDecl.getPublicId()
  1117. , notDecl.getSystemId()
  1118. );
  1119. }
  1120. }
  1121. void SAXParser::startAttList(const DTDElementDecl&)
  1122. {
  1123. // Unused by SAX DTDHandler interface at this time
  1124. }
  1125. void SAXParser::startIntSubset()
  1126. {
  1127. // Unused by SAX DTDHandler interface at this time
  1128. }
  1129. void SAXParser::startExtSubset()
  1130. {
  1131. // Unused by SAX DTDHandler interface at this time
  1132. }
  1133. void SAXParser::TextDecl( const XMLCh* const
  1134. , const XMLCh* const)
  1135. {
  1136. // Unused by SAX DTDHandler interface at this time
  1137. }
  1138. // ---------------------------------------------------------------------------
  1139. // SAXParser: Overrides of the XMLErrorReporter interface
  1140. // ---------------------------------------------------------------------------
  1141. void SAXParser::resetErrors()
  1142. {
  1143. if (fErrorHandler)
  1144. fErrorHandler->resetErrors();
  1145. }
  1146. void SAXParser::error( const unsigned int code
  1147. , const XMLCh* const msgDomain
  1148. , const XMLErrorReporter::ErrTypes errType
  1149. , const XMLCh* const errorText
  1150. , const XMLCh* const systemId
  1151. , const XMLCh* const publicId
  1152. , const XMLSSize_t lineNum
  1153. , const XMLSSize_t colNum)
  1154. {
  1155. SAXParseException toThrow = SAXParseException
  1156. (
  1157. errorText
  1158. , publicId
  1159. , systemId
  1160. , lineNum
  1161. , colNum
  1162. , fMemoryManager
  1163. );
  1164. if (!fErrorHandler)
  1165. {
  1166. if (errType == XMLErrorReporter::ErrType_Fatal)
  1167. throw toThrow;
  1168. else
  1169. return;
  1170. }
  1171. if (errType == XMLErrorReporter::ErrType_Warning)
  1172. fErrorHandler->warning(toThrow);
  1173. else if (errType == XMLErrorReporter::ErrType_Fatal)
  1174. fErrorHandler->fatalError(toThrow);
  1175. else
  1176. fErrorHandler->error(toThrow);
  1177. }
  1178. // ---------------------------------------------------------------------------
  1179. // SAXParser: Handlers for the XMLEntityHandler interface
  1180. // ---------------------------------------------------------------------------
  1181. void SAXParser::endInputSource(const InputSource&)
  1182. {
  1183. }
  1184. bool SAXParser::expandSystemId(const XMLCh* const, XMLBuffer&)
  1185. {
  1186. return false;
  1187. }
  1188. void SAXParser::resetEntities()
  1189. {
  1190. // Nothing to do for this one
  1191. }
  1192. InputSource*
  1193. SAXParser::resolveEntity( const XMLCh* const publicId
  1194. , const XMLCh* const systemId
  1195. , const XMLCh* const baseURI)
  1196. {
  1197. // Just map to the SAX entity resolver handler
  1198. if (fEntityResolver)
  1199. return fEntityResolver->resolveEntity(publicId, systemId);
  1200. return 0;
  1201. }
  1202. InputSource*
  1203. SAXParser::resolveEntity( XMLResourceIdentifier* resourceIdentifier )
  1204. {
  1205. // Just map to the SAX entity resolver handler
  1206. if (fEntityResolver)
  1207. return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
  1208. resourceIdentifier->getSystemId());
  1209. if (fXMLEntityResolver)
  1210. return fXMLEntityResolver->resolveEntity(resourceIdentifier);
  1211. return 0;
  1212. }
  1213. void SAXParser::startInputSource(const InputSource&)
  1214. {
  1215. // Nothing to do for this one
  1216. }
  1217. // ---------------------------------------------------------------------------
  1218. // SAXParser: Deprecated methods
  1219. // ---------------------------------------------------------------------------
  1220. bool SAXParser::getDoValidation() const
  1221. {
  1222. //
  1223. // We don't want to tie the public parser classes to the enum used
  1224. // by the scanner, so we use a separate one and map.
  1225. //
  1226. // DON'T mix the new and old methods!!
  1227. //
  1228. const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme();
  1229. if (scheme == XMLScanner::Val_Always)
  1230. return true;
  1231. return false;
  1232. }
  1233. void SAXParser::setDoValidation(const bool newState)
  1234. {
  1235. fScanner->setDoValidation
  1236. (
  1237. newState ? XMLScanner::Val_Always : XMLScanner::Val_Never
  1238. );
  1239. }
  1240. // ---------------------------------------------------------------------------
  1241. // SAXParser: Grammar preparsing methods
  1242. // ---------------------------------------------------------------------------
  1243. Grammar* SAXParser::loadGrammar(const char* const systemId,
  1244. const short grammarType,
  1245. const bool toCache)
  1246. {
  1247. // Avoid multiple entrance
  1248. if (fParseInProgress)
  1249. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  1250. Grammar* grammar = 0;
  1251. try
  1252. {
  1253. fParseInProgress = true;
  1254. grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
  1255. fParseInProgress = false;
  1256. }
  1257. catch(const OutOfMemoryException&)
  1258. {
  1259. throw;
  1260. }
  1261. catch(...)
  1262. {
  1263. fParseInProgress = false;
  1264. throw;
  1265. }
  1266. return grammar;
  1267. }
  1268. Grammar* SAXParser::loadGrammar(const XMLCh* const systemId,
  1269. const short grammarType,
  1270. const bool toCache)
  1271. {
  1272. // Avoid multiple entrance
  1273. if (fParseInProgress)
  1274. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  1275. Grammar* grammar = 0;
  1276. try
  1277. {
  1278. fParseInProgress = true;
  1279. grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
  1280. fParseInProgress = false;
  1281. }
  1282. catch(const OutOfMemoryException&)
  1283. {
  1284. throw;
  1285. }
  1286. catch(...)
  1287. {
  1288. fParseInProgress = false;
  1289. throw;
  1290. }
  1291. return grammar;
  1292. }
  1293. Grammar* SAXParser::loadGrammar(const InputSource& source,
  1294. const short grammarType,
  1295. const bool toCache)
  1296. {
  1297. // Avoid multiple entrance
  1298. if (fParseInProgress)
  1299. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  1300. Grammar* grammar = 0;
  1301. try
  1302. {
  1303. fParseInProgress = true;
  1304. grammar = fScanner->loadGrammar(source, grammarType, toCache);
  1305. fParseInProgress = false;
  1306. }
  1307. catch(const OutOfMemoryException&)
  1308. {
  1309. throw;
  1310. }
  1311. catch(...)
  1312. {
  1313. fParseInProgress = false;
  1314. throw;
  1315. }
  1316. return grammar;
  1317. }
  1318. void SAXParser::resetCachedGrammarPool()
  1319. {
  1320. fGrammarResolver->resetCachedGrammar();
  1321. }
  1322. XERCES_CPP_NAMESPACE_END