public static SBMLErrorLog checkConsistency(String xmlValidationString)
{
Logger logger = Logger.getLogger(SBMLValidator.class);
if (xmlValidationString == null || xmlValidationString.trim().length() == 0) {
return new SBMLErrorLog();
}
StringReader reader = new StringReader(xmlValidationString);
// DEBUG
logger.debug(xmlValidationString);
// Defining all the rules to parse the XML
XStream xstream = new XStream(new DomDriver()); // To parse XML using DOM
// XStream xstream = new XStream(new StaxDriver()); // To parse XML using Stax
xstream.alias("validation-results", SBMLErrorLog.class);
xstream.alias("option", Option.class);
xstream.alias("problem", SBMLError.class);
xstream.alias("location", Location.class);
xstream.alias("detail", Detail.class);
// xstream.registerConverter(new MessageConverter(), XStream.PRIORITY_VERY_HIGH);
xstream.registerLocalConverter(SBMLError.class, "message", new MessageConverter("message"));
xstream.registerLocalConverter(SBMLError.class, "shortmessage", new MessageConverter("shortmessage"));
xstream.alias("message", Message.class);
xstream.alias("shortmessage", Message.class);
xstream.addImplicitCollection(SBMLErrorLog.class, "options",
"option", Option.class);
xstream.addImplicitCollection(SBMLErrorLog.class,
"validationErrors", "problem", SBMLError.class);
xstream.aliasField("error", SBMLErrorLog.class, "status");
xstream.aliasField("warning", SBMLErrorLog.class, "status");
xstream.aliasField("no-errors", SBMLErrorLog.class, "status");
xstream.aliasField("file-not-readable", SBMLErrorLog.class, "status");
xstream.aliasField("out-of-memory", SBMLErrorLog.class, "status");
xstream.aliasField("segmentation-fault", SBMLErrorLog.class, "status");
xstream.aliasField("internal-error", SBMLErrorLog.class, "status");
xstream.useAttributeFor(File.class);
xstream.useAttributeFor(Option.class, "name");
xstream.useAttributeFor(Option.class, "status");
xstream.useAttributeFor(SBMLError.class, "category");
xstream.useAttributeFor(SBMLError.class, "code");
xstream.useAttributeFor(SBMLError.class, "severity");
xstream.useAttributeFor(Location.class, "line");
xstream.useAttributeFor(Location.class, "column");
xstream.useAttributeFor(Detail.class, "category");
xstream.useAttributeFor(Detail.class, "severity");
try {
SBMLErrorLog sbmlErrorLog = (SBMLErrorLog) xstream.fromXML(reader);
logger.debug("Call and Parsing of the results done !!!");
// logger.debug("File = " + resultsObj.getFile().getName());
// logger.debug("Nb Options = " + resultsObj.getOptions().size());
// logger.debug(resultsObj.getOptions());
logger.debug("Nb Problems = " + sbmlErrorLog.getValidationErrors().size());
if (sbmlErrorLog.getValidationErrors().size() > 0) {
logger.debug("ValidationError(0) = " + sbmlErrorLog.getValidationErrors().get(0));
}
return sbmlErrorLog;
} catch (XStreamException e) {
logger.error("There has been an error parsing the consistency check XML result : " + e.getMessage());
if (logger.isDebugEnabled()) {
e.printStackTrace();
}
}
return new SBMLErrorLog();
}