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;
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations