use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class AssessmentParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("assessment");
Assessment assessment = new Assessment();
// attributes
Attribute attr = element.attribute("ident");
if (attr != null)
assessment.setIdent(attr.getValue());
attr = element.attribute("title");
if (attr != null)
assessment.setTitle(attr.getValue());
// elements
// DURATION
QTIObject duration = (QTIObject) parserManager.parse(element.element("duration"));
assessment.setDuration(duration);
// ASSESSMENTCONTROL
List assessmentcontrolsXML = element.elements("assessmentcontrol");
List assessmentcontrols = new ArrayList();
for (Iterator i = assessmentcontrolsXML.iterator(); i.hasNext(); ) {
assessmentcontrols.add(parserManager.parse((Element) i.next()));
assessment.setInheritControls(true);
}
if (assessmentcontrols.size() == 0) {
assessmentcontrols.add(new Control());
assessment.setInheritControls(false);
}
assessment.setAssessmentcontrols(assessmentcontrols);
// OUTCOMES PROCESSING
OutcomesProcessing outcomesProcessing = (OutcomesProcessing) parserManager.parse(element.element("outcomes_processing"));
if (outcomesProcessing != null)
assessment.setOutcomes_processing(outcomesProcessing);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null) {
assessment.setSelection_ordering(selectionOrdering);
} else {
assessment.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()));
}
assessment.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()));
}
assessment.setItems(items);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
assessment.setObjectives(mattext.getTextTrim());
// METADATA
Metadata metadata = (Metadata) parserManager.parse(element.element("qtimetadata"));
if (metadata != null)
assessment.setMetadata(metadata);
return assessment;
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class FeedbackParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.objects.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("sectionfeedback")
// || element.getName().equalsIgnoreCase("itemfeedback")
// || element.getName().equalsIgnoreCase("assessmentfeedback");
List materialsXML = element.selectNodes(".//material");
if (materialsXML.size() == 0)
return null;
Feedback feedback = new Feedback();
// attributes
Attribute tmp = element.attribute("ident");
if (tmp != null)
feedback.setIdent(tmp.getValue());
tmp = element.attribute("title");
if (tmp != null)
feedback.setTitle(tmp.getValue());
tmp = element.attribute("view");
if (tmp != null)
feedback.setView(tmp.getValue());
// get type
if (element.element("solution") != null)
return null;
else if (element.element("hint") != null)
return null;
// parse Material
// MATERIAL
List<Object> materials = new ArrayList<>();
for (Iterator i = materialsXML.iterator(); i.hasNext(); ) {
materials.add(parserManager.parse((Element) i.next()));
}
feedback.setMaterials(materials);
return feedback;
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class MaterialParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("material");
List materials = element.elements();
if (materials.size() == 0)
return null;
Material material = new Material();
// ATTRIBUTES
Attribute label = element.attribute("label");
if (label != null)
material.setLable(label.getValue());
// ELEMENTS
for (Iterator i = materials.iterator(); i.hasNext(); ) {
QTIObject obj = (QTIObject) parserManager.parse((Element) i.next());
if (obj != null)
material.getElements().add(obj);
}
return material;
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class QTIExportProcessor method collectResourcesInMatText.
/**
* Collect the file and rewrite the
* @param el
* @param container
* @param materials
* @param paths
*/
private void collectResourcesInMatText(Element el, VFSContainer container, ItemsAndMaterials materials) {
// mattext
@SuppressWarnings("unchecked") List<Element> mattextList = el.selectNodes(".//mattext");
for (Element mat : mattextList) {
Attribute texttypeAttr = mat.attribute("texttype");
String texttype = texttypeAttr.getValue();
if ("text/html".equals(texttype)) {
@SuppressWarnings("unchecked") List<Node> childElList = new ArrayList<Node>(mat.content());
for (Node childEl : childElList) {
mat.remove(childEl);
}
for (Node childEl : childElList) {
if (Node.CDATA_SECTION_NODE == childEl.getNodeType()) {
CDATA data = (CDATA) childEl;
boolean changed = false;
String text = data.getText();
List<String> materialPaths = findMaterialInMatText(text);
for (String materialPath : materialPaths) {
VFSItem matVfsItem = container.resolve(materialPath);
if (matVfsItem instanceof VFSLeaf) {
String exportUri = generateExportPath(materials.getPaths(), matVfsItem);
materials.addMaterial(new ItemMaterial((VFSLeaf) matVfsItem, exportUri));
text = text.replaceAll(materialPath, exportUri);
changed = true;
}
}
if (changed) {
mat.addCDATA(text);
} else {
mat.add(childEl);
}
} else {
mat.add(childEl);
}
}
}
}
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class QTIExportProcessor method collectResourcesInMatMedias.
@SuppressWarnings("unchecked")
private void collectResourcesInMatMedias(Element el, VFSContainer container, ItemsAndMaterials materials) {
// matimage uri
List<Element> matList = new ArrayList<Element>();
matList.addAll(el.selectNodes(".//matimage"));
matList.addAll(el.selectNodes(".//mataudio"));
matList.addAll(el.selectNodes(".//matvideo"));
for (Element mat : matList) {
Attribute uriAttr = mat.attribute("uri");
String uri = uriAttr.getValue();
VFSItem matVfsItem = container.resolve(uri);
if (matVfsItem instanceof VFSLeaf) {
String exportUri = generateExportPath(materials.getPaths(), matVfsItem);
ItemMaterial iMat = new ItemMaterial((VFSLeaf) matVfsItem, exportUri);
materials.addMaterial(iMat);
mat.addAttribute("uri", exportUri);
}
}
}
Aggregations