Search in sources :

Example 76 with Attribute

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;
}
Also used : Control(org.olat.ims.qti.editor.beecom.objects.Control) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) SelectionOrdering(org.olat.ims.qti.editor.beecom.objects.SelectionOrdering) Attribute(org.dom4j.Attribute) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) Metadata(org.olat.ims.qti.editor.beecom.objects.Metadata) List(java.util.List) ArrayList(java.util.ArrayList)

Example 77 with Attribute

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;
}
Also used : Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 78 with Attribute

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;
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 79 with Attribute

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);
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Node(org.dom4j.Node) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) CDATA(org.dom4j.CDATA)

Example 80 with Attribute

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);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

Attribute (org.dom4j.Attribute)114 Element (org.dom4j.Element)88 Document (org.dom4j.Document)30 ArrayList (java.util.ArrayList)28 List (java.util.List)26 Iterator (java.util.Iterator)23 Node (org.dom4j.Node)14 HashMap (java.util.HashMap)12 File (java.io.File)11 SAXReader (org.dom4j.io.SAXReader)11 IOException (java.io.IOException)10 Map (java.util.Map)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)6 Namespace (org.dom4j.Namespace)5 QName (org.dom4j.QName)5 PropertyString (org.pentaho.commons.util.repository.type.PropertyString)5 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3