SAXParserImpl(SAXParserFactoryImpl spf,
Hashtable features,
boolean secureProcessing) throws SAXException {
// Instantiate a SAXParser directly and not through SAX so that we use the right ClassLoader
xmlReader = new JAXPSAXParser(this);
// JAXP "namespaceAware" == SAX Namespaces feature
// Note: there is a compatibility problem here with default values:
// JAXP default is false while SAX 2 default is true!
xmlReader.setFeature0(NAMESPACES_FEATURE, spf.isNamespaceAware());
// SAX "namespaces" and "namespace-prefixes" features should not
// both be false. We make them opposite for backward compatibility
// since JAXP 1.0 apps may want to receive xmlns* attributes.
xmlReader.setFeature0(NAMESPACE_PREFIXES_FEATURE, !spf.isNamespaceAware());
// Avoid setting the XInclude processing feature if the value is false.
// This will keep the configuration from throwing an exception if it
// does not support XInclude.
if (spf.isXIncludeAware()) {
xmlReader.setFeature0(XINCLUDE_FEATURE, true);
}
// If the secure processing feature is on set a security manager.
if (secureProcessing) {
xmlReader.setProperty0(SECURITY_MANAGER, new SecurityManager());
}
// Set application's features, followed by validation features.
setFeatures(features);
// If validating, provide a default ErrorHandler that prints
// validation errors with a warning telling the user to set an
// ErrorHandler.
if (spf.isValidating()) {
fInitErrorHandler = new DefaultValidationErrorHandler();
xmlReader.setErrorHandler(fInitErrorHandler);
}
else {
fInitErrorHandler = xmlReader.getErrorHandler();
}
xmlReader.setFeature0(VALIDATION_FEATURE, spf.isValidating());
// Get the Schema object from the factory
this.grammar = spf.getSchema();
if (grammar != null) {
XMLParserConfiguration config = xmlReader.getXMLParserConfiguration();
XMLComponent validatorComponent = null;
/** For Xerces grammars, use built-in schema validator. **/
if (grammar instanceof XSGrammarPoolContainer) {
validatorComponent = new XMLSchemaValidator();
fSchemaValidationManager = new ValidationManager();
fUnparsedEntityHandler = new UnparsedEntityHandler(fSchemaValidationManager);
config.setDTDHandler(fUnparsedEntityHandler);
fUnparsedEntityHandler.setDTDHandler(xmlReader);
xmlReader.setDTDSource(fUnparsedEntityHandler);
fSchemaValidatorComponentManager = new SchemaValidatorConfiguration(config,
(XSGrammarPoolContainer) grammar, fSchemaValidationManager);
}
/** For third party grammars, use the JAXP validator component. **/
else {
validatorComponent = new JAXPValidatorComponent(grammar.newValidatorHandler());
fSchemaValidatorComponentManager = config;
}
config.addRecognizedFeatures(validatorComponent.getRecognizedFeatures());
config.addRecognizedProperties(validatorComponent.getRecognizedProperties());
config.setDocumentHandler((XMLDocumentHandler) validatorComponent);
((XMLDocumentSource)validatorComponent).setDocumentHandler(xmlReader);
xmlReader.setDocumentSource((XMLDocumentSource) validatorComponent);
fSchemaValidator = validatorComponent;
}
// Initial EntityResolver
fInitEntityResolver = xmlReader.getEntityResolver();
}
Create a SAX parser with the associated features Parameters:
features - Hashtable of SAX features, may be null
|