1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001-2004 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 2001, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.impl.xs.opti;
  58. import java.io.IOException;
  59. import java.util.Locale;
  60. import com.sun.org.apache.xerces.internal.impl.Constants;
  61. import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
  62. import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  63. import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  64. import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
  65. import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  66. import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  67. import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  68. import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
  69. import com.sun.org.apache.xerces.internal.parsers.BasicParserConfiguration;
  70. import com.sun.org.apache.xerces.internal.util.SymbolTable;
  71. import com.sun.org.apache.xerces.internal.xni.XMLLocator;
  72. import com.sun.org.apache.xerces.internal.xni.XNIException;
  73. import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  74. import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  75. import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  76. import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  77. import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  78. import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  79. import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  80. import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
  81. import org.w3c.dom.Document;
  82. /**
  83. * @author Rahul Srivastava, Sun Microsystems Inc.
  84. *
  85. * @version $Id: SchemaParsingConfig.java,v 1.5 2004/01/26 17:28:11 mrglavas Exp $
  86. */
  87. public class SchemaParsingConfig extends BasicParserConfiguration
  88. implements XMLPullParserConfiguration {
  89. //
  90. // Constants
  91. //
  92. // feature identifiers
  93. /** Feature identifier: warn on duplicate attribute definition. */
  94. protected static final String WARN_ON_DUPLICATE_ATTDEF =
  95. Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
  96. /** Feature identifier: warn on duplicate entity definition. */
  97. // protected static final String WARN_ON_DUPLICATE_ENTITYDEF = Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
  98. /** Feature identifier: warn on undeclared element definition. */
  99. protected static final String WARN_ON_UNDECLARED_ELEMDEF =
  100. Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
  101. /** Feature identifier: allow Java encodings. */
  102. protected static final String ALLOW_JAVA_ENCODINGS =
  103. Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
  104. /** Feature identifier: continue after fatal error. */
  105. protected static final String CONTINUE_AFTER_FATAL_ERROR =
  106. Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
  107. /** Feature identifier: load external DTD. */
  108. protected static final String LOAD_EXTERNAL_DTD =
  109. Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
  110. /** Feature identifier: notify built-in refereces. */
  111. protected static final String NOTIFY_BUILTIN_REFS =
  112. Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
  113. /** Feature identifier: notify character refereces. */
  114. protected static final String NOTIFY_CHAR_REFS =
  115. Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
  116. /** Feature identifier: expose schema normalized value */
  117. protected static final String NORMALIZE_DATA =
  118. Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
  119. /** Feature identifier: send element default value via characters() */
  120. protected static final String SCHEMA_ELEMENT_DEFAULT =
  121. Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
  122. // property identifiers
  123. /** Property identifier: error reporter. */
  124. protected static final String ERROR_REPORTER =
  125. Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
  126. /** Property identifier: entity manager. */
  127. protected static final String ENTITY_MANAGER =
  128. Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
  129. /** Property identifier document scanner: */
  130. protected static final String DOCUMENT_SCANNER =
  131. Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
  132. /** Property identifier: DTD scanner. */
  133. protected static final String DTD_SCANNER =
  134. Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
  135. /** Property identifier: grammar pool. */
  136. protected static final String XMLGRAMMAR_POOL =
  137. Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
  138. /** Property identifier: DTD validator. */
  139. protected static final String DTD_VALIDATOR =
  140. Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
  141. /** Property identifier: namespace binder. */
  142. protected static final String NAMESPACE_BINDER =
  143. Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
  144. /** Property identifier: datatype validator factory. */
  145. protected static final String DATATYPE_VALIDATOR_FACTORY =
  146. Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
  147. protected static final String VALIDATION_MANAGER =
  148. Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  149. /** Property identifier: XML Schema validator. */
  150. protected static final String SCHEMA_VALIDATOR =
  151. Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
  152. // debugging
  153. /** Set to true and recompile to print exception stack trace. */
  154. private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
  155. //
  156. // Data
  157. //
  158. // components (non-configurable)
  159. /** Grammar pool. */
  160. protected XMLGrammarPool fGrammarPool;
  161. /** Datatype validator factory. */
  162. protected DTDDVFactory fDatatypeValidatorFactory;
  163. // components (configurable)
  164. /** Error reporter. */
  165. protected XMLErrorReporter fErrorReporter;
  166. /** Entity manager. */
  167. protected XMLEntityManager fEntityManager;
  168. /** Document scanner. */
  169. protected XMLDocumentScanner fScanner;
  170. /** Input Source */
  171. protected XMLInputSource fInputSource;
  172. /** DTD scanner. */
  173. protected XMLDTDScanner fDTDScanner;
  174. protected SchemaDOMParser fSchemaDOMParser;
  175. protected ValidationManager fValidationManager;
  176. // state
  177. /** Locator */
  178. protected XMLLocator fLocator;
  179. /**
  180. * True if a parse is in progress. This state is needed because
  181. * some features/properties cannot be set while parsing (e.g.
  182. * validation and namespaces).
  183. */
  184. protected boolean fParseInProgress = false;
  185. //
  186. // Constructors
  187. //
  188. /** Default constructor. */
  189. public SchemaParsingConfig() {
  190. this(null, null, null);
  191. } // <init>()
  192. /**
  193. * Constructs a parser configuration using the specified symbol table.
  194. *
  195. * @param symbolTable The symbol table to use.
  196. */
  197. public SchemaParsingConfig(SymbolTable symbolTable) {
  198. this(symbolTable, null, null);
  199. } // <init>(SymbolTable)
  200. /**
  201. * Constructs a parser configuration using the specified symbol table and
  202. * grammar pool.
  203. * <p>
  204. * <strong>REVISIT:</strong>
  205. * Grammar pool will be updated when the new validation engine is
  206. * implemented.
  207. *
  208. * @param symbolTable The symbol table to use.
  209. * @param grammarPool The grammar pool to use.
  210. */
  211. public SchemaParsingConfig(SymbolTable symbolTable,
  212. XMLGrammarPool grammarPool) {
  213. this(symbolTable, grammarPool, null);
  214. } // <init>(SymbolTable,XMLGrammarPool)
  215. /**
  216. * Constructs a parser configuration using the specified symbol table,
  217. * grammar pool, and parent settings.
  218. * <p>
  219. * <strong>REVISIT:</strong>
  220. * Grammar pool will be updated when the new validation engine is
  221. * implemented.
  222. *
  223. * @param symbolTable The symbol table to use.
  224. * @param grammarPool The grammar pool to use.
  225. * @param parentSettings The parent settings.
  226. */
  227. public SchemaParsingConfig(SymbolTable symbolTable,
  228. XMLGrammarPool grammarPool,
  229. XMLComponentManager parentSettings) {
  230. super(symbolTable, parentSettings);
  231. // add default recognized features
  232. final String[] recognizedFeatures = {
  233. PARSER_SETTINGS, WARN_ON_DUPLICATE_ATTDEF, WARN_ON_UNDECLARED_ELEMDEF,
  234. ALLOW_JAVA_ENCODINGS, CONTINUE_AFTER_FATAL_ERROR,
  235. LOAD_EXTERNAL_DTD, NOTIFY_BUILTIN_REFS,
  236. NOTIFY_CHAR_REFS
  237. };
  238. addRecognizedFeatures(recognizedFeatures);
  239. fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
  240. // set state for default features
  241. fFeatures.put(WARN_ON_DUPLICATE_ATTDEF, Boolean.FALSE);
  242. //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
  243. fFeatures.put(WARN_ON_UNDECLARED_ELEMDEF, Boolean.FALSE);
  244. fFeatures.put(ALLOW_JAVA_ENCODINGS, Boolean.FALSE);
  245. fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
  246. fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
  247. fFeatures.put(NOTIFY_BUILTIN_REFS, Boolean.FALSE);
  248. fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
  249. // add default recognized properties
  250. final String[] recognizedProperties = {
  251. ERROR_REPORTER,
  252. ENTITY_MANAGER,
  253. DOCUMENT_SCANNER,
  254. DTD_SCANNER,
  255. DTD_VALIDATOR,
  256. NAMESPACE_BINDER,
  257. XMLGRAMMAR_POOL,
  258. DATATYPE_VALIDATOR_FACTORY,
  259. VALIDATION_MANAGER
  260. };
  261. addRecognizedProperties(recognizedProperties);
  262. fGrammarPool = grammarPool;
  263. if(fGrammarPool != null){
  264. setProperty(XMLGRAMMAR_POOL, fGrammarPool);
  265. }
  266. fEntityManager = new XMLEntityManager();
  267. fProperties.put(ENTITY_MANAGER, fEntityManager);
  268. addComponent(fEntityManager);
  269. fErrorReporter = new XMLErrorReporter();
  270. fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  271. fProperties.put(ERROR_REPORTER, fErrorReporter);
  272. addComponent(fErrorReporter);
  273. fScanner = new XMLNSDocumentScannerImpl();
  274. fProperties.put(DOCUMENT_SCANNER, fScanner);
  275. addComponent((XMLComponent)fScanner);
  276. fDTDScanner = new XMLDTDScannerImpl();
  277. fProperties.put(DTD_SCANNER, fDTDScanner);
  278. addComponent((XMLComponent)fDTDScanner);
  279. fDatatypeValidatorFactory = DTDDVFactory.getInstance();;
  280. fProperties.put(DATATYPE_VALIDATOR_FACTORY,
  281. fDatatypeValidatorFactory);
  282. fValidationManager = new ValidationManager();
  283. fProperties.put(VALIDATION_MANAGER, fValidationManager);
  284. // add message formatters
  285. if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
  286. XMLMessageFormatter xmft = new XMLMessageFormatter();
  287. fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
  288. fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
  289. }
  290. if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
  291. XSMessageFormatter xmft = new XSMessageFormatter();
  292. fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
  293. }
  294. // set locale
  295. try {
  296. setLocale(Locale.getDefault());
  297. }
  298. catch (XNIException e) {
  299. // do nothing
  300. // REVISIT: What is the right thing to do? -Ac
  301. }
  302. } // <init>(SymbolTable,XMLGrammarPool)
  303. //
  304. // Public methods
  305. //
  306. /**
  307. * Set the locale to use for messages.
  308. *
  309. * @param locale The locale object to use for localization of messages.
  310. *
  311. * @exception XNIException Thrown if the parser does not support the
  312. * specified locale.
  313. */
  314. public void setLocale(Locale locale) throws XNIException {
  315. super.setLocale(locale);
  316. fErrorReporter.setLocale(locale);
  317. } // setLocale(Locale)
  318. //
  319. // XMLPullParserConfiguration methods
  320. //
  321. // parsing
  322. /**
  323. * Sets the input source for the document to parse.
  324. *
  325. * @param inputSource The document's input source.
  326. *
  327. * @exception XMLConfigurationException Thrown if there is a
  328. * configuration error when initializing the
  329. * parser.
  330. * @exception IOException Thrown on I/O error.
  331. *
  332. * @see #parse(boolean)
  333. */
  334. public void setInputSource(XMLInputSource inputSource)
  335. throws XMLConfigurationException, IOException {
  336. // REVISIT: this method used to reset all the components and
  337. // construct the pipeline. Now reset() is called
  338. // in parse (boolean) just before we parse the document
  339. // Should this method still throw exceptions..?
  340. fInputSource = inputSource;
  341. } // setInputSource(XMLInputSource)
  342. /**
  343. * Parses the document in a pull parsing fashion.
  344. *
  345. * @param complete True if the pull parser should parse the
  346. * remaining document completely.
  347. *
  348. * @returns True if there is more document to parse.
  349. *
  350. * @exception XNIException Any XNI exception, possibly wrapping
  351. * another exception.
  352. * @exception IOException An IO exception from the parser, possibly
  353. * from a byte stream or character stream
  354. * supplied by the parser.
  355. *
  356. * @see #setInputSource
  357. */
  358. public boolean parse(boolean complete) throws XNIException, IOException {
  359. //
  360. // reset and configure pipeline and set InputSource.
  361. if (fInputSource !=null) {
  362. try {
  363. // resets and sets the pipeline.
  364. reset();
  365. fScanner.setInputSource(fInputSource);
  366. fInputSource = null;
  367. }
  368. catch (XNIException ex) {
  369. if (PRINT_EXCEPTION_STACK_TRACE)
  370. ex.printStackTrace();
  371. throw ex;
  372. }
  373. catch (IOException ex) {
  374. if (PRINT_EXCEPTION_STACK_TRACE)
  375. ex.printStackTrace();
  376. throw ex;
  377. }
  378. catch (RuntimeException ex) {
  379. if (PRINT_EXCEPTION_STACK_TRACE)
  380. ex.printStackTrace();
  381. throw ex;
  382. }
  383. catch (Exception ex) {
  384. if (PRINT_EXCEPTION_STACK_TRACE)
  385. ex.printStackTrace();
  386. throw new XNIException(ex);
  387. }
  388. }
  389. try {
  390. return fScanner.scanDocument(complete);
  391. }
  392. catch (XNIException ex) {
  393. if (PRINT_EXCEPTION_STACK_TRACE)
  394. ex.printStackTrace();
  395. throw ex;
  396. }
  397. catch (IOException ex) {
  398. if (PRINT_EXCEPTION_STACK_TRACE)
  399. ex.printStackTrace();
  400. throw ex;
  401. }
  402. catch (RuntimeException ex) {
  403. if (PRINT_EXCEPTION_STACK_TRACE)
  404. ex.printStackTrace();
  405. throw ex;
  406. }
  407. catch (Exception ex) {
  408. if (PRINT_EXCEPTION_STACK_TRACE)
  409. ex.printStackTrace();
  410. throw new XNIException(ex);
  411. }
  412. } // parse(boolean):boolean
  413. /**
  414. * If the application decides to terminate parsing before the xml document
  415. * is fully parsed, the application should call this method to free any
  416. * resource allocated during parsing. For example, close all opened streams.
  417. */
  418. public void cleanup() {
  419. fEntityManager.closeReaders();
  420. }
  421. //
  422. // XMLParserConfiguration methods
  423. //
  424. /**
  425. * Parses the specified input source.
  426. *
  427. * @param source The input source.
  428. *
  429. * @exception XNIException Throws exception on XNI error.
  430. * @exception java.io.IOException Throws exception on i/o error.
  431. */
  432. public void parse(XMLInputSource source) throws XNIException, IOException {
  433. if (fParseInProgress) {
  434. // REVISIT - need to add new error message
  435. throw new XNIException("FWK005 parse may not be called while parsing.");
  436. }
  437. fParseInProgress = true;
  438. try {
  439. setInputSource(source);
  440. parse(true);
  441. }
  442. catch (XNIException ex) {
  443. if (PRINT_EXCEPTION_STACK_TRACE)
  444. ex.printStackTrace();
  445. throw ex;
  446. }
  447. catch (IOException ex) {
  448. if (PRINT_EXCEPTION_STACK_TRACE)
  449. ex.printStackTrace();
  450. throw ex;
  451. }
  452. catch (RuntimeException ex) {
  453. if (PRINT_EXCEPTION_STACK_TRACE)
  454. ex.printStackTrace();
  455. throw ex;
  456. }
  457. catch (Exception ex) {
  458. if (PRINT_EXCEPTION_STACK_TRACE)
  459. ex.printStackTrace();
  460. throw new XNIException(ex);
  461. }
  462. finally {
  463. fParseInProgress = false;
  464. // close all streams opened by xerces
  465. this.cleanup();
  466. }
  467. } // parse(InputSource)
  468. //
  469. // Protected methods
  470. //
  471. /**
  472. * Reset all components before parsing.
  473. *
  474. * @throws XNIException Thrown if an error occurs during initialization.
  475. */
  476. public void reset() throws XNIException {
  477. // set handlers
  478. if (fSchemaDOMParser == null)
  479. fSchemaDOMParser = new SchemaDOMParser(fErrorReporter);
  480. fDocumentHandler = fSchemaDOMParser;
  481. fDTDHandler = fSchemaDOMParser;
  482. fDTDContentModelHandler = fSchemaDOMParser;
  483. // configure the pipeline and initialize the components
  484. configurePipeline();
  485. super.reset();
  486. } // reset()
  487. /** Configures the pipeline. */
  488. protected void configurePipeline() {
  489. // setup document pipeline
  490. fScanner.setDocumentHandler(fDocumentHandler);
  491. fDocumentHandler.setDocumentSource(fScanner);
  492. fLastComponent = fScanner;
  493. // setup dtd pipeline
  494. if (fDTDScanner != null) {
  495. fDTDScanner.setDTDHandler(fDTDHandler);
  496. fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
  497. }
  498. } // configurePipeline()
  499. // features and properties
  500. /**
  501. * Check a feature. If feature is know and supported, this method simply
  502. * returns. Otherwise, the appropriate exception is thrown.
  503. *
  504. * @param featureId The unique identifier (URI) of the feature.
  505. *
  506. * @throws XMLConfigurationException Thrown for configuration error.
  507. * In general, components should
  508. * only throw this exception if
  509. * it is <strong>really</strong>
  510. * a critical error.
  511. */
  512. protected void checkFeature(String featureId)
  513. throws XMLConfigurationException {
  514. //
  515. // Xerces Features
  516. //
  517. if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
  518. final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
  519. //
  520. // http://apache.org/xml/features/validation/dynamic
  521. // Allows the parser to validate a document only when it
  522. // contains a grammar. Validation is turned on/off based
  523. // on each document instance, automatically.
  524. //
  525. if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
  526. featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
  527. return;
  528. }
  529. //
  530. // http://apache.org/xml/features/validation/default-attribute-values
  531. //
  532. if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
  533. featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
  534. // REVISIT
  535. short type = XMLConfigurationException.NOT_SUPPORTED;
  536. throw new XMLConfigurationException(type, featureId);
  537. }
  538. //
  539. // http://apache.org/xml/features/validation/default-attribute-values
  540. //
  541. if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
  542. featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
  543. // REVISIT
  544. short type = XMLConfigurationException.NOT_SUPPORTED;
  545. throw new XMLConfigurationException(type, featureId);
  546. }
  547. //
  548. // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
  549. //
  550. if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
  551. featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
  552. return;
  553. }
  554. //
  555. // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
  556. //
  557. if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
  558. featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
  559. return;
  560. }
  561. //
  562. // http://apache.org/xml/features/validation/default-attribute-values
  563. //
  564. if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
  565. featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
  566. short type = XMLConfigurationException.NOT_SUPPORTED;
  567. throw new XMLConfigurationException(type, featureId);
  568. }
  569. }
  570. //
  571. // Not recognized
  572. //
  573. super.checkFeature(featureId);
  574. } // checkFeature(String)
  575. /**
  576. * Check a property. If the property is know and supported, this method
  577. * simply returns. Otherwise, the appropriate exception is thrown.
  578. *
  579. * @param propertyId The unique identifier (URI) of the property
  580. * being set.
  581. *
  582. * @throws XMLConfigurationException Thrown for configuration error.
  583. * In general, components should
  584. * only throw this exception if
  585. * it is <strong>really</strong>
  586. * a critical error.
  587. */
  588. protected void checkProperty(String propertyId)
  589. throws XMLConfigurationException {
  590. //
  591. // Xerces Properties
  592. //
  593. if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
  594. final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
  595. if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
  596. propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
  597. return;
  598. }
  599. }
  600. if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
  601. final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
  602. if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
  603. propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
  604. return;
  605. }
  606. }
  607. //
  608. // Not recognized
  609. //
  610. super.checkProperty(propertyId);
  611. } // checkProperty(String)
  612. //
  613. // other methods
  614. //
  615. /** Returns the Document object. */
  616. public Document getDocument() {
  617. return fSchemaDOMParser.getDocument();
  618. }
  619. /** */
  620. public void resetNodePool() {
  621. // REVISIT: to implement: introduce a node pool to reuse DTM nodes.
  622. // reset this pool here.
  623. }
  624. }