Search in sources :

Example 21 with ItemBody

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

the class HottextAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String text, String hottext) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.hottext, title);
    // define correct answer
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("ht");
    List<Identifier> correctResponseIds = new ArrayList<>();
    correctResponseIds.add(correctResponseId);
    ResponseDeclaration responseDeclaration = createHottextCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseIds);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    HottextInteraction hottextInteraction = appendHottextInteraction(itemBody, responseDeclarationId, 0);
    P p = new P(itemBody);
    p.getInlines().add(new TextRun(p, text));
    appendHottext(p, correctResponseId, hottext);
    hottextInteraction.getBlockStatics().add(p);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

Example 22 with ItemBody

use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody 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 23 with ItemBody

use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody 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 24 with ItemBody

use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody 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 25 with ItemBody

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

the class AssessmentHtmlBuilderTest method filter_alt.

@Test
public void filter_alt() {
    String content = "<p>Test <textEntryInteraction responseIdentifier=\"RESPONSE_1\"/> </p>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Interaction> interactions = helper.findInteractions();
    Assert.assertNotNull(interactions);
    Assert.assertEquals(1, interactions.size());
    Interaction interaction = interactions.get(0);
    Assert.assertTrue(interaction instanceof TextEntryInteraction);
    Assert.assertNotNull(interaction.getResponseIdentifier());
    Assert.assertEquals("RESPONSE_1", interaction.getResponseIdentifier().toString());
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Test(org.junit.Test)

Aggregations

ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)32 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)28 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)22 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)22 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)16 NodeGroupList (uk.ac.ed.ph.jqtiplus.group.NodeGroupList)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)6 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)6 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)6 HashMap (java.util.HashMap)4 StreamResult (javax.xml.transform.stream.StreamResult)4 StringOutput (org.olat.core.gui.render.StringOutput)4 AssessmentItemFactory.appendChoiceInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)4 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)4 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)4