Search in sources :

Example 1 with AssessmentHtmlBuilder

use of org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder in project openolat by klemens.

the class HottextAssessmentItemBuilder method getAnswers.

@Override
public List<Answer> getAnswers() {
    List<Hottext> hottexts = getChoices();
    List<Answer> answers = new ArrayList<>(hottexts.size());
    for (Hottext hottext : hottexts) {
        String answer = new AssessmentHtmlBuilder().inlineStaticString(hottext.getInlineStatics());
        answer = FilterFactory.getHtmlTagAndDescapingFilter().filter(answer);
        answers.add(new Answer(hottext.getIdentifier(), answer));
    }
    return answers;
}
Also used : ArrayList(java.util.ArrayList) AssessmentItemFactory.appendHottext(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottext) Hottext(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Hottext) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder)

Example 2 with AssessmentHtmlBuilder

use of org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder in project openolat by klemens.

the class QTI12And21PoolWordExport method exportItems.

private void exportItems(List<QuestionItemFull> fullItems, OutputStream out, boolean withResponses) {
    ZipOutputStream zout = null;
    try {
        OpenXMLDocument document = new OpenXMLDocument();
        document.setDocumentHeader("");
        Translator qti12Translator = Util.createPackageTranslator(QTIWordExport.class, locale);
        Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale, qti12Translator));
        AssessmentHtmlBuilder htmlBuilder = new AssessmentHtmlBuilder();
        for (Iterator<QuestionItemFull> itemIt = fullItems.iterator(); itemIt.hasNext(); ) {
            QuestionItemFull fullItem = itemIt.next();
            if (QTIConstants.QTI_12_FORMAT.equals(fullItem.getFormat())) {
                String dir = fullItem.getDirectory();
                VFSContainer container = qpoolFileStorage.getContainer(dir);
                document.setMediaContainer(container);
                VFSItem rootItem = container.resolve(fullItem.getRootFilename());
                Item item = QTIEditHelper.readItemXml((VFSLeaf) rootItem);
                if (item.isAlient()) {
                    QTIWordExport.renderAlienItem(item, document, translator);
                } else {
                    QTIWordExport.renderItem(item, document, withResponses, translator);
                }
            } else {
                File resourceDirectory = qpoolService.getRootDirectory(fullItem);
                VFSContainer resourceContainer = qpoolService.getRootContainer(fullItem);
                document.setMediaContainer(resourceContainer);
                File resourceFile = qpoolService.getRootFile(fullItem);
                URI assessmentItemUri = resourceFile.toURI();
                ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
                AssessmentItem item = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
                QTI21WordExport.renderAssessmentItem(item, resourceFile, resourceDirectory, document, withResponses, translator, htmlBuilder);
            }
            if (itemIt.hasNext()) {
                document.appendPageBreak();
            }
        }
        zout = new ZipOutputStream(out);
        zout.setLevel(9);
        OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
        writer.createDocument(zout, document);
    } catch (Exception e) {
        log.error("", e);
    } finally {
        if (zout != null) {
            try {
                zout.finish();
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenXMLDocument(org.olat.core.util.openxml.OpenXMLDocument) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder) VFSItem(org.olat.core.util.vfs.VFSItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) OpenXMLDocumentWriter(org.olat.core.util.openxml.OpenXMLDocumentWriter) Translator(org.olat.core.gui.translator.Translator) ZipOutputStream(java.util.zip.ZipOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentTestComposerController(org.olat.ims.qti21.ui.editor.AssessmentTestComposerController) File(java.io.File)

Example 3 with AssessmentHtmlBuilder

use of org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder in project OpenOLAT by OpenOLAT.

the class HottextAssessmentItemBuilder method getAnswers.

@Override
public List<Answer> getAnswers() {
    List<Hottext> hottexts = getChoices();
    List<Answer> answers = new ArrayList<>(hottexts.size());
    for (Hottext hottext : hottexts) {
        String answer = new AssessmentHtmlBuilder().inlineStaticString(hottext.getInlineStatics());
        answer = FilterFactory.getHtmlTagAndDescapingFilter().filter(answer);
        answers.add(new Answer(hottext.getIdentifier(), answer));
    }
    return answers;
}
Also used : ArrayList(java.util.ArrayList) AssessmentItemFactory.appendHottext(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottext) Hottext(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Hottext) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder)

Example 4 with AssessmentHtmlBuilder

use of org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder in project OpenOLAT by OpenOLAT.

the class QTI12And21PoolWordExport method exportItems.

private void exportItems(List<QuestionItemFull> fullItems, OutputStream out, boolean withResponses) {
    ZipOutputStream zout = null;
    try {
        OpenXMLDocument document = new OpenXMLDocument();
        document.setDocumentHeader("");
        Translator qti12Translator = Util.createPackageTranslator(QTIWordExport.class, locale);
        Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale, qti12Translator));
        AssessmentHtmlBuilder htmlBuilder = new AssessmentHtmlBuilder();
        for (Iterator<QuestionItemFull> itemIt = fullItems.iterator(); itemIt.hasNext(); ) {
            QuestionItemFull fullItem = itemIt.next();
            if (QTIConstants.QTI_12_FORMAT.equals(fullItem.getFormat())) {
                String dir = fullItem.getDirectory();
                VFSContainer container = qpoolFileStorage.getContainer(dir);
                document.setMediaContainer(container);
                VFSItem rootItem = container.resolve(fullItem.getRootFilename());
                Item item = QTIEditHelper.readItemXml((VFSLeaf) rootItem);
                if (item.isAlient()) {
                    QTIWordExport.renderAlienItem(item, document, translator);
                } else {
                    QTIWordExport.renderItem(item, document, withResponses, translator);
                }
            } else {
                File resourceDirectory = qpoolService.getRootDirectory(fullItem);
                VFSContainer resourceContainer = qpoolService.getRootContainer(fullItem);
                document.setMediaContainer(resourceContainer);
                File resourceFile = qpoolService.getRootFile(fullItem);
                URI assessmentItemUri = resourceFile.toURI();
                ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
                AssessmentItem item = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
                QTI21WordExport.renderAssessmentItem(item, resourceFile, resourceDirectory, document, withResponses, translator, htmlBuilder);
            }
            if (itemIt.hasNext()) {
                document.appendPageBreak();
            }
        }
        zout = new ZipOutputStream(out);
        zout.setLevel(9);
        OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
        writer.createDocument(zout, document);
    } catch (Exception e) {
        log.error("", e);
    } finally {
        if (zout != null) {
            try {
                zout.finish();
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenXMLDocument(org.olat.core.util.openxml.OpenXMLDocument) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder) VFSItem(org.olat.core.util.vfs.VFSItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) OpenXMLDocumentWriter(org.olat.core.util.openxml.OpenXMLDocumentWriter) Translator(org.olat.core.gui.translator.Translator) ZipOutputStream(java.util.zip.ZipOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentTestComposerController(org.olat.ims.qti21.ui.editor.AssessmentTestComposerController) File(java.io.File)

Example 5 with AssessmentHtmlBuilder

use of org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder in project OpenOLAT by OpenOLAT.

the class QTI21WordExport method renderAssessmentItem.

public static void renderAssessmentItem(AssessmentItem item, File itemFile, File mediaDir, OpenXMLDocument document, boolean withResponses, Translator translator, AssessmentHtmlBuilder htmlBuilder) {
    StringBuilder addText = new StringBuilder();
    QTI21QuestionType type = QTI21QuestionType.getType(item);
    String typeDescription = "";
    switch(type) {
        case sc:
            typeDescription = translator.translate("form.choice");
            break;
        case mc:
            typeDescription = translator.translate("form.choice");
            break;
        case fib:
            typeDescription = translator.translate("form.fib");
            break;
        case numerical:
            typeDescription = translator.translate("form.fib");
            break;
        case kprim:
            typeDescription = translator.translate("form.kprim");
            break;
        case hotspot:
            typeDescription = translator.translate("form.hotspot");
            break;
        case essay:
            typeDescription = translator.translate("form.essay");
            break;
        case upload:
            typeDescription = translator.translate("form.upload");
            break;
        case drawing:
            typeDescription = translator.translate("form.drawing");
            break;
        case match:
            typeDescription = translator.translate("form.match");
            break;
        default:
            typeDescription = null;
            break;
    }
    Double maxScore = QtiNodesExtractor.extractMaxScore(item);
    if (StringHelper.containsNonWhitespace(typeDescription) || maxScore != null) {
        if (StringHelper.containsNonWhitespace(typeDescription)) {
            addText.append("(").append(typeDescription).append(")");
        }
        if (maxScore != null) {
            addText.append(" - ").append(AssessmentHelper.getRoundedScore(maxScore));
        }
    }
    String title = item.getTitle();
    document.appendHeading1(title, addText.toString());
    List<Block> itemBodyBlocks = item.getItemBody().getBlocks();
    String html = htmlBuilder.blocksString(itemBodyBlocks);
    document.appendHtmlText(html, true, new QTI21AndHTMLToOpenXMLHandler(document, item, itemFile, mediaDir, withResponses, htmlBuilder, translator));
    if (withResponses && (type == QTI21QuestionType.essay || type == QTI21QuestionType.upload || type == QTI21QuestionType.drawing)) {
        renderCorrectSolutionForWord(item, document, translator, htmlBuilder);
    }
}
Also used : QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Aggregations

AssessmentHtmlBuilder (org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder)4 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 Translator (org.olat.core.gui.translator.Translator)2 OpenXMLDocument (org.olat.core.util.openxml.OpenXMLDocument)2 OpenXMLDocumentWriter (org.olat.core.util.openxml.OpenXMLDocumentWriter)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 QTI21QuestionType (org.olat.ims.qti21.model.QTI21QuestionType)2 AssessmentItemFactory.appendHottext (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottext)2 AssessmentTestComposerController (org.olat.ims.qti21.ui.editor.AssessmentTestComposerController)2 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)2 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)2 RubricBlock (uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2 Hottext (uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Hottext)2