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