Search in sources :

Example 6 with SedMLError

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;
}
Also used : SedMLError(org.jlibsedml.SedMLError) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) NamedNodeMap(org.w3c.dom.NamedNodeMap) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SEDMLDocument(org.jlibsedml.SEDMLDocument) StringReader(java.io.StringReader) TransformerException(javax.xml.transform.TransformerException)

Aggregations

ArrayList (java.util.ArrayList)6 SedMLError (org.jlibsedml.SedMLError)6 SEDMLDocument (org.jlibsedml.SEDMLDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 IIdentifiable (org.jlibsedml.IIdentifiable)1 Model (org.jlibsedml.Model)1 Simulation (org.jlibsedml.Simulation)1 ASTCi (org.jmathml.ASTCi)1 ASTNode (org.jmathml.ASTNode)1 EvaluationContext (org.jmathml.EvaluationContext)1