public class SectionParser implements IParser {
private ParserManager parserManager = new ParserManager();
public Object parse(Element element) {
//assert element.getName().equalsIgnoreCase("questestinterop");
Section section = new Section();
// attributes
section.setIdent(element.attribute("ident").getValue());
section.setTitle(element.attribute("title").getValue());
// elements
// DURATION
QTIObject duration =
(QTIObject) parserManager.parse(element.element("duration"));
section.setDuration(duration);
List sectioncontrolsXML = element.elements("sectioncontrol");
List sectioncontrols = new ArrayList();
for(Iterator i= sectioncontrolsXML.iterator();i.hasNext();) {
sectioncontrols.add(parserManager.parse((Element)i.next()));
}
if (sectioncontrols.size() == 0) {
sectioncontrols.add(new Control());
}
section.setSectioncontrols(sectioncontrols);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering)parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null){
section.setSelection_ordering(selectionOrdering);
} else {
section.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()));
}
section.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()));
}
section.setItems(items);
//OBJECTIVES
Element mattext = (Element)element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
section.setObjectives(mattext.getTextTrim());
//FEEDBACKS
List feedbacksXML = element.elements("sectionfeedback");
List feedbacks = new ArrayList();
for(Iterator i = feedbacksXML.iterator();i.hasNext();) {
QTIObject tmp = (QTIObject)parserManager.parse((Element)i.next());
feedbacks.add(tmp);
}
section.setSectionfeedbacks(feedbacks);
// OUTCOMES_PROCESSING
// TODO: maybe we should use the OutcomesProcessing object and parser here? Same as on
// assessment level?
QTIObject outcomes_processing = (QTIObject)parserManager.parse(element.element("outcomes_processing"));
section.setOutcomes_processing(outcomes_processing);
return section;
}