use of org.jlibsedml.SedMLError in project vcell by virtualcell.
the class SchematronValidator method validate.
public List<SedMLError> validate() throws XMLException {
// first of all, get Validation report from Schematron stylesheets.
SEDMLDocument seddoc = new SEDMLDocument(sedml);
List<SedMLError> rc = new ArrayList<SedMLError>();
String docAsString = seddoc.writeDocumentToString();
String schematron = getSchematronXSL();
InputStream is2 = SchematronValidator.class.getClassLoader().getResourceAsStream(schematron);
TransformerFactory tf = TransformerFactory.newInstance();
StreamSource ss = new StreamSource(is2);
Transformer transformer = null;
try {
transformer = tf.newTransformer(ss);
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
StreamResult target = new StreamResult(baos);
try {
transformer.transform(new StreamSource(new StringReader(docAsString)), target);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// now use XPath to get the failed asserts, and from the location
// XPaths,
// get the SEDML element. From there, identify the line number in the
// document.
String validationReportXML = new String(baos.toByteArray());
NodeList nodes = getFailedAssertNodesFromReport(validationReportXML);
for (int i = 0; i < nodes.getLength(); i++) {
NamedNodeMap nnm = nodes.item(i).getAttributes();
String locationInSEDMLXPath = nnm.getNamedItem("location").getNodeValue();
NodeList sedNodes = getSedmlNodes(locationInSEDMLXPath, docAsString);
if (sedNodes.getLength() > 0) {
Node sedmlNode = sedNodes.item(0);
String msgText = getMessageFromAssertFailedNode(nodes, i);
if (sedmlNode.getAttributes().getNamedItem("id") != null) {
int num = getLineNumber(sedmlNode);
rc.add(new SedMLError(num, msgText, ERROR_SEVERITY.ERROR));
} else if (sedmlNode.getLocalName().equals("ci") || sedmlNode.getLocalName().equals("cn")) {
rc.add(new SedMLError(0, nodes.item(i).getChildNodes().item(1).getTextContent(), ERROR_SEVERITY.ERROR));
}
}
}
return rc;
}
Aggregations