use of org.jdom.JDOMException in project vcell by virtualcell.
the class XmlUtil method readXML.
// useful for the translators.
public static Document readXML(Reader reader, String schemaLocation, String parserClass, String schemaLocationPropName) throws RuntimeException {
SAXBuilder builder = null;
Document sDoc = null;
GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
try {
if (schemaLocation != null && schemaLocation.length() > 0) {
// ignores the parserClass, since xerces is the only validating parser we have
builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature("http://xml.org/sax/features/validation", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setErrorHandler(errorHandler);
builder.setProperty(schemaLocationPropName, schemaLocation);
} else {
// ignore schemaLocationPropName
if (parserClass == null) {
// not necessarily 'xerces'
builder = new SAXBuilder(false);
} else {
builder = new SAXBuilder(parserClass, false);
}
builder.setErrorHandler(errorHandler);
}
sDoc = builder.build(reader);
// ----- Element root = null;
// ----- root = sDoc.getRootElement();
// flush/replace previous error log with every read.
String errorHandlerLog = errorHandler.getErrorLog();
if (errorHandlerLog.length() > 0) {
System.out.println(errorHandlerLog);
XmlUtil.errorLog = errorHandlerLog;
} else {
XmlUtil.errorLog = "";
}
} catch (JDOMException e) {
e.printStackTrace();
throw new RuntimeException("source document is not well-formed\n" + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unable to read source document\n" + e.getMessage());
}
return sDoc;
}
use of org.jdom.JDOMException in project vcell by virtualcell.
the class SBMLUtils method readXML.
public static Element readXML(Reader reader) throws IOException, SbmlException {
try {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = builder.build(reader);
Element root = sDoc.getRootElement();
return root;
} catch (JDOMException e) {
e.printStackTrace(System.out);
throw new SbmlException(e.getMessage());
}
}
Aggregations