Document loadDocument(Resource resource) {
Assert.notNull(resource);
EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
InputStream inputStream = null;
try {
// this will throw an IOException if the stream cannot be opened
inputStream = encodedResource.getResource().getInputStream();
}
catch (IOException e) {
throw new ConfigurationException(
"Could not load module definition, as unable to obtain input stream for resource "
+ encodedResource.getResource(), e);
}
Document document = null;
DefaultDocumentLoader loader = new DefaultDocumentLoader();
try {
InputSource inputSource = new InputSource(inputStream);
inputSource.setEncoding(encodedResource.getEncoding());
document = loader.loadDocument(inputSource, null, new SimpleSaxErrorHandler(logger),
XmlBeanDefinitionReader.VALIDATION_NONE, false);
}
catch (Exception e) {
throw new ConfigurationException("Unable to load XML module definition document from resource "
+ encodedResource.getResource(), e);
}
finally {
try {
if (inputStream != null)
inputStream.close();