Search in sources :

Example 46 with Attribute

use of org.dom4j.Attribute in project openolat by klemens.

the class IQ12EditForm method update.

/**
 * Update the module configuration from the qti file: read min/max/cut values
 * @param res
 */
protected void update(OLATResource res) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedRoot = frm.unzipFileResource(res);
    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    if (vfsQTI == null) {
        throw new AssertException("qti file did not exist even it should be guaranteed by repositor check-in ");
    }
    // ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    if (doc == null) {
        // error reading qti file (existence check was made before)
        throw new AssertException("qti file could not be read " + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
    }
    // Extract min, max and cut value
    Float minValue = null, maxValue = null, cutValue = null;
    Element decvar = (Element) doc.selectSingleNode("questestinterop/assessment/outcomes_processing/outcomes/decvar");
    if (decvar != null) {
        Attribute minval = decvar.attribute("minvalue");
        if (minval != null) {
            String mv = minval.getValue();
            try {
                minValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute maxval = decvar.attribute("maxvalue");
        if (maxval != null) {
            String mv = maxval.getValue();
            try {
                maxValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute cutval = decvar.attribute("cutvalue");
        if (cutval != null) {
            String cv = cutval.getValue();
            try {
                cutValue = new Float(Float.parseFloat(cv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
    }
    // Put values to module configuration
    minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
    minScoreEl.setVisible(minValue != null);
    maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
    maxScoreEl.setVisible(maxValue != null);
    cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
    cutValueEl.setVisible(cutValue != null);
}
Also used : AssertException(org.olat.core.logging.AssertException) FileResourceManager(org.olat.fileresource.FileResourceManager) Attribute(org.dom4j.Attribute) VFSContainer(org.olat.core.util.vfs.VFSContainer) SelectionElement(org.olat.core.gui.components.form.flexible.elements.SelectionElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Element(org.dom4j.Element) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 47 with Attribute

use of org.dom4j.Attribute in project openolat by klemens.

the class SurveyFileResource method validateQti.

private static ResourceEvaluation validateQti(Document doc, ResourceEvaluation eval) {
    if (doc == null) {
        eval.setValid(false);
    } else {
        List assessment = doc.selectNodes("questestinterop/assessment");
        if (assessment.size() == 1) {
            Object assessmentObj = assessment.get(0);
            if (assessmentObj instanceof Element) {
                Element assessmentEl = (Element) assessmentObj;
                Attribute title = assessmentEl.attribute("title");
                if (title != null) {
                    eval.setDisplayname(title.getValue());
                }
                List metas = assessmentEl.selectNodes("qtimetadata/qtimetadatafield");
                for (Iterator iter = metas.iterator(); iter.hasNext(); ) {
                    Element el_metafield = (Element) iter.next();
                    Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel");
                    String label = el_label.getText();
                    if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) {
                        // type meta
                        Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry");
                        String entry = el_entry.getText();
                        if (entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY)) {
                            eval.setValid(true);
                        }
                    }
                }
            }
        }
    }
    return eval;
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List)

Example 48 with Attribute

use of org.dom4j.Attribute in project openolat by klemens.

the class TestFileResource method validateQti.

private static ResourceEvaluation validateQti(Document doc, ResourceEvaluation eval) {
    if (doc == null) {
        eval.setValid(false);
    } else {
        boolean validType = false;
        boolean validScore = true;
        List assessment = doc.selectNodes("questestinterop/assessment");
        if (assessment.size() == 1) {
            Object assessmentObj = assessment.get(0);
            if (assessmentObj instanceof Element) {
                Element assessmentEl = (Element) assessmentObj;
                Attribute title = assessmentEl.attribute("title");
                if (title != null) {
                    eval.setDisplayname(title.getValue());
                }
                // check if this is marked as test
                List metas = assessmentEl.selectNodes("qtimetadata/qtimetadatafield");
                for (Iterator iter = metas.iterator(); iter.hasNext(); ) {
                    Element el_metafield = (Element) iter.next();
                    Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel");
                    String label = el_label.getText();
                    if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) {
                        // type meta
                        Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry");
                        String entry = el_entry.getText();
                        if (entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF) || entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
                            validType = true;
                        }
                    }
                }
                // check if at least one section with one item
                List<Element> sectionItems = assessmentEl.selectNodes("section/item");
                if (sectionItems.size() > 0) {
                    for (Element it : sectionItems) {
                        List<?> sv = it.selectNodes("resprocessing/outcomes/decvar[@varname='SCORE']");
                        // the QTIv1.2 system relies on the SCORE variable of items
                        if (sv.size() != 1) {
                            validScore &= false;
                        }
                    }
                }
            }
        }
        eval.setValid(validType && validScore);
    }
    return eval;
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List)

Example 49 with Attribute

use of org.dom4j.Attribute in project openolat by klemens.

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 50 with Attribute

use of org.dom4j.Attribute in project openolat by klemens.

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)

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