use of org.olat.ims.qti.editor.beecom.objects.QTIObject 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.QTIObject in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.
the class QTIEditorMainController method doMove.
private void doMove(TreePosition tp) {
// user chose a position to insert a new node
GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
int targetPos = tp.getChildpos();
GenericQtiNode selectedNode = (GenericQtiNode) menuTree.getSelectedNode();
int selectedPos = selectedNode.getPosition();
GenericQtiNode parentSelectedNode = (GenericQtiNode) selectedNode.getParent();
if (parentTargetNode == parentSelectedNode) {
// if we're on the same subnode
if (targetPos > selectedNode.getPosition()) {
// if we're moving after our current position
targetPos--;
// decrease insert pos since we're going to be removed from the
// parent before re-insert
}
}
// insert into menutree (insert on GenericNode do a remove from parent)
parentTargetNode.insert(selectedNode, targetPos);
// insert into model (remove from parent needed prior to insert)
QTIObject subject = parentSelectedNode.removeQTIObjectAt(selectedPos);
parentTargetNode.insertQTIObjectAt(subject, targetPos);
qtiPackage.serializeQTIDocument();
parentSelectedNode.childNodeChanges();
parentTargetNode.childNodeChanges();
}
use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project OpenOLAT by OpenOLAT.
the class QTIEditorMainController method doExportQItem.
private void doExportQItem() {
GenericQtiNode selectedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());
if (selectedNode instanceof ItemNode) {
ItemNode itemNode = (ItemNode) selectedNode;
QTIObject qtiObject = itemNode.getUnderlyingQTIObject();
if (qtiObject instanceof Item) {
ItemAndMetadata item = new ItemAndMetadata((Item) qtiObject);
VFSContainer editorContainer = qtiPackage.getBaseDir();
qtiQpoolServiceProvider.importBeecomItem(getIdentity(), item, editorContainer, getLocale());
showInfo("export.qpool.successful", "1");
}
} else if (selectedNode instanceof SectionNode) {
SectionNode sectionNode = (SectionNode) selectedNode;
QTIObject qtiObject = sectionNode.getUnderlyingQTIObject();
if (qtiObject instanceof Section) {
int count = doExportSection((Section) qtiObject);
showInfo("export.qpool.successful", Integer.toString(count));
}
} else if (selectedNode instanceof AssessmentNode) {
AssessmentNode assessmentNode = (AssessmentNode) selectedNode;
QTIObject qtiObject = assessmentNode.getUnderlyingQTIObject();
if (qtiObject instanceof Assessment) {
int count = doExportAssessment((Assessment) qtiObject);
showInfo("export.qpool.successful", Integer.toString(count));
}
}
}
use of org.olat.ims.qti.editor.beecom.objects.QTIObject 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