Search in sources :

Example 1 with Block

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

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 2 with Block

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

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 3 with Block

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

the class InteractionResultComponentRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    InteractionResultComponent cmp = (InteractionResultComponent) source;
    Interaction interaction = cmp.getInteraction();
    ResolvedAssessmentItem resolvedAssessmentItem = cmp.getResolvedAssessmentItem();
    ItemSessionState itemSessionState = cmp.getItemSessionState();
    AssessmentRenderer assessmentRenderer = new AssessmentRenderer(renderer);
    if (cmp.isShowSolution()) {
        assessmentRenderer.setSolutionAllowed(true);
        assessmentRenderer.setSolutionMode(true);
    } else {
        assessmentRenderer.setReviewMode(true);
    }
    if (interaction instanceof Block) {
        renderBlock(assessmentRenderer, sb, cmp, resolvedAssessmentItem, itemSessionState, (Block) interaction, ubu, translator);
    } else if (interaction instanceof Flow) {
        renderFlow(assessmentRenderer, sb, cmp, resolvedAssessmentItem, itemSessionState, (Flow) interaction, ubu, translator);
    }
}
Also used : Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) Flow(uk.ac.ed.ph.jqtiplus.node.content.basic.Flow)

Example 4 with Block

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

the class HotspotAssessmentItemBuilder method extractHotspotInteraction.

private void extractHotspotInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof HotspotInteraction) {
                hotspotInteraction = (HotspotInteraction) block;
                responseIdentifier = hotspotInteraction.getResponseIdentifier();
                break;
            } else {
                serializeJqtiObject(block, sb);
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) AssessmentItemFactory.appendHotspotInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHotspotInteraction) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException)

Example 5 with Block

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

the class MatchAssessmentItemBuilder method extractMatchInteraction.

private void extractMatchInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof MatchInteraction) {
                matchInteraction = (MatchInteraction) block;
                responseIdentifier = matchInteraction.getResponseIdentifier();
                shuffle = matchInteraction.getShuffle();
                break;
            } else {
                serializeJqtiObject(block, sb);
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : AssessmentItemFactory.appendMatchInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) 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