*
* @throws IOException
*/
public LayoutDefinition read() throws IOException {
// Open the URL
InputStream inputStream = new IncludeInputStream(
new BufferedInputStream(getURL().openStream()));
Document doc = null;
try {
// Get a DocumentBuilderFactory and set it up
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(false);
dbf.setCoalescing(false);
// The opposite of creating entity ref nodes is expanding inline
dbf.setExpandEntityReferences(true);
// Get a DocumentBuilder...
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
throw new RuntimeException(ex);
}
if (getEntityResolver() != null) {
db.setEntityResolver(getEntityResolver());
}
if (getErrorHandler() != null) {
db.setErrorHandler(getErrorHandler());
}
// Parse the XML file
try {
doc = db.parse(inputStream, getBaseURI());
} catch (IOException ex) {
throw new SyntaxException("Unable to parse XML file!", ex);
} catch (SAXException ex) {
throw new SyntaxException(ex);
}
} finally {
try {
inputStream.close();
} catch (Exception ex) {
// Ignore...
}
}