Search in sources :

Example 1 with XsltStylesheetManager

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

the class AssessmentObjectComponentRenderer method transformMathmlAsString.

protected void transformMathmlAsString(StringOutput sb, String mathmlAsString) {
    if (!StringHelper.containsNonWhitespace(mathmlAsString)) {
        return;
    }
    XsltStylesheetManager stylesheetManager = CoreSpringFactory.getImpl(QTI21Service.class).getXsltStylesheetManager();
    final TransformerHandler mathmlTransformerHandler = stylesheetManager.getCompiledStylesheetHandler(ctopXsltUri, null);
    try {
        mathmlTransformerHandler.setResult(new StreamResult(sb));
        final XMLReader xmlReader = XmlUtilities.createNsAwareSaxReader();
        xmlReader.setContentHandler(mathmlTransformerHandler);
        Reader mathStream = new StringReader(mathmlAsString);
        InputSource assessmentSaxSource = new InputSource(mathStream);
        xmlReader.parse(assessmentSaxSource);
    } catch (final Exception e) {
        log.error("Rendering XSLT pipeline failed for request {}", e);
        sb.append("<span class='o_error'>ERROR MATHML</span>");
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) QTI21Service(org.olat.ims.qti21.QTI21Service) StreamResult(javax.xml.transform.stream.StreamResult) StringReader(java.io.StringReader) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) StringReader(java.io.StringReader) XsltStylesheetManager(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager) XMLReader(org.xml.sax.XMLReader) IOException(java.io.IOException)

Example 2 with XsltStylesheetManager

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

the class AssessmentObjectComponentRenderer method transformMathmlAsString.

protected void transformMathmlAsString(StringOutput sb, String mathmlAsString) {
    if (!StringHelper.containsNonWhitespace(mathmlAsString)) {
        return;
    }
    XsltStylesheetManager stylesheetManager = CoreSpringFactory.getImpl(QTI21Service.class).getXsltStylesheetManager();
    final TransformerHandler mathmlTransformerHandler = stylesheetManager.getCompiledStylesheetHandler(ctopXsltUri, null);
    try {
        mathmlTransformerHandler.setResult(new StreamResult(sb));
        final XMLReader xmlReader = XmlUtilities.createNsAwareSaxReader();
        xmlReader.setContentHandler(mathmlTransformerHandler);
        Reader mathStream = new StringReader(mathmlAsString);
        InputSource assessmentSaxSource = new InputSource(mathStream);
        xmlReader.parse(assessmentSaxSource);
    } catch (final Exception e) {
        log.error("Rendering XSLT pipeline failed for request {}", e);
        sb.append("<span class='o_error'>ERROR MATHML</span>");
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) QTI21Service(org.olat.ims.qti21.QTI21Service) StreamResult(javax.xml.transform.stream.StreamResult) StringReader(java.io.StringReader) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) StringReader(java.io.StringReader) XsltStylesheetManager(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager) XMLReader(org.xml.sax.XMLReader) IOException(java.io.IOException)

Example 3 with XsltStylesheetManager

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

the class QTI21ServiceImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    final List<JqtiExtensionPackage<?>> extensionPackages = new ArrayList<JqtiExtensionPackage<?>>();
    /* Enable MathAssess extensions if requested */
    if (qtiModule.isMathAssessExtensionEnabled()) {
        log.info("Enabling the MathAssess extensions");
        extensionPackages.add(new MathAssessExtensionPackage(xsltStylesheetCache));
        extensionPackages.add(new OpenOLATExtensionPackage(xsltStylesheetCache));
    }
    jqtiExtensionManager = new JqtiExtensionManager(extensionPackages);
    xsltStylesheetManager = new XsltStylesheetManager(new ClassPathResourceLocator(), xsltStylesheetCache);
    jqtiExtensionManager.init();
    Cacher cacher = coordinatorManager.getInstance().getCoordinator().getCacher();
    assessmentTestsCache = cacher.getCache("QTIWorks", "assessmentTests");
    assessmentItemsCache = cacher.getCache("QTIWorks", "assessmentItems");
}
Also used : JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) JqtiExtensionPackage(uk.ac.ed.ph.jqtiplus.JqtiExtensionPackage) ArrayList(java.util.ArrayList) MathAssessExtensionPackage(uk.ac.ed.ph.qtiworks.mathassess.MathAssessExtensionPackage) ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) Cacher(org.olat.core.util.coordinate.Cacher) XsltStylesheetManager(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager)

Example 4 with XsltStylesheetManager

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

the class QTI21ServiceImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    final List<JqtiExtensionPackage<?>> extensionPackages = new ArrayList<JqtiExtensionPackage<?>>();
    /* Enable MathAssess extensions if requested */
    if (qtiModule.isMathAssessExtensionEnabled()) {
        log.info("Enabling the MathAssess extensions");
        extensionPackages.add(new MathAssessExtensionPackage(xsltStylesheetCache));
        extensionPackages.add(new OpenOLATExtensionPackage(xsltStylesheetCache));
    }
    jqtiExtensionManager = new JqtiExtensionManager(extensionPackages);
    xsltStylesheetManager = new XsltStylesheetManager(new ClassPathResourceLocator(), xsltStylesheetCache);
    jqtiExtensionManager.init();
    Cacher cacher = coordinatorManager.getInstance().getCoordinator().getCacher();
    assessmentTestsCache = cacher.getCache("QTIWorks", "assessmentTests");
    assessmentItemsCache = cacher.getCache("QTIWorks", "assessmentItems");
}
Also used : JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) JqtiExtensionPackage(uk.ac.ed.ph.jqtiplus.JqtiExtensionPackage) ArrayList(java.util.ArrayList) MathAssessExtensionPackage(uk.ac.ed.ph.qtiworks.mathassess.MathAssessExtensionPackage) ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) Cacher(org.olat.core.util.coordinate.Cacher) XsltStylesheetManager(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager)

Aggregations

XsltStylesheetManager (uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager)4 IOException (java.io.IOException)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 TransformerHandler (javax.xml.transform.sax.TransformerHandler)2 StreamResult (javax.xml.transform.stream.StreamResult)2 Cacher (org.olat.core.util.coordinate.Cacher)2 QTI21Service (org.olat.ims.qti21.QTI21Service)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)2 JqtiExtensionPackage (uk.ac.ed.ph.jqtiplus.JqtiExtensionPackage)2 ClassPathResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator)2 MathAssessExtensionPackage (uk.ac.ed.ph.qtiworks.mathassess.MathAssessExtensionPackage)2