1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001, 2002 The Apache Software Foundation.
  6. * All rights 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) 2002, 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.parsers;
  58. import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
  59. import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
  60. import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
  61. import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator;
  62. import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator;
  63. import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
  64. import com.sun.org.apache.xerces.internal.util.SymbolTable;
  65. import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  66. import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  67. import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  68. import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  69. /**
  70. * This is configuration uses a scanner that integrates both scanning of the document
  71. * and binding namespaces.
  72. *
  73. * If namespace feature is turned on, the pipeline is constructured with the
  74. * following components:
  75. * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
  76. *
  77. * If the namespace feature is turned off the default document scanner implementation
  78. * is used (XMLDocumentScannerImpl).
  79. * <p>
  80. * In addition to the features and properties recognized by the base
  81. * parser configuration, this class recognizes these additional
  82. * features and properties:
  83. * <ul>
  84. * <li>Features
  85. * <ul>
  86. * <li>http://apache.org/xml/features/validation/schema</li>
  87. * <li>http://apache.org/xml/features/validation/schema-full-checking</li>
  88. * <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
  89. * <li>http://apache.org/xml/features/validation/schema/element-default</li>
  90. * </ul>
  91. * <li>Properties
  92. * <ul>
  93. * <li>http://apache.org/xml/properties/internal/error-reporter</li>
  94. * <li>http://apache.org/xml/properties/internal/entity-manager</li>
  95. * <li>http://apache.org/xml/properties/internal/document-scanner</li>
  96. * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
  97. * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
  98. * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
  99. * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
  100. * </ul>
  101. * </ul>
  102. *
  103. * @author Elena Litani, IBM
  104. *
  105. * @version $Id: IntegratedParserConfiguration.java,v 1.12 2003/07/25 18:57:23 elena Exp $
  106. */
  107. public class IntegratedParserConfiguration
  108. extends StandardParserConfiguration {
  109. //
  110. // REVISIT: should this configuration depend on the others
  111. // like DTD/Standard one?
  112. //
  113. /** Document scanner that does namespace binding. */
  114. protected XMLNSDocumentScannerImpl fNamespaceScanner;
  115. /** Default Xerces implementation of scanner */
  116. protected XMLDocumentScannerImpl fNonNSScanner;
  117. /** DTD Validator that does not bind namespaces */
  118. protected XMLDTDValidator fNonNSDTDValidator;
  119. //
  120. // Constructors
  121. //
  122. /** Default constructor. */
  123. public IntegratedParserConfiguration() {
  124. this(null, null, null);
  125. } // <init>()
  126. /**
  127. * Constructs a parser configuration using the specified symbol table.
  128. *
  129. * @param symbolTable The symbol table to use.
  130. */
  131. public IntegratedParserConfiguration(SymbolTable symbolTable) {
  132. this(symbolTable, null, null);
  133. } // <init>(SymbolTable)
  134. /**
  135. * Constructs a parser configuration using the specified symbol table and
  136. * grammar pool.
  137. * <p>
  138. * <strong>REVISIT:</strong>
  139. * Grammar pool will be updated when the new validation engine is
  140. * implemented.
  141. *
  142. * @param symbolTable The symbol table to use.
  143. * @param grammarPool The grammar pool to use.
  144. */
  145. public IntegratedParserConfiguration(SymbolTable symbolTable,
  146. XMLGrammarPool grammarPool) {
  147. this(symbolTable, grammarPool, null);
  148. } // <init>(SymbolTable,XMLGrammarPool)
  149. /**
  150. * Constructs a parser configuration using the specified symbol table,
  151. * grammar pool, and parent settings.
  152. * <p>
  153. * <strong>REVISIT:</strong>
  154. * Grammar pool will be updated when the new validation engine is
  155. * implemented.
  156. *
  157. * @param symbolTable The symbol table to use.
  158. * @param grammarPool The grammar pool to use.
  159. * @param parentSettings The parent settings.
  160. */
  161. public IntegratedParserConfiguration(SymbolTable symbolTable,
  162. XMLGrammarPool grammarPool,
  163. XMLComponentManager parentSettings) {
  164. super(symbolTable, grammarPool, parentSettings);
  165. // create components
  166. fNonNSScanner = new XMLDocumentScannerImpl();
  167. fNonNSDTDValidator = new XMLDTDValidator();
  168. // add components
  169. addComponent((XMLComponent)fNonNSScanner);
  170. addComponent((XMLComponent)fNonNSDTDValidator);
  171. } // <init>(SymbolTable,XMLGrammarPool)
  172. /** Configures the pipeline. */
  173. protected void configurePipeline() {
  174. // use XML 1.0 datatype library
  175. setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
  176. // setup DTD pipeline
  177. configureDTDPipeline();
  178. // setup document pipeline
  179. if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
  180. fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
  181. fScanner = fNamespaceScanner;
  182. fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
  183. if (fDTDValidator != null) {
  184. fProperties.put(DTD_VALIDATOR, fDTDValidator);
  185. fNamespaceScanner.setDTDValidator(fDTDValidator);
  186. fNamespaceScanner.setDocumentHandler(fDTDValidator);
  187. fDTDValidator.setDocumentSource(fNamespaceScanner);
  188. fDTDValidator.setDocumentHandler(fDocumentHandler);
  189. if (fDocumentHandler != null) {
  190. fDocumentHandler.setDocumentSource(fDTDValidator);
  191. }
  192. fLastComponent = fDTDValidator;
  193. }
  194. else {
  195. fNamespaceScanner.setDocumentHandler(fDocumentHandler);
  196. fNamespaceScanner.setDTDValidator(null);
  197. if (fDocumentHandler != null) {
  198. fDocumentHandler.setDocumentSource(fNamespaceScanner);
  199. }
  200. fLastComponent = fNamespaceScanner;
  201. }
  202. }
  203. else {
  204. fScanner = fNonNSScanner;
  205. fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
  206. if (fNonNSDTDValidator != null) {
  207. fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
  208. fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
  209. fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
  210. fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
  211. if (fDocumentHandler != null) {
  212. fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
  213. }
  214. fLastComponent = fNonNSDTDValidator;
  215. }
  216. else {
  217. fScanner.setDocumentHandler(fDocumentHandler);
  218. if (fDocumentHandler != null) {
  219. fDocumentHandler.setDocumentSource(fScanner);
  220. }
  221. fLastComponent = fScanner;
  222. }
  223. }
  224. // setup document pipeline
  225. if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
  226. // If schema validator was not in the pipeline insert it.
  227. if (fSchemaValidator == null) {
  228. fSchemaValidator = new XMLSchemaValidator();
  229. // add schema component
  230. fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
  231. addComponent(fSchemaValidator);
  232. // add schema message formatter
  233. if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
  234. XSMessageFormatter xmft = new XSMessageFormatter();
  235. fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
  236. }
  237. }
  238. fLastComponent.setDocumentHandler(fSchemaValidator);
  239. fSchemaValidator.setDocumentSource(fLastComponent);
  240. fSchemaValidator.setDocumentHandler(fDocumentHandler);
  241. if (fDocumentHandler != null) {
  242. fDocumentHandler.setDocumentSource(fSchemaValidator);
  243. }
  244. fLastComponent = fSchemaValidator;
  245. }
  246. } // configurePipeline()
  247. /** Create a document scanner: this scanner performs namespace binding
  248. */
  249. protected XMLDocumentScanner createDocumentScanner() {
  250. fNamespaceScanner = new XMLNSDocumentScannerImpl();
  251. return fNamespaceScanner;
  252. } // createDocumentScanner():XMLDocumentScanner
  253. /** Create a DTD validator: this validator performs namespace binding.
  254. */
  255. protected XMLDTDValidator createDTDValidator() {
  256. return new XMLNSDTDValidator();
  257. } // createDTDValidator():XMLDTDValidator
  258. } // class IntegratedParserConfiguration