Search in sources :

Example 1 with InterpretationFailureReason

use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason in project openolat by klemens.

the class BadRessourceHelper method extractMessage.

public static void extractMessage(BadResourceException e, StringBuilder out) {
    if (e instanceof QtiXmlInterpretationException) {
        QtiXmlInterpretationException qe = (QtiXmlInterpretationException) e;
        if (qe.getQtiModelBuildingErrors() != null) {
            for (QtiModelBuildingError error : qe.getQtiModelBuildingErrors()) {
                String localName = error.getElementLocalName();
                String msg = error.getException().getMessage();
                if (error.getElementLocation() != null) {
                    int lineNumber = error.getElementLocation().getLineNumber();
                    out.append(lineNumber + " :: " + localName + " :: " + msg + "\n");
                } else {
                    out.append(localName + " :: " + msg + "\n");
                }
            }
        }
        if (qe.getInterpretationFailureReason() != null) {
            InterpretationFailureReason reason = qe.getInterpretationFailureReason();
            out.append("Failure: " + reason + "\n");
        }
        if (qe.getXmlParseResult() != null) {
            XmlParseResult result = qe.getXmlParseResult();
            if (result.getWarnings() != null) {
                for (SAXParseException saxex : result.getWarnings()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Warnings: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
            if (result.getErrors() != null) {
                for (SAXParseException saxex : result.getErrors()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Error: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
            if (result.getFatalErrors() != null) {
                for (SAXParseException saxex : result.getFatalErrors()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Fatal: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
        }
    }
}
Also used : XmlParseResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlParseResult) SAXParseException(org.xml.sax.SAXParseException) InterpretationFailureReason(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) QtiModelBuildingError(uk.ac.ed.ph.jqtiplus.reading.QtiModelBuildingError)

Example 2 with InterpretationFailureReason

use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason in project OpenOLAT by OpenOLAT.

the class BadRessourceHelper method extractMessage.

public static void extractMessage(BadResourceException e, StringBuilder out) {
    if (e instanceof QtiXmlInterpretationException) {
        QtiXmlInterpretationException qe = (QtiXmlInterpretationException) e;
        if (qe.getQtiModelBuildingErrors() != null) {
            for (QtiModelBuildingError error : qe.getQtiModelBuildingErrors()) {
                String localName = error.getElementLocalName();
                String msg = error.getException().getMessage();
                if (error.getElementLocation() != null) {
                    int lineNumber = error.getElementLocation().getLineNumber();
                    out.append(lineNumber + " :: " + localName + " :: " + msg + "\n");
                } else {
                    out.append(localName + " :: " + msg + "\n");
                }
            }
        }
        if (qe.getInterpretationFailureReason() != null) {
            InterpretationFailureReason reason = qe.getInterpretationFailureReason();
            out.append("Failure: " + reason + "\n");
        }
        if (qe.getXmlParseResult() != null) {
            XmlParseResult result = qe.getXmlParseResult();
            if (result.getWarnings() != null) {
                for (SAXParseException saxex : result.getWarnings()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Warnings: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
            if (result.getErrors() != null) {
                for (SAXParseException saxex : result.getErrors()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Error: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
            if (result.getFatalErrors() != null) {
                for (SAXParseException saxex : result.getFatalErrors()) {
                    int lineNumber = saxex.getLineNumber();
                    int columnNumber = saxex.getColumnNumber();
                    String msg = saxex.getMessage();
                    out.append("Fatal: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
                }
            }
        }
    }
}
Also used : XmlParseResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlParseResult) SAXParseException(org.xml.sax.SAXParseException) InterpretationFailureReason(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) QtiModelBuildingError(uk.ac.ed.ph.jqtiplus.reading.QtiModelBuildingError)

Aggregations

SAXParseException (org.xml.sax.SAXParseException)2 QtiModelBuildingError (uk.ac.ed.ph.jqtiplus.reading.QtiModelBuildingError)2 QtiXmlInterpretationException (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException)2 InterpretationFailureReason (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason)2 XmlParseResult (uk.ac.ed.ph.jqtiplus.xmlutils.XmlParseResult)2