}
}
// Build a document builder
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new DocumentParserException("Cannot build a document builder", e);
}
// Error handler (throwing exceptions)
builder.setErrorHandler(new EasyBeansErrorHandler());
// Dummy entity resolver if there is none
if (entityResolver == null) {
builder.setEntityResolver(new EmptyEntityResolver());
} else {
builder.setEntityResolver(entityResolver);
}
// Parse document
URLConnection urlConnection = null;
try {
urlConnection = url.openConnection();
} catch (IOException e) {
throw new DocumentParserException("Cannot open a connection on URL '" + url + "'", e);
}
urlConnection.setDefaultUseCaches(false);
Reader reader = null;
try {
reader = new InputStreamReader(urlConnection.getInputStream());
} catch (IOException e) {
throw new DocumentParserException("Cannot build an input stream reader on URL '" + url + "'", e);
}
InputSource inputSource = new InputSource(reader);
Document document = null;
try {
document = builder.parse(inputSource);
} catch (SAXException e) {
throw new DocumentParserException("Cannot parse the XML file '" + url + "'.", e);
} catch (IOException e) {
throw new DocumentParserException("Cannot parse the XML file '" + url + "'.", e);
} finally {