2
* The Apache Software License, Version 1.1
5
* Copyright (c) 2001-2004 The Apache Software Foundation.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
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
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.
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.
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.
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
48
* ====================================================================
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) 1999, 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/>.
58
package org.apache.xerces.parsers;
60
import org.apache.xerces.impl.Constants;
61
import org.apache.xerces.impl.xs.XMLSchemaValidator;
62
import org.apache.xerces.impl.xs.XSMessageFormatter;
63
import org.apache.xerces.util.SymbolTable;
64
import org.apache.xerces.xni.grammars.XMLGrammarPool;
65
import org.apache.xerces.xni.parser.XMLComponentManager;
66
import org.apache.xerces.xni.parser.XMLConfigurationException;
69
* This is the "standard" parser configuration. It extends the DTD
70
* configuration with the standard set of parser components.
71
* The standard set of parser components include those needed
72
* to parse and validate with DTD's, and those needed for XML
75
* In addition to the features and properties recognized by the base
76
* parser configuration, this class recognizes these additional
77
* features and properties:
81
* <li>http://apache.org/xml/features/validation/schema</li>
82
* <li>http://apache.org/xml/features/validation/schema-full-checking</li>
83
* <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
84
* <li>http://apache.org/xml/features/validation/schema/element-default</li>
88
* <li>http://apache.org/xml/properties/internal/error-reporter</li>
89
* <li>http://apache.org/xml/properties/internal/entity-manager</li>
90
* <li>http://apache.org/xml/properties/internal/document-scanner</li>
91
* <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
92
* <li>http://apache.org/xml/properties/internal/grammar-pool</li>
93
* <li>http://apache.org/xml/properties/internal/validator/dtd</li>
94
* <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
98
* @author Arnaud Le Hors, IBM
99
* @author Andy Clark, IBM
101
* @version $Id: StandardParserConfiguration.java,v 1.33 2004/01/26 17:28:10 mrglavas Exp $
103
public class StandardParserConfiguration
104
extends DTDConfiguration {
110
// feature identifiers
112
/** Feature identifier: expose schema normalized value */
113
protected static final String NORMALIZE_DATA =
114
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
117
/** Feature identifier: send element default value via characters() */
118
protected static final String SCHEMA_ELEMENT_DEFAULT =
119
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
122
/** Feature identifier: augment PSVI */
123
protected static final String SCHEMA_AUGMENT_PSVI =
124
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
127
/** feature identifier: XML Schema validation */
128
protected static final String XMLSCHEMA_VALIDATION =
129
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
131
/** feature identifier: XML Schema validation -- full checking */
132
protected static final String XMLSCHEMA_FULL_CHECKING =
133
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
135
// property identifiers
137
/** Property identifier: XML Schema validator. */
138
protected static final String SCHEMA_VALIDATOR =
139
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
141
/** Property identifier: schema location. */
142
protected static final String SCHEMA_LOCATION =
143
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
145
/** Property identifier: no namespace schema location. */
146
protected static final String SCHEMA_NONS_LOCATION =
147
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
153
// components (non-configurable)
155
/** XML Schema Validator. */
156
protected XMLSchemaValidator fSchemaValidator;
162
/** Default constructor. */
163
public StandardParserConfiguration() {
164
this(null, null, null);
168
* Constructs a parser configuration using the specified symbol table.
170
* @param symbolTable The symbol table to use.
172
public StandardParserConfiguration(SymbolTable symbolTable) {
173
this(symbolTable, null, null);
174
} // <init>(SymbolTable)
177
* Constructs a parser configuration using the specified symbol table and
180
* <strong>REVISIT:</strong>
181
* Grammar pool will be updated when the new validation engine is
184
* @param symbolTable The symbol table to use.
185
* @param grammarPool The grammar pool to use.
187
public StandardParserConfiguration(SymbolTable symbolTable,
188
XMLGrammarPool grammarPool) {
189
this(symbolTable, grammarPool, null);
190
} // <init>(SymbolTable,XMLGrammarPool)
193
* Constructs a parser configuration using the specified symbol table,
194
* grammar pool, and parent settings.
196
* <strong>REVISIT:</strong>
197
* Grammar pool will be updated when the new validation engine is
200
* @param symbolTable The symbol table to use.
201
* @param grammarPool The grammar pool to use.
202
* @param parentSettings The parent settings.
204
public StandardParserConfiguration(SymbolTable symbolTable,
205
XMLGrammarPool grammarPool,
206
XMLComponentManager parentSettings) {
207
super(symbolTable, grammarPool, parentSettings);
209
// add default recognized features
210
final String[] recognizedFeatures = {
212
SCHEMA_ELEMENT_DEFAULT,
214
// NOTE: These shouldn't really be here but since the XML Schema
215
// validator is constructed dynamically, its recognized
216
// features might not have been set and it would cause a
217
// not-recognized exception to be thrown. -Ac
218
XMLSCHEMA_VALIDATION,
219
XMLSCHEMA_FULL_CHECKING,
221
addRecognizedFeatures(recognizedFeatures);
223
// set state for default features
224
setFeature(SCHEMA_ELEMENT_DEFAULT, true);
225
setFeature(NORMALIZE_DATA, true);
226
setFeature(SCHEMA_AUGMENT_PSVI, true);
228
// add default recognized properties
230
final String[] recognizedProperties = {
231
// NOTE: These shouldn't really be here but since the XML Schema
232
// validator is constructed dynamically, its recognized
233
// properties might not have been set and it would cause a
234
// not-recognized exception to be thrown. -Ac
236
SCHEMA_NONS_LOCATION,
239
addRecognizedProperties(recognizedProperties);
241
} // <init>(SymbolTable,XMLGrammarPool)
247
/** Configures the pipeline. */
248
protected void configurePipeline() {
249
super.configurePipeline();
250
if ( getFeature(XMLSCHEMA_VALIDATION )) {
251
// If schema validator was not in the pipeline insert it.
252
if (fSchemaValidator == null) {
253
fSchemaValidator = new XMLSchemaValidator();
255
// add schema component
256
fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
257
addComponent(fSchemaValidator);
258
// add schema message formatter
259
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
260
XSMessageFormatter xmft = new XSMessageFormatter();
261
fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
265
fLastComponent = fSchemaValidator;
266
fNamespaceBinder.setDocumentHandler(fSchemaValidator);
268
fSchemaValidator.setDocumentHandler(fDocumentHandler);
269
fSchemaValidator.setDocumentSource(fNamespaceBinder);
273
} // configurePipeline()
275
// features and properties
278
* Check a feature. If feature is know and supported, this method simply
279
* returns. Otherwise, the appropriate exception is thrown.
281
* @param featureId The unique identifier (URI) of the feature.
283
* @throws XMLConfigurationException Thrown for configuration error.
284
* In general, components should
285
* only throw this exception if
286
* it is <strong>really</strong>
289
protected void checkFeature(String featureId)
290
throws XMLConfigurationException {
296
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
297
final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
300
// http://apache.org/xml/features/validation/schema
301
// Lets the user turn Schema validation support on/off.
303
if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() &&
304
featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) {
307
// activate full schema checking
308
if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() &&
309
featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) {
312
// Feature identifier: expose schema normalized value
313
// http://apache.org/xml/features/validation/schema/normalized-value
314
if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() &&
315
featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) {
318
// Feature identifier: send element default value via characters()
319
// http://apache.org/xml/features/validation/schema/element-default
320
if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() &&
321
featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) {
330
super.checkFeature(featureId);
332
} // checkFeature(String)
335
* Check a property. If the property is know and supported, this method
336
* simply returns. Otherwise, the appropriate exception is thrown.
338
* @param propertyId The unique identifier (URI) of the property
341
* @throws XMLConfigurationException Thrown for configuration error.
342
* In general, components should
343
* only throw this exception if
344
* it is <strong>really</strong>
347
protected void checkProperty(String propertyId)
348
throws XMLConfigurationException {
354
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
355
final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
357
if (suffixLength == Constants.SCHEMA_LOCATION.length() &&
358
propertyId.endsWith(Constants.SCHEMA_LOCATION)) {
361
if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() &&
362
propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) {
367
if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
368
final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
370
if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
371
propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
380
super.checkProperty(propertyId);
382
} // checkProperty(String)
384
} // class StandardParserConfiguration