Search in sources :

Example 6 with XsltSerializationOptions

use of uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions in project openolat by klemens.

the class QTI21ServiceImpl method storeStateDocument.

private void storeStateDocument(Document stateXml, File sessionFile) {
    XsltSerializationOptions xsltSerializationOptions = new XsltSerializationOptions();
    xsltSerializationOptions.setIndenting(true);
    xsltSerializationOptions.setIncludingXMLDeclaration(false);
    Transformer serializer = XsltStylesheetManager.createSerializer(xsltSerializationOptions);
    try (OutputStream resultStream = new FileOutputStream(sessionFile)) {
        serializer.transform(new DOMSource(stateXml), new StreamResult(resultStream));
    } catch (TransformerException | IOException e) {
        throw new OLATRuntimeException("Unexpected Exception serializing state DOM", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) XsltSerializationOptions(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 7 with XsltSerializationOptions

use of uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions in project OpenOLAT by OpenOLAT.

the class QTI21ServiceImpl method storeStateDocument.

private void storeStateDocument(Document stateXml, File sessionFile) {
    XsltSerializationOptions xsltSerializationOptions = new XsltSerializationOptions();
    xsltSerializationOptions.setIndenting(true);
    xsltSerializationOptions.setIncludingXMLDeclaration(false);
    Transformer serializer = XsltStylesheetManager.createSerializer(xsltSerializationOptions);
    try (OutputStream resultStream = new FileOutputStream(sessionFile)) {
        serializer.transform(new DOMSource(stateXml), new StreamResult(resultStream));
    } catch (TransformerException | IOException e) {
        throw new OLATRuntimeException("Unexpected Exception serializing state DOM", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) XsltSerializationOptions(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 8 with XsltSerializationOptions

use of uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions in project openolat by klemens.

the class QTI21ServiceImpl method persistAssessmentObject.

@Override
public boolean persistAssessmentObject(File resourceFile, AssessmentObject assessmentObject) {
    try (FileOutputStream out = new FileOutputStream(resourceFile)) {
        final XsltSerializationOptions xsltSerializationOptions = new XsltSerializationOptions();
        xsltSerializationOptions.setIndenting(false);
        qtiSerializer().serializeJqtiObject(assessmentObject, new StreamResult(out), new SaxFiringOptions(), xsltSerializationOptions);
        assessmentTestsCache.remove(resourceFile);
        assessmentItemsCache.remove(resourceFile);
        return true;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) FileOutputStream(java.io.FileOutputStream) XsltSerializationOptions(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions) SaxFiringOptions(uk.ac.ed.ph.jqtiplus.serialization.SaxFiringOptions) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Aggregations

StreamResult (javax.xml.transform.stream.StreamResult)8 XsltSerializationOptions (uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions)8 SaxFiringOptions (uk.ac.ed.ph.jqtiplus.serialization.SaxFiringOptions)6 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 TransformerException (javax.xml.transform.TransformerException)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 OutputStream (java.io.OutputStream)2 Transformer (javax.xml.transform.Transformer)2 DOMSource (javax.xml.transform.dom.DOMSource)2 QtiXmlInterpretationException (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException)2 XmlResourceNotFoundException (uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException)2