Search in sources :

Example 1 with AsciiMathHelper

use of uk.ac.ed.ph.qtiworks.mathassess.glue.AsciiMathHelper in project OpenOLAT by OpenOLAT.

the class MathWebDispatcher method execute.

@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
    UserRequest ureq = null;
    try {
        // upon creation URL is checked for
        ureq = new UserRequestImpl("math", request, response);
    } catch (NumberFormatException nfe) {
        DispatcherModule.sendBadRequest(request.getPathInfo(), response);
        return;
    }
    String asciiMathInput = ureq.getParameter("input");
    Map<String, String> upConvertedAsciiMathInput;
    if (StringHelper.containsNonWhitespace(asciiMathInput)) {
        XsltStylesheetCache stylesheetCache = CoreSpringFactory.getImpl(QTI21Service.class).getXsltStylesheetCache();
        AsciiMathHelper asciiMathHelper = new AsciiMathHelper(new XsltStylesheetCacheAdapter(stylesheetCache));
        upConvertedAsciiMathInput = asciiMathHelper.upConvertAsciiMathInput(asciiMathInput);
    } else {
        upConvertedAsciiMathInput = Collections.emptyMap();
    }
    try {
        JSONObject object = new JSONObject();
        for (Map.Entry<String, String> entry : upConvertedAsciiMathInput.entrySet()) {
            object.append(entry.getKey(), entry.getValue());
        }
        object.write(response.getWriter());
    } catch (JSONException | IOException e) {
        log.error("", e);
    }
}
Also used : AsciiMathHelper(uk.ac.ed.ph.qtiworks.mathassess.glue.AsciiMathHelper) XsltStylesheetCacheAdapter(uk.ac.ed.ph.qtiworks.mathassess.XsltStylesheetCacheAdapter) JSONException(org.json.JSONException) IOException(java.io.IOException) XsltStylesheetCache(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetCache) QTI21Service(org.olat.ims.qti21.QTI21Service) JSONObject(org.json.JSONObject) Map(java.util.Map) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Example 2 with AsciiMathHelper

use of uk.ac.ed.ph.qtiworks.mathassess.glue.AsciiMathHelper in project openolat by klemens.

the class MathWebDispatcher method execute.

@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
    UserRequest ureq = null;
    try {
        // upon creation URL is checked for
        ureq = new UserRequestImpl("math", request, response);
    } catch (NumberFormatException nfe) {
        DispatcherModule.sendBadRequest(request.getPathInfo(), response);
        return;
    }
    String asciiMathInput = ureq.getParameter("input");
    Map<String, String> upConvertedAsciiMathInput;
    if (StringHelper.containsNonWhitespace(asciiMathInput)) {
        XsltStylesheetCache stylesheetCache = CoreSpringFactory.getImpl(QTI21Service.class).getXsltStylesheetCache();
        AsciiMathHelper asciiMathHelper = new AsciiMathHelper(new XsltStylesheetCacheAdapter(stylesheetCache));
        upConvertedAsciiMathInput = asciiMathHelper.upConvertAsciiMathInput(asciiMathInput);
    } else {
        upConvertedAsciiMathInput = Collections.emptyMap();
    }
    try {
        JSONObject object = new JSONObject();
        for (Map.Entry<String, String> entry : upConvertedAsciiMathInput.entrySet()) {
            object.append(entry.getKey(), entry.getValue());
        }
        object.write(response.getWriter());
    } catch (JSONException | IOException e) {
        log.error("", e);
    }
}
Also used : AsciiMathHelper(uk.ac.ed.ph.qtiworks.mathassess.glue.AsciiMathHelper) XsltStylesheetCacheAdapter(uk.ac.ed.ph.qtiworks.mathassess.XsltStylesheetCacheAdapter) JSONException(org.json.JSONException) IOException(java.io.IOException) XsltStylesheetCache(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetCache) QTI21Service(org.olat.ims.qti21.QTI21Service) JSONObject(org.json.JSONObject) Map(java.util.Map) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Aggregations

IOException (java.io.IOException)2 Map (java.util.Map)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 UserRequest (org.olat.core.gui.UserRequest)2 UserRequestImpl (org.olat.core.gui.UserRequestImpl)2 QTI21Service (org.olat.ims.qti21.QTI21Service)2 XsltStylesheetCache (uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetCache)2 XsltStylesheetCacheAdapter (uk.ac.ed.ph.qtiworks.mathassess.XsltStylesheetCacheAdapter)2 AsciiMathHelper (uk.ac.ed.ph.qtiworks.mathassess.glue.AsciiMathHelper)2