Fields Summary |
---|
private static final String | PARSER_SETTINGSFeature identifier: parser settings. |
private static final String | ENTITY_RESOLVERProperty identifier: entity resolver. |
private static final String | ERROR_HANDLERProperty identifier: error handler. |
private static final String | ERROR_REPORTERProperty identifier: error reporter. |
private static final String | SCHEMA_VALIDATORProperty identifier: XML Schema validator. |
private static final String | SYMBOL_TABLEProperty identifier: symbol table. |
private static final String | VALIDATION_MANAGERProperty identifier: validation manager. |
private SoftReference | fConfigurationSoftReference to parser configuration. |
private final org.apache.xerces.impl.xs.XMLSchemaValidator | fSchemaValidatorSchema validator. |
private final XMLSchemaValidatorComponentManager | fComponentManagerComponent manager. |
Methods Summary |
---|
private org.apache.xerces.xni.parser.XMLParserConfiguration | initialize()
XML11Configuration config = new XML11Configuration();
config.setProperty(ENTITY_RESOLVER, fComponentManager.getProperty(ENTITY_RESOLVER));
config.setProperty(ERROR_HANDLER, fComponentManager.getProperty(ERROR_HANDLER));
XMLErrorReporter errorReporter = (XMLErrorReporter) fComponentManager.getProperty(ERROR_REPORTER);
config.setProperty(ERROR_REPORTER, errorReporter);
// add message formatters
if (errorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
XMLMessageFormatter xmft = new XMLMessageFormatter();
errorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
errorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
}
config.setProperty(SYMBOL_TABLE, fComponentManager.getProperty(SYMBOL_TABLE));
config.setProperty(VALIDATION_MANAGER, fComponentManager.getProperty(VALIDATION_MANAGER));
config.setDocumentHandler(fSchemaValidator);
config.setDTDHandler(null);
config.setDTDContentModelHandler(null);
fConfiguration = new SoftReference(config);
return config;
|
public void | validate(javax.xml.transform.Source source, javax.xml.transform.Result result)
if (result == null) {
final StreamSource streamSource = (StreamSource) source;
XMLInputSource input = new XMLInputSource(streamSource.getPublicId(), streamSource.getSystemId(), null);
input.setByteStream(streamSource.getInputStream());
input.setCharacterStream(streamSource.getReader());
// Gets the parser configuration. We'll create and initialize a new one, if we
// haven't created one before or if the previous one was garbage collected.
XMLParserConfiguration config = (XMLParserConfiguration) fConfiguration.get();
if (config == null) {
config = initialize();
}
// If settings have changed on the component manager, refresh the error handler and entity resolver.
else if (fComponentManager.getFeature(PARSER_SETTINGS)) {
config.setProperty(ENTITY_RESOLVER, fComponentManager.getProperty(ENTITY_RESOLVER));
config.setProperty(ERROR_HANDLER, fComponentManager.getProperty(ERROR_HANDLER));
}
// prepare for parse
fComponentManager.reset();
fSchemaValidator.setDocumentHandler(null);
try {
config.parse(input);
}
catch (XMLParseException e) {
throw Util.toSAXParseException(e);
}
catch (XNIException e) {
throw Util.toSAXException(e);
}
return;
}
throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SourceResultMismatch",
new Object [] {source.getClass().getName(), result.getClass().getName()}));
|