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;
39 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
40 import com.sun.org.apache.xerces.internal.xni.XNIException;
41 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
42 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
43 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
44 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
45 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
46 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
47 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
48 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
49
50 /**
51 * This is the non validating parser configuration. It extends the basic
52 * configuration with the set of following parser components:
53 * Document scanner, DTD scanner, namespace binder, document handler.
54 * <p>
55 * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>
56 * non-validating XML processor, since conformant non-validating processor is required
57 * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,
58 * include the replacement text of internal entities, and supply default attribute values".
140
141 /** Property identifier: namespace binder. */
142 protected static final String NAMESPACE_BINDER =
143 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
144
145 /** Property identifier: datatype validator factory. */
146 protected static final String DATATYPE_VALIDATOR_FACTORY =
147 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
148
149 protected static final String VALIDATION_MANAGER =
150 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
151
152 /** Property identifier: XML Schema validator. */
153 protected static final String SCHEMA_VALIDATOR =
154 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
155
156 /** Property identifier: locale. */
157 protected static final String LOCALE =
158 Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
159
160 // debugging
161
162 /** Set to true and recompile to print exception stack trace. */
163 private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
164
165 //
166 // Data
167 //
168
169 // components (non-configurable)
170
171 /** Grammar pool. */
172 protected XMLGrammarPool fGrammarPool;
173
174 /** Datatype validator factory. */
175 protected DTDDVFactory fDatatypeValidatorFactory;
176
177 // components (configurable)
178
179 /** Error reporter. */
293 //setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager
294 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
295 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
296 fFeatures.put(NAMESPACES, Boolean.TRUE);
297 //setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl
298 //setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl
299 //setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
300 //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
301
302 // add default recognized properties
303 final String[] recognizedProperties = {
304 ERROR_REPORTER,
305 ENTITY_MANAGER,
306 DOCUMENT_SCANNER,
307 DTD_SCANNER,
308 DTD_VALIDATOR,
309 NAMESPACE_BINDER,
310 XMLGRAMMAR_POOL,
311 DATATYPE_VALIDATOR_FACTORY,
312 VALIDATION_MANAGER,
313 LOCALE
314 };
315 addRecognizedProperties(recognizedProperties);
316
317 fGrammarPool = grammarPool;
318 if(fGrammarPool != null){
319 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
320 }
321
322 fEntityManager = createEntityManager();
323 fProperties.put(ENTITY_MANAGER, fEntityManager);
324 addComponent(fEntityManager);
325
326 fErrorReporter = createErrorReporter();
327 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
328 fProperties.put(ERROR_REPORTER, fErrorReporter);
329 addComponent(fErrorReporter);
330
331 // this configuration delays creation of the scanner
332 // till it is known if namespace processing should be performed
333
350 fProperties.put(VALIDATION_MANAGER, fValidationManager);
351 }
352 // add message formatters
353 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
354 XMLMessageFormatter xmft = new XMLMessageFormatter();
355 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
356 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
357 }
358
359 fConfigUpdated = false;
360
361 // set locale
362 try {
363 setLocale(Locale.getDefault());
364 }
365 catch (XNIException e) {
366 // do nothing
367 // REVISIT: What is the right thing to do? -Ac
368 }
369
370 } // <init>(SymbolTable,XMLGrammarPool)
371
372 //
373 // Public methods
374 //
375 public void setFeature(String featureId, boolean state)
376 throws XMLConfigurationException {
377 fConfigUpdated = true;
378 super.setFeature(featureId, state);
379 }
380
381 public PropertyState getPropertyState(String propertyId)
382 throws XMLConfigurationException {
383 if (LOCALE.equals(propertyId)) {
384 return PropertyState.is(getLocale());
385 }
386 return super.getPropertyState(propertyId);
387 }
388
389 public void setProperty(String propertyId, Object value)
|
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;
39 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
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;
50
51 /**
52 * This is the non validating parser configuration. It extends the basic
53 * configuration with the set of following parser components:
54 * Document scanner, DTD scanner, namespace binder, document handler.
55 * <p>
56 * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>
57 * non-validating XML processor, since conformant non-validating processor is required
58 * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,
59 * include the replacement text of internal entities, and supply default attribute values".
141
142 /** Property identifier: namespace binder. */
143 protected static final String NAMESPACE_BINDER =
144 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
145
146 /** Property identifier: datatype validator factory. */
147 protected static final String DATATYPE_VALIDATOR_FACTORY =
148 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
149
150 protected static final String VALIDATION_MANAGER =
151 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
152
153 /** Property identifier: XML Schema validator. */
154 protected static final String SCHEMA_VALIDATOR =
155 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
156
157 /** Property identifier: locale. */
158 protected static final String LOCALE =
159 Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
160
161 /** Property identifier: Security property manager. */
162 protected static final String XML_SECURITY_PROPERTY_MANAGER =
163 Constants.XML_SECURITY_PROPERTY_MANAGER;
164
165 // debugging
166
167 /** Set to true and recompile to print exception stack trace. */
168 private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
169
170 //
171 // Data
172 //
173
174 // components (non-configurable)
175
176 /** Grammar pool. */
177 protected XMLGrammarPool fGrammarPool;
178
179 /** Datatype validator factory. */
180 protected DTDDVFactory fDatatypeValidatorFactory;
181
182 // components (configurable)
183
184 /** Error reporter. */
298 //setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager
299 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
300 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
301 fFeatures.put(NAMESPACES, Boolean.TRUE);
302 //setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl
303 //setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl
304 //setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
305 //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
306
307 // add default recognized properties
308 final String[] recognizedProperties = {
309 ERROR_REPORTER,
310 ENTITY_MANAGER,
311 DOCUMENT_SCANNER,
312 DTD_SCANNER,
313 DTD_VALIDATOR,
314 NAMESPACE_BINDER,
315 XMLGRAMMAR_POOL,
316 DATATYPE_VALIDATOR_FACTORY,
317 VALIDATION_MANAGER,
318 LOCALE,
319 XML_SECURITY_PROPERTY_MANAGER
320 };
321 addRecognizedProperties(recognizedProperties);
322
323 fGrammarPool = grammarPool;
324 if(fGrammarPool != null){
325 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
326 }
327
328 fEntityManager = createEntityManager();
329 fProperties.put(ENTITY_MANAGER, fEntityManager);
330 addComponent(fEntityManager);
331
332 fErrorReporter = createErrorReporter();
333 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
334 fProperties.put(ERROR_REPORTER, fErrorReporter);
335 addComponent(fErrorReporter);
336
337 // this configuration delays creation of the scanner
338 // till it is known if namespace processing should be performed
339
356 fProperties.put(VALIDATION_MANAGER, fValidationManager);
357 }
358 // add message formatters
359 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
360 XMLMessageFormatter xmft = new XMLMessageFormatter();
361 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
362 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
363 }
364
365 fConfigUpdated = false;
366
367 // set locale
368 try {
369 setLocale(Locale.getDefault());
370 }
371 catch (XNIException e) {
372 // do nothing
373 // REVISIT: What is the right thing to do? -Ac
374 }
375
376 setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager());
377 } // <init>(SymbolTable,XMLGrammarPool)
378
379 //
380 // Public methods
381 //
382 public void setFeature(String featureId, boolean state)
383 throws XMLConfigurationException {
384 fConfigUpdated = true;
385 super.setFeature(featureId, state);
386 }
387
388 public PropertyState getPropertyState(String propertyId)
389 throws XMLConfigurationException {
390 if (LOCALE.equals(propertyId)) {
391 return PropertyState.is(getLocale());
392 }
393 return super.getPropertyState(propertyId);
394 }
395
396 public void setProperty(String propertyId, Object value)
|