PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://atf2flightsim.googlecode.com/
C++ | 726 lines | 536 code | 83 blank | 107 comment | 236 complexity | e327d00aa330b74e581845a6730009df 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) 2002, 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) 2001, 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. * This file contains code to build the DOM tree. It registers a document
  58. * handler with the scanner. In these handler methods, appropriate DOM nodes
  59. * are created and added to the DOM tree.
  60. *
  61. * $Id: DOMBuilderImpl.cpp,v 1.1.1.1 2009/03/14 06:42:54 whitegr Exp $
  62. *
  63. */
  64. // ---------------------------------------------------------------------------
  65. // Includes
  66. // ---------------------------------------------------------------------------
  67. #include <xercesc/parsers/DOMBuilderImpl.hpp>
  68. #include <xercesc/util/IOException.hpp>
  69. #include <xercesc/dom/DOMEntityResolver.hpp>
  70. #include <xercesc/dom/DOMErrorHandler.hpp>
  71. #include <xercesc/dom/impl/DOMErrorImpl.hpp>
  72. #include <xercesc/dom/impl/DOMLocatorImpl.hpp>
  73. #include <xercesc/dom/DOMException.hpp>
  74. #include <xercesc/sax/SAXParseException.hpp>
  75. #include <xercesc/internal/XMLScanner.hpp>
  76. #include <xercesc/framework/Wrapper4DOMInputSource.hpp>
  77. #include <xercesc/framework/XMLGrammarPool.hpp>
  78. #include <xercesc/framework/XMLSchemaDescription.hpp>
  79. #include <xercesc/util/Janitor.hpp>
  80. #include <xercesc/validators/common/GrammarResolver.hpp>
  81. #include <xercesc/util/OutOfMemoryException.hpp>
  82. #include <xercesc/util/XMLEntityResolver.hpp>
  83. XERCES_CPP_NAMESPACE_BEGIN
  84. // ---------------------------------------------------------------------------
  85. // DOMBuilderImpl: Constructors and Destructor
  86. // ---------------------------------------------------------------------------
  87. DOMBuilderImpl::DOMBuilderImpl( XMLValidator* const valToAdopt
  88. , MemoryManager* const manager
  89. , XMLGrammarPool* const gramPool) :
  90. AbstractDOMParser(valToAdopt, manager, gramPool)
  91. , fAutoValidation(false)
  92. , fValidation(false)
  93. , fErrorHandler(0)
  94. , fEntityResolver(0)
  95. , fXMLEntityResolver(0)
  96. , fFilter(0)
  97. , fCharsetOverridesXMLEncoding(true)
  98. , fUserAdoptsDocument(false)
  99. {
  100. // dom spec has different default from scanner's default, so set explicitly
  101. getScanner()->setNormalizeData(false);
  102. }
  103. DOMBuilderImpl::~DOMBuilderImpl()
  104. {
  105. }
  106. // ---------------------------------------------------------------------------
  107. // DOMBuilderImpl: Setter methods
  108. // ---------------------------------------------------------------------------
  109. void DOMBuilderImpl::setErrorHandler(DOMErrorHandler* const handler)
  110. {
  111. fErrorHandler = handler;
  112. if (fErrorHandler) {
  113. getScanner()->setErrorReporter(this);
  114. }
  115. else {
  116. getScanner()->setErrorReporter(0);
  117. }
  118. }
  119. void DOMBuilderImpl::setEntityResolver(DOMEntityResolver* const handler)
  120. {
  121. fEntityResolver = handler;
  122. if (fEntityResolver) {
  123. getScanner()->setEntityHandler(this);
  124. fXMLEntityResolver = 0;
  125. }
  126. else {
  127. getScanner()->setEntityHandler(0);
  128. }
  129. }
  130. void DOMBuilderImpl::setXMLEntityResolver(XMLEntityResolver* const handler)
  131. {
  132. fXMLEntityResolver = handler;
  133. if (fXMLEntityResolver) {
  134. getScanner()->setEntityHandler(this);
  135. fEntityResolver = 0;
  136. }
  137. else {
  138. getScanner()->setEntityHandler(0);
  139. }
  140. }
  141. void DOMBuilderImpl::setFilter(DOMBuilderFilter* const filter)
  142. {
  143. throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  144. }
  145. // ---------------------------------------------------------------------------
  146. // DOMBuilderImpl: Feature methods
  147. // ---------------------------------------------------------------------------
  148. void DOMBuilderImpl::setFeature(const XMLCh* const name, const bool state)
  149. {
  150. if (XMLString::compareIString(name, XMLUni::fgDOMEntities) == 0) {
  151. setCreateEntityReferenceNodes(state);
  152. }
  153. else if (XMLString::compareIString(name, XMLUni::fgDOMComments) == 0) {
  154. setCreateCommentNodes(state);
  155. }
  156. else if (XMLString::compareIString(name, XMLUni::fgDOMDatatypeNormalization) == 0) {
  157. getScanner()->setNormalizeData(state);
  158. }
  159. else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaces) == 0) {
  160. setDoNamespaces(state);
  161. }
  162. else if (XMLString::compareIString(name, XMLUni::fgDOMWhitespaceInElementContent) == 0) {
  163. setIncludeIgnorableWhitespace(state);
  164. }
  165. else if (XMLString::compareIString(name, XMLUni::fgDOMValidation) == 0) {
  166. fValidation = state;
  167. if (state) {
  168. if (getValidationScheme() == AbstractDOMParser::Val_Never)
  169. setValidationScheme(AbstractDOMParser::Val_Always);
  170. }
  171. else {
  172. setValidationScheme(AbstractDOMParser::Val_Never);
  173. }
  174. }
  175. else if (XMLString::compareIString(name, XMLUni::fgDOMValidateIfSchema) == 0) {
  176. fAutoValidation = state;
  177. if (state) {
  178. setValidationScheme(AbstractDOMParser::Val_Auto);
  179. }
  180. else {
  181. setValidationScheme(AbstractDOMParser::Val_Never);
  182. }
  183. }
  184. else if (XMLString::compareIString(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) {
  185. // in fact, setting this has no effect to the parser
  186. fCharsetOverridesXMLEncoding = state;
  187. }
  188. else if (XMLString::compareIString(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0 ||
  189. XMLString::compareIString(name, XMLUni::fgDOMInfoset) == 0 ||
  190. XMLString::compareIString(name, XMLUni::fgDOMCanonicalForm) == 0 ) {
  191. if (state)
  192. throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  193. }
  194. else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaceDeclarations) == 0 ||
  195. XMLString::compareIString(name, XMLUni::fgDOMCDATASections) == 0 ) {
  196. if (!state)
  197. throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  198. }
  199. else if (XMLString::compareIString(name, XMLUni::fgXercesSchema) == 0)
  200. {
  201. setDoSchema(state);
  202. }
  203. else if (XMLString::compareIString(name, XMLUni::fgXercesSchemaFullChecking) == 0)
  204. {
  205. setValidationSchemaFullChecking(state);
  206. }
  207. else if (XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0)
  208. {
  209. if(state)
  210. fUserAdoptsDocument = true;
  211. else
  212. fUserAdoptsDocument = false;
  213. }
  214. else if (XMLString::compareIString(name, XMLUni::fgXercesLoadExternalDTD) == 0)
  215. {
  216. setLoadExternalDTD(state);
  217. }
  218. else if (XMLString::compareIString(name, XMLUni::fgXercesContinueAfterFatalError) == 0)
  219. {
  220. setExitOnFirstFatalError(!state);
  221. }
  222. else if (XMLString::compareIString(name, XMLUni::fgXercesValidationErrorAsFatal) == 0)
  223. {
  224. setValidationConstraintFatal(state);
  225. }
  226. else if (XMLString::compareIString(name, XMLUni::fgXercesCacheGrammarFromParse) == 0)
  227. {
  228. getScanner()->cacheGrammarFromParse(state);
  229. if (state)
  230. getScanner()->useCachedGrammarInParse(state);
  231. }
  232. else if (XMLString::compareIString(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0)
  233. {
  234. if (state || !getScanner()->isCachingGrammarFromParse())
  235. getScanner()->useCachedGrammarInParse(state);
  236. }
  237. else if (XMLString::compareIString(name, XMLUni::fgXercesCalculateSrcOfs) == 0)
  238. {
  239. getScanner()->setCalculateSrcOfs(state);
  240. }
  241. else if (XMLString::compareIString(name, XMLUni::fgXercesStandardUriConformant) == 0)
  242. {
  243. getScanner()->setStandardUriConformant(state);
  244. }
  245. else {
  246. throw DOMException(DOMException::NOT_FOUND_ERR, 0);
  247. }
  248. }
  249. bool DOMBuilderImpl::getFeature(const XMLCh* const name) const
  250. {
  251. if (XMLString::compareIString(name, XMLUni::fgDOMEntities) == 0) {
  252. return getCreateEntityReferenceNodes();
  253. }
  254. else if (XMLString::compareIString(name, XMLUni::fgDOMComments) == 0) {
  255. return getCreateCommentNodes();
  256. }
  257. else if (XMLString::compareIString(name, XMLUni::fgDOMDatatypeNormalization) == 0) {
  258. return getScanner()->getNormalizeData();
  259. }
  260. else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaces) == 0) {
  261. return getDoNamespaces();
  262. }
  263. else if (XMLString::compareIString(name, XMLUni::fgDOMWhitespaceInElementContent) == 0) {
  264. return getIncludeIgnorableWhitespace();
  265. }
  266. else if (XMLString::compareIString(name, XMLUni::fgDOMValidation) == 0) {
  267. return fValidation;
  268. }
  269. else if (XMLString::compareIString(name, XMLUni::fgDOMValidateIfSchema) == 0) {
  270. return fAutoValidation;
  271. }
  272. else if (XMLString::compareIString(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) {
  273. return fCharsetOverridesXMLEncoding;
  274. }
  275. else if (XMLString::compareIString(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0 ||
  276. XMLString::compareIString(name, XMLUni::fgDOMInfoset) == 0 ||
  277. XMLString::compareIString(name, XMLUni::fgDOMCanonicalForm) == 0 ) {
  278. return false;
  279. }
  280. else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaceDeclarations) == 0 ||
  281. XMLString::compareIString(name, XMLUni::fgDOMCDATASections) == 0 ) {
  282. return true;
  283. }
  284. else if (XMLString::compareIString(name, XMLUni::fgXercesSchema) == 0)
  285. {
  286. return getDoSchema();
  287. }
  288. else if (XMLString::compareIString(name, XMLUni::fgXercesSchemaFullChecking) == 0)
  289. {
  290. return getValidationSchemaFullChecking();
  291. }
  292. else if (XMLString::compareIString(name, XMLUni::fgXercesLoadExternalDTD) == 0)
  293. {
  294. return getLoadExternalDTD();
  295. }
  296. else if (XMLString::compareIString(name, XMLUni::fgXercesContinueAfterFatalError) == 0)
  297. {
  298. return !getExitOnFirstFatalError();
  299. }
  300. else if (XMLString::compareIString(name, XMLUni::fgXercesValidationErrorAsFatal) == 0)
  301. {
  302. return getValidationConstraintFatal();
  303. }
  304. else if (XMLString::compareIString(name, XMLUni::fgXercesCacheGrammarFromParse) == 0)
  305. {
  306. return getScanner()->isCachingGrammarFromParse();
  307. }
  308. else if (XMLString::compareIString(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0)
  309. {
  310. return getScanner()->isUsingCachedGrammarInParse();
  311. }
  312. else if (XMLString::compareIString(name, XMLUni::fgXercesCalculateSrcOfs) == 0)
  313. {
  314. return getScanner()->getCalculateSrcOfs();
  315. }
  316. else if (XMLString::compareIString(name, XMLUni::fgXercesStandardUriConformant) == 0)
  317. {
  318. return getScanner()->getStandardUriConformant();
  319. }
  320. else if(XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) {
  321. return fUserAdoptsDocument;
  322. }
  323. else {
  324. throw DOMException(DOMException::NOT_FOUND_ERR, 0);
  325. }
  326. return false;
  327. }
  328. bool DOMBuilderImpl::canSetFeature(const XMLCh* const name, const bool state) const
  329. {
  330. if ((XMLString::compareIString(name, XMLUni::fgDOMEntities) == 0) ||
  331. (XMLString::compareIString(name, XMLUni::fgDOMComments) == 0) ||
  332. (XMLString::compareIString(name, XMLUni::fgDOMDatatypeNormalization) == 0) ||
  333. (XMLString::compareIString(name, XMLUni::fgDOMNamespaces) == 0) ||
  334. (XMLString::compareIString(name, XMLUni::fgDOMValidation) == 0) ||
  335. (XMLString::compareIString(name, XMLUni::fgDOMValidateIfSchema) == 0) ||
  336. (XMLString::compareIString(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) ||
  337. (XMLString::compareIString(name, XMLUni::fgDOMWhitespaceInElementContent) == 0) ||
  338. (XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) ||
  339. (XMLString::compareIString(name, XMLUni::fgXercesCalculateSrcOfs) == 0) ||
  340. (XMLString::compareIString(name, XMLUni::fgXercesStandardUriConformant) == 0)) {
  341. return true;
  342. }
  343. else if (XMLString::compareIString(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0 ||
  344. XMLString::compareIString(name, XMLUni::fgDOMInfoset) == 0 ||
  345. XMLString::compareIString(name, XMLUni::fgDOMCanonicalForm) == 0 ) {
  346. if (!state)
  347. return true;
  348. }
  349. else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaceDeclarations) == 0 ||
  350. XMLString::compareIString(name, XMLUni::fgDOMCDATASections) == 0 ) {
  351. if (state)
  352. return true;
  353. }
  354. else if ((XMLString::compareIString(name, XMLUni::fgXercesSchema) == 0) ||
  355. (XMLString::compareIString(name, XMLUni::fgXercesSchemaFullChecking) == 0) ||
  356. (XMLString::compareIString(name, XMLUni::fgXercesLoadExternalDTD) == 0) ||
  357. (XMLString::compareIString(name, XMLUni::fgXercesContinueAfterFatalError) == 0) ||
  358. (XMLString::compareIString(name, XMLUni::fgXercesValidationErrorAsFatal) == 0) ||
  359. (XMLString::compareIString(name, XMLUni::fgXercesCacheGrammarFromParse) == 0) ||
  360. (XMLString::compareIString(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0)) {
  361. return true;
  362. }
  363. return false;
  364. }
  365. // ---------------------------------------------------------------------------
  366. // DOMBuilderImpl: Non standard extension
  367. // ---------------------------------------------------------------------------
  368. void DOMBuilderImpl::setProperty(const XMLCh* const name, void* value)
  369. {
  370. if (XMLString::compareIString(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0)
  371. {
  372. setExternalSchemaLocation((XMLCh*)value);
  373. }
  374. else if (XMLString::compareIString(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0)
  375. {
  376. setExternalNoNamespaceSchemaLocation((XMLCh*)value);
  377. }
  378. else if (XMLString::compareIString(name, XMLUni::fgXercesSecurityManager) == 0)
  379. {
  380. setSecurityManager((SecurityManager*)value);
  381. }
  382. else if (XMLString::equals(name, XMLUni::fgXercesScannerName))
  383. {
  384. AbstractDOMParser::useScanner((const XMLCh*) value);
  385. }
  386. else if (XMLString::equals(name, XMLUni::fgXercesParserUseDocumentFromImplementation))
  387. {
  388. useImplementation((const XMLCh*) value);
  389. }
  390. else
  391. throw DOMException(DOMException::NOT_FOUND_ERR, 0);
  392. }
  393. void* DOMBuilderImpl::getProperty(const XMLCh* const name) const
  394. {
  395. if (XMLString::compareIString(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0)
  396. return (void*)getExternalSchemaLocation();
  397. else if (XMLString::compareIString(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0)
  398. return (void*)getExternalNoNamespaceSchemaLocation();
  399. else if (XMLString::compareIString(name, XMLUni::fgXercesSecurityManager) == 0)
  400. return (void*)getSecurityManager();
  401. else
  402. throw DOMException(DOMException::NOT_FOUND_ERR, 0);
  403. return 0;
  404. }
  405. void DOMBuilderImpl::release()
  406. {
  407. DOMBuilderImpl* builder = (DOMBuilderImpl*) this;
  408. delete builder;
  409. }
  410. void DOMBuilderImpl::resetDocumentPool()
  411. {
  412. resetPool();
  413. }
  414. // ---------------------------------------------------------------------------
  415. // DOMBuilderImpl: Parsing methods
  416. // ---------------------------------------------------------------------------
  417. DOMDocument* DOMBuilderImpl::parse(const DOMInputSource& source)
  418. {
  419. Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false, getMemoryManager());
  420. AbstractDOMParser::parse(isWrapper);
  421. if (fUserAdoptsDocument)
  422. return adoptDocument();
  423. else
  424. return getDocument();
  425. }
  426. DOMDocument* DOMBuilderImpl::parseURI(const XMLCh* const systemId)
  427. {
  428. AbstractDOMParser::parse(systemId);
  429. if (fUserAdoptsDocument)
  430. return adoptDocument();
  431. else
  432. return getDocument();
  433. }
  434. DOMDocument* DOMBuilderImpl::parseURI(const char* const systemId)
  435. {
  436. AbstractDOMParser::parse(systemId);
  437. if (fUserAdoptsDocument)
  438. return adoptDocument();
  439. else
  440. return getDocument();
  441. }
  442. void DOMBuilderImpl::parseWithContext(const DOMInputSource& source,
  443. DOMNode* const contextNode,
  444. const short action)
  445. {
  446. throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  447. }
  448. // ---------------------------------------------------------------------------
  449. // DOMBuilderImpl: Implementation of the XMLErrorReporter interface
  450. // ---------------------------------------------------------------------------
  451. void DOMBuilderImpl::error( const unsigned int code
  452. , const XMLCh* const msgDomain
  453. , const XMLErrorReporter::ErrTypes errType
  454. , const XMLCh* const errorText
  455. , const XMLCh* const systemId
  456. , const XMLCh* const publicId
  457. , const XMLSSize_t lineNum
  458. , const XMLSSize_t colNum)
  459. {
  460. if (fErrorHandler) {
  461. short severity = DOMError::DOM_SEVERITY_ERROR;
  462. if (errType == XMLErrorReporter::ErrType_Warning)
  463. severity = DOMError::DOM_SEVERITY_WARNING;
  464. else if (errType == XMLErrorReporter::ErrType_Fatal)
  465. severity = DOMError::DOM_SEVERITY_FATAL_ERROR;
  466. DOMLocatorImpl location((int)lineNum, (int) colNum, getCurrentNode(), systemId);
  467. DOMErrorImpl domError(severity, errorText, &location);
  468. // if user return false, we should stop the process, so throw an error
  469. if (!fErrorHandler->handleError(domError) && !getScanner()->getInException())
  470. throw (XMLErrs::Codes) code;
  471. }
  472. }
  473. void DOMBuilderImpl::resetErrors()
  474. {
  475. }
  476. // ---------------------------------------------------------------------------
  477. // DOMBuilderImpl: Implementation of XMLEntityHandler interface
  478. // ---------------------------------------------------------------------------
  479. InputSource*
  480. DOMBuilderImpl::resolveEntity(const XMLCh* const publicId,
  481. const XMLCh* const systemId,
  482. const XMLCh* const baseURI)
  483. {
  484. //
  485. // Just map it to the SAX entity resolver. If there is not one installed,
  486. // return a null pointer to cause the default resolution.
  487. //
  488. if (fEntityResolver) {
  489. DOMInputSource* is = fEntityResolver->resolveEntity(publicId, systemId, baseURI);
  490. if (is)
  491. return new Wrapper4DOMInputSource(is, true, getMemoryManager());
  492. }
  493. return 0;
  494. }
  495. InputSource*
  496. DOMBuilderImpl::resolveEntity( XMLResourceIdentifier* resourceIdentifier )
  497. {
  498. //
  499. // Just map it to the SAX entity resolver. If there is not one installed,
  500. // return a null pointer to cause the default resolution.
  501. //
  502. if (fEntityResolver) {
  503. DOMInputSource* is = fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
  504. resourceIdentifier->getSystemId(),
  505. resourceIdentifier->getBaseURI());
  506. if (is)
  507. return new Wrapper4DOMInputSource(is, true, getMemoryManager());
  508. }
  509. if (fXMLEntityResolver) {
  510. return(fXMLEntityResolver->resolveEntity(resourceIdentifier));
  511. }
  512. return 0;
  513. }
  514. // ---------------------------------------------------------------------------
  515. // DOMBuilderImpl: Grammar preparsing methods
  516. // ---------------------------------------------------------------------------
  517. Grammar* DOMBuilderImpl::loadGrammar(const char* const systemId,
  518. const short grammarType,
  519. const bool toCache)
  520. {
  521. // Avoid multiple entrance
  522. if (getParseInProgress())
  523. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  524. Grammar* grammar = 0;
  525. try
  526. {
  527. setParseInProgress(true);
  528. if (grammarType == Grammar::DTDGrammarType)
  529. getScanner()->setDocTypeHandler(0);
  530. grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
  531. // Release DOM tree - DTD
  532. DOMDocument* doc = adoptDocument();
  533. if (doc)
  534. doc->release();
  535. if (grammarType == Grammar::DTDGrammarType)
  536. getScanner()->setDocTypeHandler(this);
  537. setParseInProgress(false);
  538. }
  539. catch(const OutOfMemoryException&)
  540. {
  541. throw;
  542. }
  543. catch(...)
  544. {
  545. if (grammarType == Grammar::DTDGrammarType)
  546. getScanner()->setDocTypeHandler(this);
  547. setParseInProgress(false);
  548. throw;
  549. }
  550. return grammar;
  551. }
  552. Grammar* DOMBuilderImpl::loadGrammar(const XMLCh* const systemId,
  553. const short grammarType,
  554. const bool toCache)
  555. {
  556. // Avoid multiple entrance
  557. if (getParseInProgress())
  558. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  559. Grammar* grammar = 0;
  560. try
  561. {
  562. setParseInProgress(true);
  563. if (grammarType == Grammar::DTDGrammarType)
  564. getScanner()->setDocTypeHandler(0);
  565. grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
  566. // Release DOM tree - DTD
  567. DOMDocument* doc = adoptDocument();
  568. if (doc)
  569. doc->release();
  570. if (grammarType == Grammar::DTDGrammarType)
  571. getScanner()->setDocTypeHandler(this);
  572. setParseInProgress(false);
  573. }
  574. catch(const OutOfMemoryException&)
  575. {
  576. throw;
  577. }
  578. catch(...)
  579. {
  580. if (grammarType == Grammar::DTDGrammarType)
  581. getScanner()->setDocTypeHandler(this);
  582. setParseInProgress(false);
  583. throw;
  584. }
  585. return grammar;
  586. }
  587. Grammar* DOMBuilderImpl::loadGrammar(const DOMInputSource& source,
  588. const short grammarType,
  589. const bool toCache)
  590. {
  591. // Avoid multiple entrance
  592. if (getParseInProgress())
  593. ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
  594. Grammar* grammar = 0;
  595. try
  596. {
  597. Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false, getMemoryManager());
  598. setParseInProgress(true);
  599. if (grammarType == Grammar::DTDGrammarType)
  600. getScanner()->setDocTypeHandler(0);
  601. grammar = getScanner()->loadGrammar(isWrapper, grammarType, toCache);
  602. // Release DOM tree - DTD
  603. DOMDocument* doc = adoptDocument();
  604. if (doc)
  605. doc->release();
  606. if (grammarType == Grammar::DTDGrammarType)
  607. getScanner()->setDocTypeHandler(this);
  608. setParseInProgress(false);
  609. }
  610. catch(const OutOfMemoryException&)
  611. {
  612. throw;
  613. }
  614. catch(...)
  615. {
  616. if (grammarType == Grammar::DTDGrammarType)
  617. getScanner()->setDocTypeHandler(this);
  618. setParseInProgress(false);
  619. throw;
  620. }
  621. return grammar;
  622. }
  623. void DOMBuilderImpl::resetCachedGrammarPool()
  624. {
  625. getGrammarResolver()->resetCachedGrammar();
  626. }
  627. Grammar* DOMBuilderImpl::getGrammar(const XMLCh* const nameSpaceKey) const
  628. {
  629. return getGrammarResolver()->getGrammar(nameSpaceKey);
  630. }
  631. Grammar* DOMBuilderImpl::getRootGrammar() const
  632. {
  633. return getScanner()->getRootGrammar();
  634. }
  635. const XMLCh* DOMBuilderImpl::getURIText(unsigned int uriId) const
  636. {
  637. return getScanner()->getURIText(uriId);
  638. }
  639. unsigned int DOMBuilderImpl::getSrcOffset() const
  640. {
  641. return getScanner()->getSrcOffset();
  642. }
  643. XERCES_CPP_NAMESPACE_END