Search in sources :

Example 36 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project OpenOLAT by OpenOLAT.

the class AlienItemAnalyzer method checkItemBody.

/**
 * Check if there are text after the interaction
 */
private void checkItemBody(Report report) {
    if (report.getType() == QTI21QuestionType.sc || report.getType() == QTI21QuestionType.mc || report.getType() == QTI21QuestionType.kprim || report.getType() == QTI21QuestionType.match || report.getType() == QTI21QuestionType.matchdraganddrop || report.getType() == QTI21QuestionType.hotspot || report.getType() == QTI21QuestionType.essay || report.getType() == QTI21QuestionType.upload) {
        ItemBody itemBody = item.getItemBody();
        List<Block> blocks = itemBody.getBlocks();
        Block lastBlock = blocks.get(blocks.size() - 1);
        if (!(lastBlock instanceof Interaction)) {
            report.addWarning(ReportWarningEnum.textAfterInteraction);
        }
    }
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Example 37 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project openolat by klemens.

the class AssessmentHtmlBuilderTest method filter.

@Test
public void filter() throws IOException {
    String content = "<html><p>Test \u00EA<strong><span><img src='img.jpg'></span></strong></p><p>Test 2</p></html>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Block> paragraphs = helper.getBlocks();
    Assert.assertNotNull(paragraphs);
    Assert.assertEquals(2, paragraphs.size());
    // The serializer can throw some exceptions if it doens't like the model
    // we want to serialize.
    StringOutput sb = new StringOutput();
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
    String serializedQti = sb.toString();
    Assert.assertTrue(serializedQti.contains("img.jpg"));
    sb.close();
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StreamResult(javax.xml.transform.stream.StreamResult) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) StringOutput(org.olat.core.gui.render.StringOutput) Test(org.junit.Test)

Example 38 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project openolat by klemens.

the class AssessmentHtmlBuilderTest method serializeVideo.

@Test
public void serializeVideo() throws IOException {
    String content = "<p><span id=\"olatFlashMovieViewer213060\" class=\"olatFlashMovieViewer\" style=\"display:block;border:solid 1px #000; width:320px; height:240px;\">\n" + "<script src=\"/raw/fx-111111x11/movie/player.js\" type=\"text/javascript\"></script>\n" + "<script type=\"text/javascript\" defer=\"defer\">// <![CDATA[\n" + "BPlayer.insertPlayer(\"demo-video.mp4\",\"olatFlashMovieViewer213060\",320,240,0,0,\"video\",undefined,false,false,true,undefined);\n" + "// ]]></script>\n" + "</span></p>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Block> paragraphs = helper.getBlocks();
    Assert.assertNotNull(paragraphs);
    Assert.assertEquals(1, paragraphs.size());
    StringOutput sb = new StringOutput();
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
    String serializedQti = sb.toString();
    Assert.assertNotNull(serializedQti);
    Assert.assertTrue(serializedQti.contains("object"));
    Assert.assertFalse(serializedQti.contains("span"));
    Assert.assertFalse(serializedQti.contains("script"));
    sb.close();
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StreamResult(javax.xml.transform.stream.StreamResult) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) StringOutput(org.olat.core.gui.render.StringOutput) Test(org.junit.Test)

Example 39 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project openolat by klemens.

the class FIBAssessmentItemBuilder method buildItemBody.

@Override
protected void buildItemBody() {
    // remove current blocks
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    blocks.clear();
    // add question
    getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
    // transfer text entry to the interactions
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    List<String> usedResponseIdentifiers = new ArrayList<>(interactions.size());
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            TextEntryInteraction textEntryInteraction = (TextEntryInteraction) interaction;
            String responseIdentifier = interaction.getResponseIdentifier().toString();
            AbstractEntry entry = responseIdentifierToTextEntry.get(responseIdentifier);
            if (entry != null) {
                textEntryInteraction.setPlaceholderText(entry.getPlaceholder());
                textEntryInteraction.setExpectedLength(entry.getExpectedLength());
            }
            usedResponseIdentifiers.add(responseIdentifier);
        }
    }
    List<String> mappedResponseIdentifiers = new ArrayList<>(responseIdentifierToTextEntry.keySet());
    mappedResponseIdentifiers.removeAll(usedResponseIdentifiers);
    for (String mappedResponseIdentifier : mappedResponseIdentifiers) {
        responseIdentifierToTextEntry.remove(mappedResponseIdentifier);
    }
}
Also used : AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ArrayList(java.util.ArrayList) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Example 40 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project openolat by klemens.

the class FIBAssessmentItemBuilder method extractQuestions.

public String extractQuestions() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            serializeJqtiObject(block, sb);
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
    return question;
}
Also used : Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException)

Aggregations

Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)50 StringOutput (org.olat.core.gui.render.StringOutput)24 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)18 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)12 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)10 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)8 StreamResult (javax.xml.transform.stream.StreamResult)6 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 DrawingInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction)6 ExtendedTextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction)6 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)6 UploadInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction)6 Test (org.junit.Test)4 AssessmentItemFactory.appendExtendedTextInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendExtendedTextInteraction)4 AssessmentItemFactory.appendHotspotInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHotspotInteraction)4 Flow (uk.ac.ed.ph.jqtiplus.node.content.basic.Flow)4 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)4 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)4