ErrorReporter.getErrorHandler().reportError("File not found:"+filename);
is = new ResourceLocator("config.xml").getInputStream();
}
} catch (IOException e) {
ErrorReporter.getErrorHandler().reportError("Cannot load file:"+filename,e);
throw new ConfigurationManagerException(e.getLocalizedMessage());
}
if ( is != null ) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// set the validation flag (true if it should be validated)
dbf.setValidating(validate);
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
ErrorReporter.getErrorHandler().reportError("The parser cannot create a new document builder",pce);
throw new ConfigurationManagerException("The parser cannot create a new document builder: " + pce.getMessage());
}
// if we have to validate then we need to define an error handler here
if (validate) {
try {
// Set an ErrorHandler before parsing
OutputStreamWriter errorWriter =
new OutputStreamWriter(System.err, "UTF-8");
db.setErrorHandler(new ConfigErrorHandler(new PrintWriter(errorWriter, true)));
//new MyErrorHandler(new PrintWriter(errorWriter, true)));
} catch (Exception e) {
ErrorReporter.getErrorHandler().reportError("The parser cannot set up the error handler",e);
throw new ConfigurationManagerException("The parser cannot set up the error handler");
}
}
Document doc = null;
try {
doc = db.parse(is);
} catch (SAXException se) {
ErrorReporter.getErrorHandler().reportError("The parser cannot parse the file",se);
throw new ConfigurationManagerException("The parser cannot parse the file: " + se.getMessage());
} catch (IOException ioe) {
ErrorReporter.getErrorHandler().reportError("The parser cannot open the file",ioe);
throw new ConfigurationManagerException("The parser cannot open the file: " + ioe.getMessage());
}
Configuration config = parser.parse(doc, configurationName);
config.resetCreated();
return config;
}
else {
ErrorReporter.getErrorHandler().reportError("The file:"+filename+" not found in classpath");
throw new ConfigurationManagerException("The file could not be found in the classpath");
}
}