author | joehw |
Thu, 28 Jul 2016 22:58:41 -0700 | |
changeset 39907 | db51759e3695 |
parent 25868 | 686eef1e7a79 |
child 42247 | 52fafb950d5a |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
39907 | 2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
12005 | 3 |
*/ |
4 |
/* |
|
39907 | 5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
6 |
* contributor license agreements. See the NOTICE file distributed with |
|
7 |
* this work for additional information regarding copyright ownership. |
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
9 |
* (the "License"); you may not use this file except in compliance with |
|
10 |
* the License. You may obtain a copy of the License at |
|
12005 | 11 |
* |
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
||
21 |
package com.sun.org.apache.xerces.internal.parsers; |
|
22 |
||
23 |
import java.io.IOException; |
|
24 |
import java.util.Locale; |
|
25 |
||
26 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
27 |
import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl; |
|
28 |
import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; |
|
30 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
31 |
import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl; |
|
32 |
import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; |
|
33 |
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; |
|
34 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; |
|
35 |
import com.sun.org.apache.xerces.internal.util.FeatureState; |
|
36 |
import com.sun.org.apache.xerces.internal.util.PropertyState; |
|
37 |
import com.sun.org.apache.xerces.internal.util.Status; |
|
38 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
19479
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
12457
diff
changeset
|
39 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
12005 | 40 |
import com.sun.org.apache.xerces.internal.xni.XMLLocator; |
41 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
42 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
|
43 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; |
|
44 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
45 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
46 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; |
|
47 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; |
|
48 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
49 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; |
|
39907 | 50 |
import javax.xml.XMLConstants; |
51 |
import javax.xml.catalog.CatalogFeatures; |
|
52 |
import jdk.xml.internal.JdkXmlUtils; |
|
12005 | 53 |
|
54 |
/** |
|
55 |
* This is the non validating parser configuration. It extends the basic |
|
56 |
* configuration with the set of following parser components: |
|
57 |
* Document scanner, DTD scanner, namespace binder, document handler. |
|
58 |
* <p> |
|
59 |
* Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a> |
|
60 |
* non-validating XML processor, since conformant non-validating processor is required |
|
61 |
* to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values, |
|
62 |
* include the replacement text of internal entities, and supply default attribute values". |
|
63 |
* |
|
64 |
* @author Elena Litani, IBM |
|
65 |
*/ |
|
66 |
public class NonValidatingConfiguration |
|
67 |
extends BasicParserConfiguration |
|
68 |
implements XMLPullParserConfiguration { |
|
69 |
||
70 |
// |
|
71 |
// Constants |
|
72 |
// |
|
73 |
||
74 |
// feature identifiers |
|
75 |
||
76 |
/** Feature identifier: warn on duplicate attribute definition. */ |
|
77 |
protected static final String WARN_ON_DUPLICATE_ATTDEF = |
|
78 |
Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; |
|
79 |
||
80 |
/** Feature identifier: warn on duplicate entity definition. */ |
|
81 |
protected static final String WARN_ON_DUPLICATE_ENTITYDEF = |
|
82 |
Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE; |
|
83 |
||
84 |
/** Feature identifier: warn on undeclared element definition. */ |
|
85 |
protected static final String WARN_ON_UNDECLARED_ELEMDEF = |
|
86 |
Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE; |
|
87 |
||
88 |
/** Feature identifier: allow Java encodings. */ |
|
89 |
protected static final String ALLOW_JAVA_ENCODINGS = |
|
90 |
Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; |
|
91 |
||
92 |
/** Feature identifier: continue after fatal error. */ |
|
93 |
protected static final String CONTINUE_AFTER_FATAL_ERROR = |
|
94 |
Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; |
|
95 |
||
96 |
/** Feature identifier: load external DTD. */ |
|
97 |
protected static final String LOAD_EXTERNAL_DTD = |
|
98 |
Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; |
|
99 |
||
100 |
/** Feature identifier: notify built-in refereces. */ |
|
101 |
protected static final String NOTIFY_BUILTIN_REFS = |
|
102 |
Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE; |
|
103 |
||
104 |
/** Feature identifier: notify character refereces. */ |
|
105 |
protected static final String NOTIFY_CHAR_REFS = |
|
106 |
Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE; |
|
107 |
||
108 |
||
109 |
/** Feature identifier: expose schema normalized value */ |
|
110 |
protected static final String NORMALIZE_DATA = |
|
111 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; |
|
112 |
||
113 |
||
114 |
/** Feature identifier: send element default value via characters() */ |
|
115 |
protected static final String SCHEMA_ELEMENT_DEFAULT = |
|
116 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; |
|
117 |
||
118 |
// property identifiers |
|
119 |
||
120 |
/** Property identifier: error reporter. */ |
|
121 |
protected static final String ERROR_REPORTER = |
|
122 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
123 |
||
124 |
/** Property identifier: entity manager. */ |
|
125 |
protected static final String ENTITY_MANAGER = |
|
126 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
127 |
||
128 |
/** Property identifier document scanner: */ |
|
129 |
protected static final String DOCUMENT_SCANNER = |
|
130 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; |
|
131 |
||
132 |
/** Property identifier: DTD scanner. */ |
|
133 |
protected static final String DTD_SCANNER = |
|
134 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; |
|
135 |
||
136 |
/** Property identifier: grammar pool. */ |
|
137 |
protected static final String XMLGRAMMAR_POOL = |
|
138 |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
139 |
||
140 |
/** Property identifier: DTD validator. */ |
|
141 |
protected static final String DTD_VALIDATOR = |
|
142 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; |
|
143 |
||
144 |
/** Property identifier: namespace binder. */ |
|
145 |
protected static final String NAMESPACE_BINDER = |
|
146 |
Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; |
|
147 |
||
148 |
/** Property identifier: datatype validator factory. */ |
|
149 |
protected static final String DATATYPE_VALIDATOR_FACTORY = |
|
150 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; |
|
151 |
||
152 |
protected static final String VALIDATION_MANAGER = |
|
153 |
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; |
|
154 |
||
155 |
/** Property identifier: XML Schema validator. */ |
|
156 |
protected static final String SCHEMA_VALIDATOR = |
|
157 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; |
|
158 |
||
159 |
/** Property identifier: locale. */ |
|
160 |
protected static final String LOCALE = |
|
161 |
Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; |
|
162 |
||
20973 | 163 |
/** Property identifier: Security property manager. */ |
164 |
protected static final String XML_SECURITY_PROPERTY_MANAGER = |
|
165 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
|
166 |
||
167 |
/** Property identifier: Security manager. */ |
|
168 |
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER; |
|
169 |
||
12005 | 170 |
// debugging |
171 |
||
172 |
/** Set to true and recompile to print exception stack trace. */ |
|
173 |
private static final boolean PRINT_EXCEPTION_STACK_TRACE = false; |
|
174 |
||
175 |
// |
|
176 |
// Data |
|
177 |
// |
|
178 |
||
179 |
// components (non-configurable) |
|
180 |
||
181 |
/** Grammar pool. */ |
|
182 |
protected XMLGrammarPool fGrammarPool; |
|
183 |
||
184 |
/** Datatype validator factory. */ |
|
185 |
protected DTDDVFactory fDatatypeValidatorFactory; |
|
186 |
||
187 |
// components (configurable) |
|
188 |
||
189 |
/** Error reporter. */ |
|
190 |
protected XMLErrorReporter fErrorReporter; |
|
191 |
||
192 |
/** Entity manager. */ |
|
193 |
protected XMLEntityManager fEntityManager; |
|
194 |
||
195 |
/** Document scanner. */ |
|
196 |
protected XMLDocumentScanner fScanner; |
|
197 |
||
198 |
/** Input Source */ |
|
199 |
protected XMLInputSource fInputSource; |
|
200 |
||
201 |
/** DTD scanner. */ |
|
202 |
protected XMLDTDScanner fDTDScanner; |
|
203 |
||
204 |
||
205 |
protected ValidationManager fValidationManager; |
|
206 |
||
207 |
// private data |
|
208 |
||
209 |
/** Document scanner that does namespace binding. */ |
|
210 |
private XMLNSDocumentScannerImpl fNamespaceScanner; |
|
211 |
||
212 |
/** Default Xerces implementation of scanner*/ |
|
213 |
private XMLDocumentScannerImpl fNonNSScanner; |
|
214 |
||
215 |
||
216 |
/** fConfigUpdated is set to true if there has been any change to the configuration settings, |
|
217 |
* i.e a feature or a property was changed. |
|
218 |
*/ |
|
219 |
protected boolean fConfigUpdated = false; |
|
220 |
||
221 |
||
222 |
// state |
|
223 |
||
224 |
/** Locator */ |
|
225 |
protected XMLLocator fLocator; |
|
226 |
||
227 |
/** |
|
228 |
* True if a parse is in progress. This state is needed because |
|
229 |
* some features/properties cannot be set while parsing (e.g. |
|
230 |
* validation and namespaces). |
|
231 |
*/ |
|
232 |
protected boolean fParseInProgress = false; |
|
233 |
||
234 |
// |
|
235 |
// Constructors |
|
236 |
// |
|
237 |
||
238 |
/** Default constructor. */ |
|
239 |
public NonValidatingConfiguration() { |
|
240 |
this(null, null, null); |
|
241 |
} // <init>() |
|
242 |
||
243 |
/** |
|
244 |
* Constructs a parser configuration using the specified symbol table. |
|
245 |
* |
|
246 |
* @param symbolTable The symbol table to use. |
|
247 |
*/ |
|
248 |
public NonValidatingConfiguration(SymbolTable symbolTable) { |
|
249 |
this(symbolTable, null, null); |
|
250 |
} // <init>(SymbolTable) |
|
251 |
||
252 |
/** |
|
253 |
* Constructs a parser configuration using the specified symbol table and |
|
254 |
* grammar pool. |
|
255 |
* <p> |
|
256 |
* <strong>REVISIT:</strong> |
|
257 |
* Grammar pool will be updated when the new validation engine is |
|
258 |
* implemented. |
|
259 |
* |
|
260 |
* @param symbolTable The symbol table to use. |
|
261 |
* @param grammarPool The grammar pool to use. |
|
262 |
*/ |
|
263 |
public NonValidatingConfiguration(SymbolTable symbolTable, |
|
264 |
XMLGrammarPool grammarPool) { |
|
265 |
this(symbolTable, grammarPool, null); |
|
266 |
} // <init>(SymbolTable,XMLGrammarPool) |
|
267 |
||
268 |
/** |
|
269 |
* Constructs a parser configuration using the specified symbol table, |
|
270 |
* grammar pool, and parent settings. |
|
271 |
* <p> |
|
272 |
* <strong>REVISIT:</strong> |
|
273 |
* Grammar pool will be updated when the new validation engine is |
|
274 |
* implemented. |
|
275 |
* |
|
276 |
* @param symbolTable The symbol table to use. |
|
277 |
* @param grammarPool The grammar pool to use. |
|
278 |
* @param parentSettings The parent settings. |
|
279 |
*/ |
|
280 |
public NonValidatingConfiguration(SymbolTable symbolTable, |
|
281 |
XMLGrammarPool grammarPool, |
|
282 |
XMLComponentManager parentSettings) { |
|
283 |
super(symbolTable, parentSettings); |
|
284 |
||
285 |
// add default recognized features |
|
286 |
final String[] recognizedFeatures = { |
|
39907 | 287 |
PARSER_SETTINGS, |
288 |
NAMESPACES, |
|
12005 | 289 |
//WARN_ON_DUPLICATE_ATTDEF, // from XMLDTDScannerImpl |
290 |
//WARN_ON_UNDECLARED_ELEMDEF, // from XMLDTDScannerImpl |
|
291 |
//ALLOW_JAVA_ENCODINGS, // from XMLEntityManager |
|
292 |
CONTINUE_AFTER_FATAL_ERROR, |
|
293 |
//LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl |
|
294 |
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl |
|
295 |
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl |
|
296 |
//WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager |
|
39907 | 297 |
XMLConstants.USE_CATALOG |
12005 | 298 |
}; |
299 |
addRecognizedFeatures(recognizedFeatures); |
|
300 |
||
301 |
// set state for default features |
|
302 |
//setFeature(WARN_ON_DUPLICATE_ATTDEF, false); // from XMLDTDScannerImpl |
|
303 |
//setFeature(WARN_ON_UNDECLARED_ELEMDEF, false); // from XMLDTDScannerImpl |
|
304 |
//setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager |
|
305 |
fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); |
|
39907 | 306 |
fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); |
307 |
fFeatures.put(NAMESPACES, Boolean.TRUE); |
|
12005 | 308 |
//setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl |
309 |
//setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl |
|
310 |
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl |
|
311 |
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager |
|
39907 | 312 |
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); |
12005 | 313 |
|
314 |
// add default recognized properties |
|
315 |
final String[] recognizedProperties = { |
|
316 |
ERROR_REPORTER, |
|
317 |
ENTITY_MANAGER, |
|
318 |
DOCUMENT_SCANNER, |
|
319 |
DTD_SCANNER, |
|
320 |
DTD_VALIDATOR, |
|
321 |
NAMESPACE_BINDER, |
|
322 |
XMLGRAMMAR_POOL, |
|
323 |
DATATYPE_VALIDATOR_FACTORY, |
|
324 |
VALIDATION_MANAGER, |
|
20973 | 325 |
LOCALE, |
326 |
SECURITY_MANAGER, |
|
39907 | 327 |
XML_SECURITY_PROPERTY_MANAGER, |
328 |
JdkXmlUtils.CATALOG_DEFER, |
|
329 |
JdkXmlUtils.CATALOG_FILES, |
|
330 |
JdkXmlUtils.CATALOG_PREFER, |
|
331 |
JdkXmlUtils.CATALOG_RESOLVE |
|
12005 | 332 |
}; |
333 |
addRecognizedProperties(recognizedProperties); |
|
334 |
||
335 |
fGrammarPool = grammarPool; |
|
336 |
if(fGrammarPool != null){ |
|
337 |
fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); |
|
338 |
} |
|
339 |
||
340 |
fEntityManager = createEntityManager(); |
|
341 |
fProperties.put(ENTITY_MANAGER, fEntityManager); |
|
342 |
addComponent(fEntityManager); |
|
343 |
||
344 |
fErrorReporter = createErrorReporter(); |
|
345 |
fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); |
|
346 |
fProperties.put(ERROR_REPORTER, fErrorReporter); |
|
347 |
addComponent(fErrorReporter); |
|
348 |
||
349 |
// this configuration delays creation of the scanner |
|
350 |
// till it is known if namespace processing should be performed |
|
351 |
||
352 |
fDTDScanner = createDTDScanner(); |
|
353 |
if (fDTDScanner != null) { |
|
354 |
fProperties.put(DTD_SCANNER, fDTDScanner); |
|
355 |
if (fDTDScanner instanceof XMLComponent) { |
|
356 |
addComponent((XMLComponent)fDTDScanner); |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
fDatatypeValidatorFactory = createDatatypeValidatorFactory(); |
|
361 |
if (fDatatypeValidatorFactory != null) { |
|
362 |
fProperties.put(DATATYPE_VALIDATOR_FACTORY, |
|
363 |
fDatatypeValidatorFactory); |
|
364 |
} |
|
365 |
fValidationManager = createValidationManager(); |
|
366 |
||
367 |
if (fValidationManager != null) { |
|
368 |
fProperties.put(VALIDATION_MANAGER, fValidationManager); |
|
369 |
} |
|
370 |
// add message formatters |
|
371 |
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { |
|
372 |
XMLMessageFormatter xmft = new XMLMessageFormatter(); |
|
373 |
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); |
|
374 |
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); |
|
375 |
} |
|
376 |
||
377 |
fConfigUpdated = false; |
|
378 |
||
379 |
// set locale |
|
380 |
try { |
|
381 |
setLocale(Locale.getDefault()); |
|
382 |
} |
|
383 |
catch (XNIException e) { |
|
384 |
// do nothing |
|
385 |
// REVISIT: What is the right thing to do? -Ac |
|
386 |
} |
|
387 |
||
19479
e4f3adf06beb
8022548: SPECJVM2008 has errors introduced in 7u40-b34
joehw
parents:
12457
diff
changeset
|
388 |
setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager()); |
39907 | 389 |
|
390 |
// Initialize Catalog features |
|
391 |
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { |
|
392 |
setProperty(f.getPropertyName(), null); |
|
393 |
} |
|
12005 | 394 |
} // <init>(SymbolTable,XMLGrammarPool) |
395 |
||
396 |
// |
|
397 |
// Public methods |
|
398 |
// |
|
399 |
public void setFeature(String featureId, boolean state) |
|
400 |
throws XMLConfigurationException { |
|
401 |
fConfigUpdated = true; |
|
402 |
super.setFeature(featureId, state); |
|
403 |
} |
|
404 |
||
405 |
public PropertyState getPropertyState(String propertyId) |
|
406 |
throws XMLConfigurationException { |
|
407 |
if (LOCALE.equals(propertyId)) { |
|
408 |
return PropertyState.is(getLocale()); |
|
409 |
} |
|
410 |
return super.getPropertyState(propertyId); |
|
411 |
} |
|
412 |
||
413 |
public void setProperty(String propertyId, Object value) |
|
414 |
throws XMLConfigurationException { |
|
415 |
fConfigUpdated = true; |
|
416 |
if (LOCALE.equals(propertyId)) { |
|
417 |
setLocale((Locale) value); |
|
418 |
} |
|
419 |
super.setProperty(propertyId, value); |
|
420 |
} |
|
421 |
||
422 |
/** |
|
423 |
* Set the locale to use for messages. |
|
424 |
* |
|
425 |
* @param locale The locale object to use for localization of messages. |
|
426 |
* |
|
427 |
* @exception XNIException Thrown if the parser does not support the |
|
428 |
* specified locale. |
|
429 |
*/ |
|
430 |
public void setLocale(Locale locale) throws XNIException { |
|
431 |
super.setLocale(locale); |
|
432 |
fErrorReporter.setLocale(locale); |
|
433 |
} // setLocale(Locale) |
|
434 |
||
435 |
public FeatureState getFeatureState(String featureId) |
|
436 |
throws XMLConfigurationException { |
|
437 |
// make this feature special |
|
438 |
if (featureId.equals(PARSER_SETTINGS)){ |
|
439 |
return FeatureState.is(fConfigUpdated); |
|
440 |
} |
|
441 |
return super.getFeatureState(featureId); |
|
442 |
||
443 |
} // getFeature(String):boolean |
|
444 |
// |
|
445 |
// XMLPullParserConfiguration methods |
|
446 |
// |
|
447 |
||
448 |
// parsing |
|
449 |
||
450 |
/** |
|
451 |
* Sets the input source for the document to parse. |
|
452 |
* |
|
453 |
* @param inputSource The document's input source. |
|
454 |
* |
|
455 |
* @exception XMLConfigurationException Thrown if there is a |
|
456 |
* configuration error when initializing the |
|
457 |
* parser. |
|
458 |
* @exception IOException Thrown on I/O error. |
|
459 |
* |
|
460 |
* @see #parse(boolean) |
|
461 |
*/ |
|
462 |
public void setInputSource(XMLInputSource inputSource) |
|
463 |
throws XMLConfigurationException, IOException { |
|
464 |
||
465 |
// REVISIT: this method used to reset all the components and |
|
466 |
// construct the pipeline. Now reset() is called |
|
467 |
// in parse (boolean) just before we parse the document |
|
468 |
// Should this method still throw exceptions..? |
|
469 |
||
470 |
fInputSource = inputSource; |
|
471 |
||
472 |
} // setInputSource(XMLInputSource) |
|
473 |
||
474 |
/** |
|
475 |
* Parses the document in a pull parsing fashion. |
|
476 |
* |
|
477 |
* @param complete True if the pull parser should parse the |
|
478 |
* remaining document completely. |
|
479 |
* |
|
480 |
* @return True if there is more document to parse. |
|
481 |
* |
|
482 |
* @exception XNIException Any XNI exception, possibly wrapping |
|
483 |
* another exception. |
|
484 |
* @exception IOException An IO exception from the parser, possibly |
|
485 |
* from a byte stream or character stream |
|
486 |
* supplied by the parser. |
|
487 |
* |
|
488 |
* @see #setInputSource |
|
489 |
*/ |
|
490 |
public boolean parse(boolean complete) throws XNIException, IOException { |
|
491 |
// |
|
492 |
// reset and configure pipeline and set InputSource. |
|
493 |
if (fInputSource !=null) { |
|
494 |
try { |
|
495 |
// resets and sets the pipeline. |
|
496 |
reset(); |
|
497 |
fScanner.setInputSource(fInputSource); |
|
498 |
fInputSource = null; |
|
499 |
} |
|
500 |
catch (XNIException ex) { |
|
501 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
502 |
ex.printStackTrace(); |
|
503 |
throw ex; |
|
504 |
} |
|
505 |
catch (IOException ex) { |
|
506 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
507 |
ex.printStackTrace(); |
|
508 |
throw ex; |
|
509 |
} |
|
510 |
catch (RuntimeException ex) { |
|
511 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
512 |
ex.printStackTrace(); |
|
513 |
throw ex; |
|
514 |
} |
|
515 |
catch (Exception ex) { |
|
516 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
517 |
ex.printStackTrace(); |
|
518 |
throw new XNIException(ex); |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
try { |
|
523 |
return fScanner.scanDocument(complete); |
|
524 |
} |
|
525 |
catch (XNIException ex) { |
|
526 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
527 |
ex.printStackTrace(); |
|
528 |
throw ex; |
|
529 |
} |
|
530 |
catch (IOException ex) { |
|
531 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
532 |
ex.printStackTrace(); |
|
533 |
throw ex; |
|
534 |
} |
|
535 |
catch (RuntimeException ex) { |
|
536 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
537 |
ex.printStackTrace(); |
|
538 |
throw ex; |
|
539 |
} |
|
540 |
catch (Exception ex) { |
|
541 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
542 |
ex.printStackTrace(); |
|
543 |
throw new XNIException(ex); |
|
544 |
} |
|
545 |
||
546 |
} // parse(boolean):boolean |
|
547 |
||
548 |
/** |
|
549 |
* If the application decides to terminate parsing before the xml document |
|
550 |
* is fully parsed, the application should call this method to free any |
|
551 |
* resource allocated during parsing. For example, close all opened streams. |
|
552 |
*/ |
|
553 |
public void cleanup() { |
|
554 |
fEntityManager.closeReaders(); |
|
555 |
} |
|
556 |
||
557 |
// |
|
558 |
// XMLParserConfiguration methods |
|
559 |
// |
|
560 |
||
561 |
/** |
|
562 |
* Parses the specified input source. |
|
563 |
* |
|
564 |
* @param source The input source. |
|
565 |
* |
|
566 |
* @exception XNIException Throws exception on XNI error. |
|
567 |
* @exception java.io.IOException Throws exception on i/o error. |
|
568 |
*/ |
|
569 |
public void parse(XMLInputSource source) throws XNIException, IOException { |
|
570 |
||
571 |
if (fParseInProgress) { |
|
572 |
// REVISIT - need to add new error message |
|
573 |
throw new XNIException("FWK005 parse may not be called while parsing."); |
|
574 |
} |
|
575 |
fParseInProgress = true; |
|
576 |
||
577 |
try { |
|
578 |
setInputSource(source); |
|
579 |
parse(true); |
|
580 |
} |
|
581 |
catch (XNIException ex) { |
|
582 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
583 |
ex.printStackTrace(); |
|
584 |
throw ex; |
|
585 |
} |
|
586 |
catch (IOException ex) { |
|
587 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
588 |
ex.printStackTrace(); |
|
589 |
throw ex; |
|
590 |
} |
|
591 |
catch (RuntimeException ex) { |
|
592 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
593 |
ex.printStackTrace(); |
|
594 |
throw ex; |
|
595 |
} |
|
596 |
catch (Exception ex) { |
|
597 |
if (PRINT_EXCEPTION_STACK_TRACE) |
|
598 |
ex.printStackTrace(); |
|
599 |
throw new XNIException(ex); |
|
600 |
} |
|
601 |
finally { |
|
602 |
fParseInProgress = false; |
|
603 |
// close all streams opened by xerces |
|
604 |
this.cleanup(); |
|
605 |
} |
|
606 |
||
607 |
} // parse(InputSource) |
|
608 |
||
609 |
// |
|
610 |
// Protected methods |
|
611 |
// |
|
612 |
||
613 |
/** |
|
614 |
* Reset all components before parsing. |
|
615 |
* |
|
616 |
* @throws XNIException Thrown if an error occurs during initialization. |
|
617 |
*/ |
|
618 |
protected void reset() throws XNIException { |
|
619 |
||
620 |
if (fValidationManager != null) |
|
621 |
fValidationManager.reset(); |
|
622 |
// configure the pipeline and initialize the components |
|
623 |
configurePipeline(); |
|
624 |
super.reset(); |
|
625 |
||
626 |
} // reset() |
|
627 |
||
628 |
/** Configures the pipeline. */ |
|
629 |
protected void configurePipeline() { |
|
630 |
// create appropriate scanner |
|
631 |
// and register it as one of the components. |
|
632 |
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { |
|
633 |
if (fNamespaceScanner == null) { |
|
634 |
fNamespaceScanner = new XMLNSDocumentScannerImpl(); |
|
635 |
addComponent((XMLComponent)fNamespaceScanner); |
|
636 |
} |
|
637 |
fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); |
|
638 |
fNamespaceScanner.setDTDValidator(null); |
|
639 |
fScanner = fNamespaceScanner; |
|
640 |
} |
|
641 |
else { |
|
642 |
if (fNonNSScanner == null) { |
|
643 |
fNonNSScanner = new XMLDocumentScannerImpl(); |
|
644 |
addComponent((XMLComponent)fNonNSScanner); |
|
645 |
} |
|
646 |
fProperties.put(DOCUMENT_SCANNER, fNonNSScanner); |
|
647 |
fScanner = fNonNSScanner; |
|
648 |
} |
|
649 |
||
650 |
fScanner.setDocumentHandler(fDocumentHandler); |
|
651 |
fLastComponent = fScanner; |
|
652 |
// setup dtd pipeline |
|
653 |
if (fDTDScanner != null) { |
|
654 |
fDTDScanner.setDTDHandler(fDTDHandler); |
|
655 |
fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler); |
|
656 |
} |
|
657 |
||
658 |
||
659 |
} // configurePipeline() |
|
660 |
||
661 |
// features and properties |
|
662 |
||
663 |
/** |
|
664 |
* Check a feature. If feature is know and supported, this method simply |
|
665 |
* returns. Otherwise, the appropriate exception is thrown. |
|
666 |
* |
|
667 |
* @param featureId The unique identifier (URI) of the feature. |
|
668 |
* |
|
669 |
* @throws XMLConfigurationException Thrown for configuration error. |
|
670 |
* In general, components should |
|
671 |
* only throw this exception if |
|
672 |
* it is <strong>really</strong> |
|
673 |
* a critical error. |
|
674 |
*/ |
|
675 |
protected FeatureState checkFeature(String featureId) |
|
676 |
throws XMLConfigurationException { |
|
677 |
||
678 |
// |
|
679 |
// Xerces Features |
|
680 |
// |
|
681 |
||
682 |
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { |
|
683 |
final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); |
|
684 |
||
685 |
// |
|
686 |
// http://apache.org/xml/features/validation/dynamic |
|
687 |
// Allows the parser to validate a document only when it |
|
688 |
// contains a grammar. Validation is turned on/off based |
|
689 |
// on each document instance, automatically. |
|
690 |
// |
|
691 |
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && |
|
692 |
featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { |
|
693 |
return FeatureState.RECOGNIZED; |
|
694 |
} |
|
695 |
// |
|
696 |
// http://apache.org/xml/features/validation/default-attribute-values |
|
697 |
// |
|
698 |
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && |
|
699 |
featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { |
|
700 |
// REVISIT |
|
701 |
return FeatureState.NOT_SUPPORTED; |
|
702 |
} |
|
703 |
// |
|
704 |
// http://apache.org/xml/features/validation/default-attribute-values |
|
705 |
// |
|
706 |
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && |
|
707 |
featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { |
|
708 |
// REVISIT |
|
709 |
return FeatureState.NOT_SUPPORTED; |
|
710 |
} |
|
711 |
// |
|
712 |
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar |
|
713 |
// |
|
714 |
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && |
|
715 |
featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { |
|
716 |
return FeatureState.RECOGNIZED; |
|
717 |
} |
|
718 |
// |
|
719 |
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd |
|
720 |
// |
|
721 |
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && |
|
722 |
featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { |
|
723 |
return FeatureState.RECOGNIZED; |
|
724 |
} |
|
725 |
||
726 |
// |
|
727 |
// http://apache.org/xml/features/validation/default-attribute-values |
|
728 |
// |
|
729 |
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && |
|
730 |
featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { |
|
731 |
return FeatureState.NOT_SUPPORTED; |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
// |
|
736 |
// Not recognized |
|
737 |
// |
|
738 |
||
739 |
return super.checkFeature(featureId); |
|
740 |
||
741 |
} // checkFeature(String) |
|
742 |
||
743 |
/** |
|
744 |
* Check a property. If the property is know and supported, this method |
|
745 |
* simply returns. Otherwise, the appropriate exception is thrown. |
|
746 |
* |
|
747 |
* @param propertyId The unique identifier (URI) of the property |
|
748 |
* being set. |
|
749 |
* |
|
750 |
* @throws XMLConfigurationException Thrown for configuration error. |
|
751 |
* In general, components should |
|
752 |
* only throw this exception if |
|
753 |
* it is <strong>really</strong> |
|
754 |
* a critical error. |
|
755 |
*/ |
|
756 |
protected PropertyState checkProperty(String propertyId) |
|
757 |
throws XMLConfigurationException { |
|
758 |
||
759 |
// |
|
760 |
// Xerces Properties |
|
761 |
// |
|
762 |
||
763 |
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { |
|
764 |
final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); |
|
765 |
||
766 |
if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && |
|
767 |
propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { |
|
768 |
return PropertyState.RECOGNIZED; |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) { |
|
773 |
final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length(); |
|
774 |
||
775 |
if (suffixLength == Constants.SCHEMA_SOURCE.length() && |
|
776 |
propertyId.endsWith(Constants.SCHEMA_SOURCE)) { |
|
777 |
return PropertyState.RECOGNIZED; |
|
778 |
} |
|
779 |
} |
|
780 |
||
781 |
// |
|
782 |
// Not recognized |
|
783 |
// |
|
784 |
||
785 |
return super.checkProperty(propertyId); |
|
786 |
||
787 |
} // checkProperty(String) |
|
788 |
||
789 |
// factory methods |
|
790 |
||
791 |
/** Creates an entity manager. */ |
|
792 |
protected XMLEntityManager createEntityManager() { |
|
793 |
return new XMLEntityManager(); |
|
794 |
} // createEntityManager():XMLEntityManager |
|
795 |
||
796 |
/** Creates an error reporter. */ |
|
797 |
protected XMLErrorReporter createErrorReporter() { |
|
798 |
return new XMLErrorReporter(); |
|
799 |
} // createErrorReporter():XMLErrorReporter |
|
800 |
||
801 |
/** Create a document scanner. */ |
|
802 |
protected XMLDocumentScanner createDocumentScanner() { |
|
803 |
return null; |
|
804 |
} // createDocumentScanner():XMLDocumentScanner |
|
805 |
||
806 |
/** Create a DTD scanner. */ |
|
807 |
protected XMLDTDScanner createDTDScanner() { |
|
808 |
return new XMLDTDScannerImpl(); |
|
809 |
} // createDTDScanner():XMLDTDScanner |
|
810 |
||
811 |
/** Create a datatype validator factory. */ |
|
812 |
protected DTDDVFactory createDatatypeValidatorFactory() { |
|
813 |
return DTDDVFactory.getInstance(); |
|
814 |
} // createDatatypeValidatorFactory():DatatypeValidatorFactory |
|
815 |
protected ValidationManager createValidationManager(){ |
|
816 |
return new ValidationManager(); |
|
817 |
} |
|
818 |
||
819 |
} // class NonValidatingConfiguration |