Search in sources :

Example 11 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class QTIDocumentParser method parse.

public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("questestinterop");
    QTIDocument qtiDocument = new QTIDocument();
    Object tmp = null;
    Element qticomment = element.element("qticomment");
    qtiDocument.setQticomment((QTIObject) parserManager.parse(qticomment));
    Element objectbank = element.element("objectbank");
    tmp = parserManager.parse(objectbank);
    if (tmp != null) {
        qtiDocument.setObjectbank((QTIObject) tmp);
    }
    Element assesment = element.element("assessment");
    tmp = parserManager.parse(assesment);
    if (tmp != null) {
        qtiDocument.setAssessment((Assessment) tmp);
    }
    return qtiDocument;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) Element(org.dom4j.Element) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject)

Example 12 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.

the class CSVToQuestionConverterTest method importMultipleChoice.

@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
    URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
    Assert.assertNotNull(importTxtUrl);
    File importTxt = new File(importTxtUrl.toURI());
    String input = FileUtils.readFileToString(importTxt, "UTF-8");
    Translator translator = new KeyTranslator(Locale.ENGLISH);
    ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
    converter.parse(input);
    List<ItemAndMetadata> items = converter.getItems();
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    ItemAndMetadata importedItem = items.get(0);
    Item item = importedItem.getItem();
    Assert.assertNotNull(item);
    Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
    Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
    Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
    Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
    Material questionMat = item.getQuestion().getQuestion();
    Assert.assertNotNull(questionMat);
    Assert.assertNotNull(questionMat.getElements());
    Assert.assertEquals(1, questionMat.getElements().size());
    QTIObject questionMatEl = questionMat.getElements().get(0);
    Assert.assertTrue(questionMatEl instanceof Mattext);
    String text = ((Mattext) questionMatEl).getContent();
    Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
    ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
    Assert.assertNotNull(question.getResponses());
    Assert.assertEquals(7, question.getResponses().size());
    List<Response> responses = question.getResponses();
    Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
    // after it will be set to true for all of them
    Assert.assertTrue(responses.get(0).isCorrect());
    Assert.assertTrue(responses.get(1).isCorrect());
    Assert.assertTrue(responses.get(2).isCorrect());
    Assert.assertFalse(responses.get(3).isCorrect());
    Assert.assertFalse(responses.get(4).isCorrect());
    Assert.assertFalse(responses.get(5).isCorrect());
    Assert.assertFalse(responses.get(6).isCorrect());
    String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
    Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
    String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
    Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
Also used : Material(org.olat.ims.qti.editor.beecom.objects.Material) URL(java.net.URL) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) Item(org.olat.ims.qti.editor.beecom.objects.Item) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Translator(org.olat.core.gui.translator.Translator) KeyTranslator(org.olat.test.KeyTranslator) KeyTranslator(org.olat.test.KeyTranslator) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) File(java.io.File) Test(org.junit.Test)

Example 13 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.

