Search in sources :

Example 1 with Mattext

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

the class CSVToQuestionConverter method createMattext.

private Mattext createMattext(String text) {
    // text is already in a CDATA
    text = text.replace("// <![CDATA[", "").replace("// ]]>", "");
    // Use explicit return which create a P tag if you want a line break.
    if (text.startsWith("<br />") && text.length() > 6)
        text = text.substring(6);
    if (text.endsWith("<br />") && text.length() > 6)
        text = text.substring(0, text.length() - 6);
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    text = conditionalCommentFilter.filter(text);
    Mattext mattext = new Mattext(text);
    return mattext;
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Filter(org.olat.core.util.filter.Filter)

Example 2 with Mattext

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

the class CSVToQuestionConverter method processQuestion.

private void processQuestion(String[] parts) {
    if (currentItem == null)
        return;
    Question question = currentItem.getItem().getQuestion();
    Material mat = question.getQuestion();
    String content = parts[1];
    Mattext matText = new Mattext(content);
    List<QTIObject> elements = new ArrayList<QTIObject>(1);
    elements.add(matText);
    mat.setElements(elements);
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) ArrayList(java.util.ArrayList) 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) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 3 with Mattext

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

the class QTIEditHelper method createKPRIMItem.

/**
 * Creates a new Kprim item
 * @param trans
 * @return New Kprim item.
 */
public static Item createKPRIMItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_KPRIM + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // controls
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    // prepare question
    float maxValue = 1;
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_KPRIM);
    question.setSingleCorrect(false);
    // Kprim has always 4 answers, each of them score 1/4 of the maximum value
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(false);
    newChoice.setPoints(maxValue / 4);
    question.getResponses().add(newChoice);
    ChoiceResponse newChoice2 = new ChoiceResponse();
    newChoice2.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice2.setCorrect(false);
    newChoice2.setPoints(maxValue / 4);
    question.getResponses().add(newChoice2);
    ChoiceResponse newChoice3 = new ChoiceResponse();
    newChoice3.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice3.setCorrect(false);
    newChoice3.setPoints(maxValue / 4);
    question.getResponses().add(newChoice3);
    ChoiceResponse newChoice4 = new ChoiceResponse();
    newChoice4.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice4.setCorrect(false);
    newChoice4.setPoints(maxValue / 4);
    question.getResponses().add(newChoice4);
    question.setMaxValue(maxValue);
    newItem.setQuestion(question);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    return newItem;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) ArrayList(java.util.ArrayList) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 4 with Mattext

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

the class QTIEditHelper method fetchChoices.

/**
 * Fetch choices.
 * @param response_labels
 * @return Map of choices.
 */
public static List<Response> fetchChoices(List response_labels) {
    List<Response> choices = new ArrayList<Response>();
    for (Iterator i = response_labels.iterator(); i.hasNext(); ) {
        ChoiceResponse choice = new ChoiceResponse();
        Element response_label = (Element) i.next();
        choice.setIdent(response_label.attributeValue("ident"));
        List materials = response_label.selectNodes(".//material");
        Material content = new Material();
        for (Iterator iter = materials.iterator(); iter.hasNext(); ) {
            Element el_material = (Element) iter.next();
            Material mat = (Material) parserManager.parse(el_material);
            content.getElements().addAll(mat.getElements());
        }
        // assure material always has some content
        if (content.getElements().size() == 0) {
            content.getElements().add(new Mattext(""));
        }
        choice.setContent(content);
        choices.add(choice);
    }
    return choices;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 5 with Mattext

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

the class QTIEditHelper method setFeedback.

/**
 * Set feedback
 * @param object
 * @param feedbackString
 * @param sIdent
 */
public static void setFeedback(QTIObject object, String feedbackString, String sIdent) {
    List<Feedback> feedbacks = getFeedbacks(object);
    Feedback feedback = getFeedback(sIdent, feedbacks);
    if (feedbackString == null || feedbackString.trim().length() == 0) {
        feedbacks.remove(feedback);
        return;
    }
    if (feedback != null) {
        feedbackString = feedbackString.trim();
        List matList = feedback.getMaterials();
        if (matList.size() > 0) {
            Material mat = (Material) feedback.getMaterials().get(0);
            if (mat == null) {
                mat = new Material();
                mat.getElements().add(new Mattext(feedbackString));
                feedback.getMaterials().add(mat);
            } else if (mat.getElements().size() > 0) {
                mat.getElements().set(0, new Mattext(feedbackString));
            } else {
                mat.getElements().add(new Mattext(feedbackString));
            }
        } else {
            Material mat = new Material();
            mat.getElements().add(new Mattext(feedbackString));
            feedback.getMaterials().add(mat);
        }
    } else {
        Feedback newFeedback = new Feedback();
        newFeedback.setIdent(sIdent);
        newFeedback.setView("All");
        Mattext newMattext = new Mattext(feedbackString);
        List<QTIObject> newMattextL = new ArrayList<>();
        newMattextL.add(newMattext);
        Material material = new Material();
        material.setElements(newMattextL);
        List<Material> newMaterialL = new ArrayList<>();
        newMaterialL.add(material);
        newFeedback.setMaterials(newMaterialL);
        feedbacks.add(newFeedback);
    }
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)26 ArrayList (java.util.ArrayList)18 Material (org.olat.ims.qti.editor.beecom.objects.Material)16 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)12 Item (org.olat.ims.qti.editor.beecom.objects.Item)12 VFSItem (org.olat.core.util.vfs.VFSItem)10 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)10 Control (org.olat.ims.qti.editor.beecom.objects.Control)10 List (java.util.List)8 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)8 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)8 Response (org.olat.ims.qti.editor.beecom.objects.Response)8 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)6 Filter (org.olat.core.util.filter.Filter)4 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)4 File (java.io.File)2 URL (java.net.URL)2 Iterator (java.util.Iterator)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2