Search in sources :

Example 21 with QTIObject

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

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 22 with QTIObject

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

the class ItemParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("item");
    Item item = new Item();
    Attribute tmp = element.attribute("ident");
    if (tmp != null)
        item.setIdent(tmp.getValue());
    else
        item.setIdent("" + CodeHelper.getRAMUniqueID());
    tmp = element.attribute("title");
    if (tmp != null)
        item.setTitle(tmp.getValue());
    tmp = element.attribute("label");
    if (tmp != null)
        item.setLabel(tmp.getValue());
    tmp = element.attribute("maxattempts");
    if (tmp != null) {
        try {
            item.setMaxattempts(Integer.parseInt(tmp.getValue()));
        } catch (NumberFormatException nfe) {
            item.setMaxattempts(0);
        }
    }
    // if editor can't handle type of item, just keep raw XML
    if (!(item.getIdent().startsWith(ITEM_PREFIX_SCQ) || item.getIdent().startsWith(ITEM_PREFIX_MCQ) || item.getIdent().startsWith(ITEM_PREFIX_FIB) || item.getIdent().startsWith(ITEM_PREFIX_ESSAY) || item.getIdent().startsWith(ITEM_PREFIX_KPRIM))) {
        item.setRawXML(new QTIXMLWrapper(element));
        return item;
    }
    // for render_fib that contains rows attribute and convert them to essay
    if (item.getIdent().startsWith(ITEM_PREFIX_FIB) && element.selectNodes(".//render_fib[@rows]").size() > 0) {
        item.setIdent(item.getIdent().replaceFirst("FIB", "ESSAY"));
    }
    // DURATION
    Duration duration = (Duration) parserManager.parse(element.element("duration"));
    item.setDuration(duration);
    // CONTROLS
    List itemcontrolsXML = element.elements("itemcontrol");
    List itemcontrols = new ArrayList();
    for (Iterator i = itemcontrolsXML.iterator(); i.hasNext(); ) {
        itemcontrols.add(parserManager.parse((Element) i.next()));
    }
    if (itemcontrols.size() == 0) {
        itemcontrols.add(new Control());
    }
    item.setItemcontrols(itemcontrols);
    // OBJECTIVES
    Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null)
        item.setObjectives(mattext.getTextTrim());
    // QUESTIONS
    if (item.getIdent().startsWith(ITEM_PREFIX_SCQ))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_MCQ))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_FIB))
        item.setQuestion(FIBQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_ESSAY))
        item.setQuestion(EssayQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_KPRIM))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    // FEEDBACKS
    List feedbacksXML = element.elements("itemfeedback");
    List feedbacks = new ArrayList();
    item.setItemfeedbacks(feedbacks);
    Question question = item.getQuestion();
    for (Iterator i = feedbacksXML.iterator(); i.hasNext(); ) {
        Element el_feedback = (Element) i.next();
        if (el_feedback.element("solution") != null) {
            // fetch solution
            Element el_solution = el_feedback.element("solution");
            question.setSolutionText(getMaterialAsString(el_solution));
        } else if (el_feedback.element("hint") != null) {
            // fetch hint
            Element el_hint = el_feedback.element("hint");
            question.setHintText(getMaterialAsString(el_hint));
        } else {
            QTIObject tmpObj = (QTIObject) parserManager.parse(el_feedback);
            if (tmpObj != null)
                feedbacks.add(tmpObj);
        }
    }
    return item;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) Control(org.olat.ims.qti.editor.beecom.objects.Control) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) QTIXMLWrapper(org.olat.ims.qti.editor.beecom.objects.QTIXMLWrapper) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Duration(org.olat.ims.qti.editor.beecom.objects.Duration) ArrayList(java.util.ArrayList) List(java.util.List) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

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