the class MaterialFormController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(UserRequest ureq) {
    // trust authors, don't to XSS filtering
    String newHtml = richText.getRawValue();
    // the text fragment is saved in a cdata, remove cdata from movie plugin
    newHtml = newHtml.replace("// <![CDATA[", "").replace("// ]]>", "");
    // Use explicit return which create a P tag if you want a line break.
    if (newHtml.startsWith("<br />") && newHtml.length() > 6)
        newHtml = newHtml.substring(6);
    if (newHtml.endsWith("<br />") && newHtml.length() > 6)
        newHtml = newHtml.substring(0, newHtml.length() - 6);
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    newHtml = conditionalCommentFilter.filter(newHtml);
    // 
    if (htmlContent.equals(newHtml)) {
        // No changes. Cancel editing.
        fireEvent(ureq, Event.CANCELLED_EVENT);
    } else {
        if (isRestrictedEditMode) {
            // In restricted edit mode, if the content has changed, write a memento
            // (by firing the before change event).
            QTIObjectBeforeChangeEvent qobce = new QTIObjectBeforeChangeEvent();
            qobce.init(mat.getId(), htmlContent);
            fireEvent(ureq, qobce);
        }
        // Collect the content of all MatElements in a single text element
        // (text/html) and save it (for Material objects with multiple elements
        // such as images, videos, text, breaks, etc. this can be regarded as
        // "lazy migration" to the new rich text style).
        Mattext textHtml = new Mattext(newHtml);
        // A single text/html element will be left over.
        List<QTIObject> elements = new ArrayList<QTIObject>(1);
        elements.add(textHtml);
        mat.setElements(elements);
        fireEvent(ureq, Event.DONE_EVENT);
    }
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Filter(org.olat.core.util.filter.Filter) ArrayList(java.util.ArrayList)

Example 14 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.

the class AssessmentParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("assessment");
    Assessment assessment = new Assessment();
    // attributes
    Attribute attr = element.attribute("ident");
    if (attr != null)
        assessment.setIdent(attr.getValue());
    attr = element.attribute("title");
    if (attr != null)
        assessment.setTitle(attr.getValue());
    // elements
    // DURATION
    QTIObject duration = (QTIObject) parserManager.parse(element.element("duration"));
    assessment.setDuration(duration);
    // ASSESSMENTCONTROL
    List assessmentcontrolsXML = element.elements("assessmentcontrol");
    List assessmentcontrols = new ArrayList();
    for (Iterator i = assessmentcontrolsXML.iterator(); i.hasNext(); ) {
        assessmentcontrols.add(parserManager.parse((Element) i.next()));
        assessment.setInheritControls(true);
    }
    if (assessmentcontrols.size() == 0) {
        assessmentcontrols.add(new Control());
        assessment.setInheritControls(false);
    }
    assessment.setAssessmentcontrols(assessmentcontrols);
    // OUTCOMES PROCESSING
    OutcomesProcessing outcomesProcessing = (OutcomesProcessing) parserManager.parse(element.element("outcomes_processing"));
    if (outcomesProcessing != null)
        assessment.setOutcomes_processing(outcomesProcessing);
    // SELECTION ORDERING
    SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
    if (selectionOrdering != null) {
        assessment.setSelection_ordering(selectionOrdering);
    } else {
        assessment.setSelection_ordering(new SelectionOrdering());
    }
    // SECTIONS
    List sectionsXML = element.elements("section");
    List sections = new ArrayList();
    for (Iterator i = sectionsXML.iterator(); i.hasNext(); ) {
        sections.add(parserManager.parse((Element) i.next()));
    }
    assessment.setSections(sections);
    // ITEMS
    List itemsXML = element.elements("item");
    List items = new ArrayList();
    for (Iterator i = itemsXML.iterator(); i.hasNext(); ) {
        items.add(parserManager.parse((Element) i.next()));
    }
    assessment.setItems(items);
    // OBJECTIVES
    Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null)
        assessment.setObjectives(mattext.getTextTrim());
    // METADATA
    Metadata metadata = (Metadata) parserManager.parse(element.element("qtimetadata"));
    if (metadata != null)
        assessment.setMetadata(metadata);
    return assessment;
}
Also used : Control(org.olat.ims.qti.editor.beecom.objects.Control) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) SelectionOrdering(org.olat.ims.qti.editor.beecom.objects.SelectionOrdering) Attribute(org.dom4j.Attribute) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) Metadata(org.olat.ims.qti.editor.beecom.objects.Metadata) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.

the class MaterialParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("material");
    List materials = element.elements();
    if (materials.size() == 0)
        return null;
    Material material = new Material();
    // ATTRIBUTES
    Attribute label = element.attribute("label");
    if (label != null)
        material.setLable(label.getValue());
    // ELEMENTS
    for (Iterator i = materials.iterator(); i.hasNext(); ) {
        QTIObject obj = (QTIObject) parserManager.parse((Element) i.next());
        if (obj != null)
            material.getElements().add(obj);
    }
    return material;
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)22 ArrayList (java.util.ArrayList)12 List (java.util.List)10 Element (org.dom4j.Element)10 Iterator (java.util.Iterator)8 Material (org.olat.ims.qti.editor.beecom.objects.Material)8 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)8 Attribute (org.dom4j.Attribute)6 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)4 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)4 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)4 Question (org.olat.ims.qti.editor.beecom.objects.Question)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 SelectionOrdering (org.olat.ims.qti.editor.beecom.objects.SelectionOrdering)4 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)4 File (java.io.File)2 URL (java.net.URL)2