001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.parsers;
019:
020: import org.apache.xerces.impl.XMLDocumentScannerImpl;
021: import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
022: import org.apache.xerces.impl.dtd.XMLDTDValidator;
023: import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
024: import org.apache.xerces.impl.xs.XMLSchemaValidator;
025: import org.apache.xerces.impl.xs.XSMessageFormatter;
026: import org.apache.xerces.util.SymbolTable;
027: import org.apache.xerces.xni.grammars.XMLGrammarPool;
028: import org.apache.xerces.xni.parser.XMLComponent;
029: import org.apache.xerces.xni.parser.XMLComponentManager;
030: import org.apache.xerces.xni.parser.XMLDocumentScanner;
031:
032: /**
033: * This is configuration uses a scanner that integrates both scanning of the document
034: * and binding namespaces.
035: *
036: * If namespace feature is turned on, the pipeline is constructured with the
037: * following components:
038: * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
039: *
040: * If the namespace feature is turned off the default document scanner implementation
041: * is used (XMLDocumentScannerImpl).
042: * <p>
043: * In addition to the features and properties recognized by the base
044: * parser configuration, this class recognizes these additional
045: * features and properties:
046: * <ul>
047: * <li>Features
048: * <ul>
049: * <li>http://apache.org/xml/features/validation/schema</li>
050: * <li>http://apache.org/xml/features/validation/schema-full-checking</li>
051: * <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
052: * <li>http://apache.org/xml/features/validation/schema/element-default</li>
053: * </ul>
054: * <li>Properties
055: * <ul>
056: * <li>http://apache.org/xml/properties/internal/error-reporter</li>
057: * <li>http://apache.org/xml/properties/internal/entity-manager</li>
058: * <li>http://apache.org/xml/properties/internal/document-scanner</li>
059: * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
060: * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
061: * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
062: * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
063: * </ul>
064: * </ul>
065: *
066: * @author Elena Litani, IBM
067: *
068: * @version $Id: IntegratedParserConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
069: */
070: public class IntegratedParserConfiguration extends
071: StandardParserConfiguration {
072:
073: //
074: // REVISIT: should this configuration depend on the others
075: // like DTD/Standard one?
076: //
077:
078: /** Document scanner that does namespace binding. */
079: protected XMLNSDocumentScannerImpl fNamespaceScanner;
080:
081: /** Default Xerces implementation of scanner */
082: protected XMLDocumentScannerImpl fNonNSScanner;
083:
084: /** DTD Validator that does not bind namespaces */
085: protected XMLDTDValidator fNonNSDTDValidator;
086:
087: //
088: // Constructors
089: //
090:
091: /** Default constructor. */
092: public IntegratedParserConfiguration() {
093: this (null, null, null);
094: } // <init>()
095:
096: /**
097: * Constructs a parser configuration using the specified symbol table.
098: *
099: * @param symbolTable The symbol table to use.
100: */
101: public IntegratedParserConfiguration(SymbolTable symbolTable) {
102: this (symbolTable, null, null);
103: } // <init>(SymbolTable)
104:
105: /**
106: * Constructs a parser configuration using the specified symbol table and
107: * grammar pool.
108: * <p>
109: * <strong>REVISIT:</strong>
110: * Grammar pool will be updated when the new validation engine is
111: * implemented.
112: *
113: * @param symbolTable The symbol table to use.
114: * @param grammarPool The grammar pool to use.
115: */
116: public IntegratedParserConfiguration(SymbolTable symbolTable,
117: XMLGrammarPool grammarPool) {
118: this (symbolTable, grammarPool, null);
119: } // <init>(SymbolTable,XMLGrammarPool)
120:
121: /**
122: * Constructs a parser configuration using the specified symbol table,
123: * grammar pool, and parent settings.
124: * <p>
125: * <strong>REVISIT:</strong>
126: * Grammar pool will be updated when the new validation engine is
127: * implemented.
128: *
129: * @param symbolTable The symbol table to use.
130: * @param grammarPool The grammar pool to use.
131: * @param parentSettings The parent settings.
132: */
133: public IntegratedParserConfiguration(SymbolTable symbolTable,
134: XMLGrammarPool grammarPool,
135: XMLComponentManager parentSettings) {
136: super (symbolTable, grammarPool, parentSettings);
137:
138: // create components
139: fNonNSScanner = new XMLDocumentScannerImpl();
140: fNonNSDTDValidator = new XMLDTDValidator();
141:
142: // add components
143: addComponent((XMLComponent) fNonNSScanner);
144: addComponent((XMLComponent) fNonNSDTDValidator);
145:
146: } // <init>(SymbolTable,XMLGrammarPool)
147:
148: /** Configures the pipeline. */
149: protected void configurePipeline() {
150:
151: // use XML 1.0 datatype library
152: setProperty(DATATYPE_VALIDATOR_FACTORY,
153: fDatatypeValidatorFactory);
154:
155: // setup DTD pipeline
156: configureDTDPipeline();
157:
158: // setup document pipeline
159: if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
160: fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
161: fScanner = fNamespaceScanner;
162: fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
163: if (fDTDValidator != null) {
164: fProperties.put(DTD_VALIDATOR, fDTDValidator);
165: fNamespaceScanner.setDTDValidator(fDTDValidator);
166: fNamespaceScanner.setDocumentHandler(fDTDValidator);
167: fDTDValidator.setDocumentSource(fNamespaceScanner);
168: fDTDValidator.setDocumentHandler(fDocumentHandler);
169: if (fDocumentHandler != null) {
170: fDocumentHandler.setDocumentSource(fDTDValidator);
171: }
172: fLastComponent = fDTDValidator;
173: } else {
174: fNamespaceScanner.setDocumentHandler(fDocumentHandler);
175: fNamespaceScanner.setDTDValidator(null);
176: if (fDocumentHandler != null) {
177: fDocumentHandler
178: .setDocumentSource(fNamespaceScanner);
179: }
180: fLastComponent = fNamespaceScanner;
181: }
182: } else {
183: fScanner = fNonNSScanner;
184: fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
185: if (fNonNSDTDValidator != null) {
186: fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
187: fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
188: fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
189: fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
190: if (fDocumentHandler != null) {
191: fDocumentHandler
192: .setDocumentSource(fNonNSDTDValidator);
193: }
194: fLastComponent = fNonNSDTDValidator;
195: } else {
196: fScanner.setDocumentHandler(fDocumentHandler);
197: if (fDocumentHandler != null) {
198: fDocumentHandler.setDocumentSource(fScanner);
199: }
200: fLastComponent = fScanner;
201: }
202: }
203:
204: // setup document pipeline
205: if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
206: // If schema validator was not in the pipeline insert it.
207: if (fSchemaValidator == null) {
208: fSchemaValidator = new XMLSchemaValidator();
209:
210: // add schema component
211: fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
212: addComponent(fSchemaValidator);
213: // add schema message formatter
214: if (fErrorReporter
215: .getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
216: XSMessageFormatter xmft = new XSMessageFormatter();
217: fErrorReporter.putMessageFormatter(
218: XSMessageFormatter.SCHEMA_DOMAIN, xmft);
219: }
220:
221: }
222:
223: fLastComponent.setDocumentHandler(fSchemaValidator);
224: fSchemaValidator.setDocumentSource(fLastComponent);
225: fSchemaValidator.setDocumentHandler(fDocumentHandler);
226: if (fDocumentHandler != null) {
227: fDocumentHandler.setDocumentSource(fSchemaValidator);
228: }
229: fLastComponent = fSchemaValidator;
230: }
231: } // configurePipeline()
232:
233: /** Create a document scanner: this scanner performs namespace binding
234: */
235: protected XMLDocumentScanner createDocumentScanner() {
236: fNamespaceScanner = new XMLNSDocumentScannerImpl();
237: return fNamespaceScanner;
238: } // createDocumentScanner():XMLDocumentScanner
239:
240: /** Create a DTD validator: this validator performs namespace binding.
241: */
242: protected XMLDTDValidator createDTDValidator() {
243: return new XMLNSDTDValidator();
244: } // createDTDValidator():XMLDTDValidator
245:
246: } // class IntegratedParserConfiguration
|