org.springframework.beans.factory.xml
public class: DefaultDocumentLoader [javadoc |
source]
java.lang.Object
org.springframework.beans.factory.xml.DefaultDocumentLoader
All Implemented Interfaces:
DocumentLoader
Spring's default
DocumentLoader implementation.
Simply loads documents using the standard JAXP-configured
XML parser. If you want to change the DocumentBuilder that is used to
load documents, then one strategy is to define a corresponding Java system property
when starting your JVM. For example, to use the Oracle DocumentBuilder ,
you might start your application like as follows:
java -Djavax.xml.parsers.DocumentBuilderFactory=oracle.xml.jaxp.JXDocumentBuilderFactory MyMainClass
- author:
Rob - Harrop
- author:
Juergen - Hoeller
- since:
2.0 -
| Method from org.springframework.beans.factory.xml.DefaultDocumentLoader Detail: |
protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory,
EntityResolver entityResolver,
ErrorHandler errorHandler) throws ParserConfigurationException {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
if (entityResolver != null) {
docBuilder.setEntityResolver(entityResolver);
}
if (errorHandler != null) {
docBuilder.setErrorHandler(errorHandler);
}
return docBuilder;
}
Create a JAXP DocumentBuilder that this bean definition reader
will use for parsing XML documents. Can be overridden in subclasses,
adding further initialization of the builder. |
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode,
boolean namespaceAware) throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(namespaceAware);
if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
factory.setValidating(true);
if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
// Enforce namespace aware for XSD...
factory.setNamespaceAware(true);
try {
factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
}
catch (IllegalArgumentException ex) {
ParserConfigurationException pcex = new ParserConfigurationException(
"Unable to validate using XSD: Your JAXP provider [" + factory +
"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
pcex.initCause(ex);
throw pcex;
}
}
}
return factory;
}
|
public Document loadDocument(InputSource inputSource,
EntityResolver entityResolver,
ErrorHandler errorHandler,
int validationMode,
boolean namespaceAware) throws Exception {
DocumentBuilderFactory factory = createDocumentBuilderFactory(validationMode, namespaceAware);
if (logger.isDebugEnabled()) {
logger.debug("Using JAXP provider [" + factory.getClass().getName() + "]");
}
DocumentBuilder builder = createDocumentBuilder(factory, entityResolver, errorHandler);
return builder.parse(inputSource);
}
|