Search in sources :

Example 1 with DefaultMediaResource

use of org.olat.core.gui.media.DefaultMediaResource in project OpenOLAT by OpenOLAT.

the class QTIArchiver method exportQTI12.

public MediaResource exportQTI12() {
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    // fields separated by
    String sep = "\\t";
    // fields embedded by
    String emb = "\"";
    // carriage return
    String car = "\\r\\n";
    sep = convert2CtrlChars(sep);
    car = convert2CtrlChars(car);
    boolean tagLess = true;
    QTIExportFormatter formatter = getFormatter(sep, emb, car, tagLess);
    formatter.setMapWithExportItemConfigs(qtiItemConfigs);
    return new DefaultMediaResource() {

        @Override
        public String getContentType() {
            return "text/csv";
        }

        @Override
        public void prepare(HttpServletResponse hres) {
            try {
                hres.setCharacterEncoding("UTF-8");
            } catch (Exception e) {
                log.error("", e);
            }
            String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
            String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
            hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
            hres.setHeader("Content-Description", urlEncodedLabel);
            try (OutputStream out = hres.getOutputStream()) {
                List<QTIResult> qtiResults = qrm.selectResults(courseOres.getResourceableId(), courseNode.getIdent(), testRe.getKey(), null, 5);
                qem.exportResults(formatter, qtiResults, qtiItemObjectList, out);
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) DefaultMediaResource(org.olat.core.gui.media.DefaultMediaResource) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) Date(java.util.Date)

Example 2 with DefaultMediaResource

use of org.olat.core.gui.media.DefaultMediaResource in project openolat by klemens.

the class QTIArchiver method exportQTI12.

public MediaResource exportQTI12() {
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    // fields separated by
    String sep = "\\t";
    // fields embedded by
    String emb = "\"";
    // carriage return
    String car = "\\r\\n";
    sep = convert2CtrlChars(sep);
    car = convert2CtrlChars(car);
    boolean tagLess = true;
    QTIExportFormatter formatter = getFormatter(sep, emb, car, tagLess);
    formatter.setMapWithExportItemConfigs(qtiItemConfigs);
    return new DefaultMediaResource() {

        @Override
        public String getContentType() {
            return "text/csv";
        }

        @Override
        public void prepare(HttpServletResponse hres) {
            try {
                hres.setCharacterEncoding("UTF-8");
            } catch (Exception e) {
                log.error("", e);
            }
            String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
            String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
            hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
            hres.setHeader("Content-Description", urlEncodedLabel);
            try (OutputStream out = hres.getOutputStream()) {
                List<QTIResult> qtiResults = qrm.selectResults(courseOres.getResourceableId(), courseNode.getIdent(), testRe.getKey(), null, 5);
                qem.exportResults(formatter, qtiResults, qtiItemObjectList, out);
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) DefaultMediaResource(org.olat.core.gui.media.DefaultMediaResource) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 DefaultMediaResource (org.olat.core.gui.media.DefaultMediaResource)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 QTIResult (org.olat.ims.qti.QTIResult)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2