/**
* @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;
}
// exported olat surveys don't have the correct essay prefix. Search
// 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));