2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.parsers;
20
import org.apache.xerces.impl.XMLDocumentScannerImpl;
21
import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
22
import org.apache.xerces.impl.dtd.XMLDTDValidator;
23
import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
24
import org.apache.xerces.impl.xs.XMLSchemaValidator;
25
import org.apache.xerces.impl.xs.XSMessageFormatter;
26
import org.apache.xerces.util.SymbolTable;
27
import org.apache.xerces.xni.grammars.XMLGrammarPool;
28
import org.apache.xerces.xni.parser.XMLComponent;
29
import org.apache.xerces.xni.parser.XMLComponentManager;
30
import org.apache.xerces.xni.parser.XMLDocumentScanner;
33
* This is configuration uses a scanner that integrates both scanning of the document
34
* and binding namespaces.
36
* If namespace feature is turned on, the pipeline is constructured with the
37
* following components:
38
* XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
40
* If the namespace feature is turned off the default document scanner implementation
41
* is used (XMLDocumentScannerImpl).
43
* In addition to the features and properties recognized by the base
44
* parser configuration, this class recognizes these additional
45
* features and properties:
49
* <li>http://apache.org/xml/features/validation/schema</li>
50
* <li>http://apache.org/xml/features/validation/schema-full-checking</li>
51
* <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
52
* <li>http://apache.org/xml/features/validation/schema/element-default</li>
56
* <li>http://apache.org/xml/properties/internal/error-reporter</li>
57
* <li>http://apache.org/xml/properties/internal/entity-manager</li>
58
* <li>http://apache.org/xml/properties/internal/document-scanner</li>
59
* <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
60
* <li>http://apache.org/xml/properties/internal/grammar-pool</li>
61
* <li>http://apache.org/xml/properties/internal/validator/dtd</li>
62
* <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
66
* @author Elena Litani, IBM
68
* @version $Id: IntegratedParserConfiguration.java,v 1.2 2009/12/10 03:18:31 matthewoliver Exp $
70
public class IntegratedParserConfiguration
71
extends StandardParserConfiguration {
75
// REVISIT: should this configuration depend on the others
76
// like DTD/Standard one?
79
/** Document scanner that does namespace binding. */
80
protected XMLNSDocumentScannerImpl fNamespaceScanner;
82
/** Default Xerces implementation of scanner */
83
protected XMLDocumentScannerImpl fNonNSScanner;
85
/** DTD Validator that does not bind namespaces */
86
protected XMLDTDValidator fNonNSDTDValidator;
92
/** Default constructor. */
93
public IntegratedParserConfiguration() {
94
this(null, null, null);
98
* Constructs a parser configuration using the specified symbol table.
100
* @param symbolTable The symbol table to use.
102
public IntegratedParserConfiguration(SymbolTable symbolTable) {
103
this(symbolTable, null, null);
104
} // <init>(SymbolTable)
107
* Constructs a parser configuration using the specified symbol table and
110
* <strong>REVISIT:</strong>
111
* Grammar pool will be updated when the new validation engine is
114
* @param symbolTable The symbol table to use.
115
* @param grammarPool The grammar pool to use.
117
public IntegratedParserConfiguration(SymbolTable symbolTable,
118
XMLGrammarPool grammarPool) {
119
this(symbolTable, grammarPool, null);
120
} // <init>(SymbolTable,XMLGrammarPool)
123
* Constructs a parser configuration using the specified symbol table,
124
* grammar pool, and parent settings.
126
* <strong>REVISIT:</strong>
127
* Grammar pool will be updated when the new validation engine is
130
* @param symbolTable The symbol table to use.
131
* @param grammarPool The grammar pool to use.
132
* @param parentSettings The parent settings.
134
public IntegratedParserConfiguration(SymbolTable symbolTable,
135
XMLGrammarPool grammarPool,
136
XMLComponentManager parentSettings) {
137
super(symbolTable, grammarPool, parentSettings);
140
fNonNSScanner = new XMLDocumentScannerImpl();
141
fNonNSDTDValidator = new XMLDTDValidator();
144
addComponent((XMLComponent)fNonNSScanner);
145
addComponent((XMLComponent)fNonNSDTDValidator);
147
} // <init>(SymbolTable,XMLGrammarPool)
150
/** Configures the pipeline. */
151
protected void configurePipeline() {
153
// use XML 1.0 datatype library
154
setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
156
// setup DTD pipeline
157
configureDTDPipeline();
159
// setup document pipeline
160
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
161
fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
162
fScanner = fNamespaceScanner;
163
fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
164
if (fDTDValidator != null) {
165
fProperties.put(DTD_VALIDATOR, fDTDValidator);
166
fNamespaceScanner.setDTDValidator(fDTDValidator);
167
fNamespaceScanner.setDocumentHandler(fDTDValidator);
168
fDTDValidator.setDocumentSource(fNamespaceScanner);
169
fDTDValidator.setDocumentHandler(fDocumentHandler);
170
if (fDocumentHandler != null) {
171
fDocumentHandler.setDocumentSource(fDTDValidator);
173
fLastComponent = fDTDValidator;
176
fNamespaceScanner.setDocumentHandler(fDocumentHandler);
177
fNamespaceScanner.setDTDValidator(null);
178
if (fDocumentHandler != null) {
179
fDocumentHandler.setDocumentSource(fNamespaceScanner);
181
fLastComponent = fNamespaceScanner;
185
fScanner = fNonNSScanner;
186
fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
187
if (fNonNSDTDValidator != null) {
188
fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
189
fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
190
fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
191
fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
192
if (fDocumentHandler != null) {
193
fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
195
fLastComponent = fNonNSDTDValidator;
198
fScanner.setDocumentHandler(fDocumentHandler);
199
if (fDocumentHandler != null) {
200
fDocumentHandler.setDocumentSource(fScanner);
202
fLastComponent = fScanner;
206
// setup document pipeline
207
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
208
// If schema validator was not in the pipeline insert it.
209
if (fSchemaValidator == null) {
210
fSchemaValidator = new XMLSchemaValidator();
212
// add schema component
213
fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
214
addComponent(fSchemaValidator);
215
// add schema message formatter
216
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
217
XSMessageFormatter xmft = new XSMessageFormatter();
218
fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
223
fLastComponent.setDocumentHandler(fSchemaValidator);
224
fSchemaValidator.setDocumentSource(fLastComponent);
225
fSchemaValidator.setDocumentHandler(fDocumentHandler);
226
if (fDocumentHandler != null) {
227
fDocumentHandler.setDocumentSource(fSchemaValidator);
229
fLastComponent = fSchemaValidator;
231
} // configurePipeline()
235
/** Create a document scanner: this scanner performs namespace binding
237
protected XMLDocumentScanner createDocumentScanner() {
238
fNamespaceScanner = new XMLNSDocumentScannerImpl();
239
return fNamespaceScanner;
240
} // createDocumentScanner():XMLDocumentScanner
243
/** Create a DTD validator: this validator performs namespace binding.
245
protected XMLDTDValidator createDTDValidator() {
246
return new XMLNSDTDValidator();
247
} // createDTDValidator():XMLDTDValidator
249
} // class IntegratedParserConfiguration