private static Document loadBundle(final ClassLoader loader, final String bundleName) {
// Next search for a Properties file.
InputStream stream = (InputStream)java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
if (loader != null) {
return loader.getResourceAsStream(bundleName);
} else {
return ClassLoader.getSystemResourceAsStream(bundleName);
}
}
}
);
if (stream != null) {
try {
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse(stream);
return doc;
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
stream.close();
} catch (Exception e) {
// to avoid propagating an IOException back into the caller
// (I'm assuming this is never going to happen, and if it does,
// I'm obeying the precedent of swallowing exceptions set by the
// existing code above)
}
}
}
return null;
}