18 * limitations under the License. |
18 * limitations under the License. |
19 */ |
19 */ |
20 |
20 |
21 package com.sun.org.apache.xerces.internal.parsers; |
21 package com.sun.org.apache.xerces.internal.parsers; |
22 |
22 |
|
23 import java.io.File; |
23 import java.io.IOException; |
24 import java.io.IOException; |
24 import java.util.ArrayList; |
25 import java.util.ArrayList; |
25 import java.util.HashMap; |
26 import java.util.HashMap; |
26 import java.util.Locale; |
27 import java.util.Locale; |
|
28 import java.util.Properties; |
|
29 import javax.xml.XMLConstants; |
27 |
30 |
28 import com.sun.org.apache.xerces.internal.impl.Constants; |
31 import com.sun.org.apache.xerces.internal.impl.Constants; |
29 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl; |
32 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl; |
30 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl; |
33 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl; |
31 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl; |
34 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl; |
50 import com.sun.org.apache.xerces.internal.util.FeatureState; |
53 import com.sun.org.apache.xerces.internal.util.FeatureState; |
51 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; |
54 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; |
52 import com.sun.org.apache.xerces.internal.util.PropertyState; |
55 import com.sun.org.apache.xerces.internal.util.PropertyState; |
53 import com.sun.org.apache.xerces.internal.util.Status; |
56 import com.sun.org.apache.xerces.internal.util.Status; |
54 import com.sun.org.apache.xerces.internal.util.SymbolTable; |
57 import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
58 import com.sun.org.apache.xerces.internal.utils.SecuritySupport; |
55 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; |
59 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; |
56 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; |
60 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; |
57 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; |
61 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; |
58 import com.sun.org.apache.xerces.internal.xni.XMLLocator; |
62 import com.sun.org.apache.xerces.internal.xni.XMLLocator; |
59 import com.sun.org.apache.xerces.internal.xni.XNIException; |
63 import com.sun.org.apache.xerces.internal.xni.XNIException; |
271 Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; |
275 Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; |
272 |
276 |
273 /** Property identifier: Schema DV Factory */ |
277 /** Property identifier: Schema DV Factory */ |
274 protected static final String SCHEMA_DV_FACTORY = |
278 protected static final String SCHEMA_DV_FACTORY = |
275 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY; |
279 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY; |
|
280 |
|
281 /** Property identifier: access to external dtd */ |
|
282 protected static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD; |
|
283 |
|
284 /** Property identifier: access to external schema */ |
|
285 protected static final String ACCESS_EXTERNAL_SCHEMA = XMLConstants.ACCESS_EXTERNAL_SCHEMA; |
276 |
286 |
277 // debugging |
287 // debugging |
278 |
288 |
279 /** Set to true and recompile to print exception stack trace. */ |
289 /** Set to true and recompile to print exception stack trace. */ |
280 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; |
290 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; |
473 // features might not have been set and it would cause a |
483 // features might not have been set and it would cause a |
474 // not-recognized exception to be thrown. -Ac |
484 // not-recognized exception to be thrown. -Ac |
475 XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING, |
485 XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING, |
476 EXTERNAL_GENERAL_ENTITIES, |
486 EXTERNAL_GENERAL_ENTITIES, |
477 EXTERNAL_PARAMETER_ENTITIES, |
487 EXTERNAL_PARAMETER_ENTITIES, |
478 PARSER_SETTINGS |
488 PARSER_SETTINGS, |
|
489 XMLConstants.FEATURE_SECURE_PROCESSING |
479 }; |
490 }; |
480 addRecognizedFeatures(recognizedFeatures); |
491 addRecognizedFeatures(recognizedFeatures); |
481 // set state for default features |
492 // set state for default features |
482 fFeatures.put(VALIDATION, Boolean.FALSE); |
493 fFeatures.put(VALIDATION, Boolean.FALSE); |
483 fFeatures.put(NAMESPACES, Boolean.TRUE); |
494 fFeatures.put(NAMESPACES, Boolean.TRUE); |
486 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); |
497 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); |
487 fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE); |
498 fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE); |
488 fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE); |
499 fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE); |
489 fFeatures.put(NORMALIZE_DATA, Boolean.TRUE); |
500 fFeatures.put(NORMALIZE_DATA, Boolean.TRUE); |
490 fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); |
501 fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); |
491 fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE); |
502 fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE); |
492 fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE); |
503 fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE); |
493 fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE); |
504 fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE); |
494 fFeatures.put(NAMESPACE_GROWTH, Boolean.FALSE); |
505 fFeatures.put(NAMESPACE_GROWTH, Boolean.FALSE); |
495 fFeatures.put(TOLERATE_DUPLICATES, Boolean.FALSE); |
506 fFeatures.put(TOLERATE_DUPLICATES, Boolean.FALSE); |
496 fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE); |
507 fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE); |
497 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); |
508 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); |
|
509 fFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); |
498 |
510 |
499 // add default recognized properties |
511 // add default recognized properties |
500 final String[] recognizedProperties = |
512 final String[] recognizedProperties = |
501 { |
513 { |
502 SYMBOL_TABLE, |
514 SYMBOL_TABLE, |
503 ERROR_HANDLER, |
515 ERROR_HANDLER, |
504 ENTITY_RESOLVER, |
516 ENTITY_RESOLVER, |
505 ERROR_REPORTER, |
517 ERROR_REPORTER, |
506 ENTITY_MANAGER, |
518 ENTITY_MANAGER, |
507 DOCUMENT_SCANNER, |
519 DOCUMENT_SCANNER, |
508 DTD_SCANNER, |
520 DTD_SCANNER, |
509 DTD_PROCESSOR, |
521 DTD_PROCESSOR, |
510 DTD_VALIDATOR, |
522 DTD_VALIDATOR, |
511 DATATYPE_VALIDATOR_FACTORY, |
523 DATATYPE_VALIDATOR_FACTORY, |
512 VALIDATION_MANAGER, |
524 VALIDATION_MANAGER, |
513 SCHEMA_VALIDATOR, |
525 SCHEMA_VALIDATOR, |
514 XML_STRING, |
526 XML_STRING, |
515 XMLGRAMMAR_POOL, |
527 XMLGRAMMAR_POOL, |
516 JAXP_SCHEMA_SOURCE, |
528 JAXP_SCHEMA_SOURCE, |
517 JAXP_SCHEMA_LANGUAGE, |
529 JAXP_SCHEMA_LANGUAGE, |
518 // NOTE: These shouldn't really be here but since the XML Schema |
530 // NOTE: These shouldn't really be here but since the XML Schema |
519 // validator is constructed dynamically, its recognized |
531 // validator is constructed dynamically, its recognized |
521 // not-recognized exception to be thrown. -Ac |
533 // not-recognized exception to be thrown. -Ac |
522 SCHEMA_LOCATION, |
534 SCHEMA_LOCATION, |
523 SCHEMA_NONS_LOCATION, |
535 SCHEMA_NONS_LOCATION, |
524 LOCALE, |
536 LOCALE, |
525 SCHEMA_DV_FACTORY, |
537 SCHEMA_DV_FACTORY, |
|
538 ACCESS_EXTERNAL_DTD, |
|
539 ACCESS_EXTERNAL_SCHEMA |
526 }; |
540 }; |
527 addRecognizedProperties(recognizedProperties); |
541 addRecognizedProperties(recognizedProperties); |
528 |
542 |
529 if (symbolTable == null) { |
543 if (symbolTable == null) { |
530 symbolTable = new SymbolTable(); |
544 symbolTable = new SymbolTable(); |
531 } |
545 } |
532 fSymbolTable = symbolTable; |
546 fSymbolTable = symbolTable; |
533 fProperties.put(SYMBOL_TABLE, fSymbolTable); |
547 fProperties.put(SYMBOL_TABLE, fSymbolTable); |
534 |
548 |
535 fGrammarPool = grammarPool; |
549 fGrammarPool = grammarPool; |
536 if (fGrammarPool != null) { |
550 if (fGrammarPool != null) { |
537 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); |
551 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); |
538 } |
552 } |
539 |
553 |
540 fEntityManager = new XMLEntityManager(); |
554 fEntityManager = new XMLEntityManager(); |
541 fProperties.put(ENTITY_MANAGER, fEntityManager); |
555 fProperties.put(ENTITY_MANAGER, fEntityManager); |
542 addCommonComponent(fEntityManager); |
556 addCommonComponent(fEntityManager); |
567 |
581 |
568 fValidationManager = new ValidationManager(); |
582 fValidationManager = new ValidationManager(); |
569 fProperties.put(VALIDATION_MANAGER, fValidationManager); |
583 fProperties.put(VALIDATION_MANAGER, fValidationManager); |
570 |
584 |
571 fVersionDetector = new XMLVersionDetector(); |
585 fVersionDetector = new XMLVersionDetector(); |
|
586 |
|
587 //FEATURE_SECURE_PROCESSING is true, see the feature above |
|
588 String accessExternal = SecuritySupport.getDefaultAccessProperty( |
|
589 Constants.SP_ACCESS_EXTERNAL_DTD, Constants.EXTERNAL_ACCESS_DEFAULT); |
|
590 fProperties.put(ACCESS_EXTERNAL_DTD, accessExternal); |
|
591 |
|
592 accessExternal = SecuritySupport.getDefaultAccessProperty( |
|
593 Constants.SP_ACCESS_EXTERNAL_SCHEMA, Constants.EXTERNAL_ACCESS_DEFAULT); |
|
594 fProperties.put(ACCESS_EXTERNAL_SCHEMA, accessExternal); |
572 |
595 |
573 // add message formatters |
596 // add message formatters |
574 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { |
597 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { |
575 XMLMessageFormatter xmft = new XMLMessageFormatter(); |
598 XMLMessageFormatter xmft = new XMLMessageFormatter(); |
576 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); |
599 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); |