Search in sources :

Example 41 with Item

use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.

the class QTIEditHelper method readItemXml.

public static Item readItemXml(VFSLeaf leaf) {
    Document doc = null;
    try {
        InputStream is = leaf.getInputStream();
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(is, false);
        Element item = (Element) doc.selectSingleNode("questestinterop/item");
        ParserManager parser = new ParserManager();
        Item qtiItem = (Item) parser.parse(item);
        is.close();
        return qtiItem;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) InputStream(java.io.InputStream) Element(org.dom4j.Element) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) XMLParser(org.olat.core.util.xml.XMLParser) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) IOException(java.io.IOException)

Example 42 with Item

use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.

the class QTIEditHelper method getFeedbacks.

/**
 * @param object
 * @return
 */
private static List<Feedback> getFeedbacks(QTIObject object) {
    List<Feedback> feedbacks = null;
    if (Item.class.isAssignableFrom(object.getClass())) {
        Item item = (Item) object;
        feedbacks = item.getItemfeedbacks();
    } else if (Section.class.isAssignableFrom(object.getClass())) {
        Section section = (Section) object;
        feedbacks = section.getSectionfeedbacks();
    } else if (Assessment.class.isAssignableFrom(object.getClass())) {
        Assessment assessment = (Assessment) object;
        feedbacks = assessment.getAssessfeedbacks();
    }
    return feedbacks;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 43 with Item

use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.

the class QTIEditHelper method getMediaReferences.

/**
 * Retrieves all referenced media by thisItem if filterOut is false,
 * or all referenced media by other items if filterOut is true.
 * <p>
 * Iterates over all sections, items, etc. </br>
 * -> if filterOut is true gets all references except those for thisItem.
 * -> if filterOut is false gets all references for thisItem.
 *
 * @param qtiDocument
 * @param thisItem
 * @param filterOut
 * @return Returns empty set if no reference found.
 */
private static Set<String> getMediaReferences(QTIDocument qtiDocument, Item thisItem, boolean filterOut) {
    HashSet<String> returnSet = new HashSet<String>();
    // sections
    List sectionList = qtiDocument.getAssessment().getSections();
    Iterator sectionIterator = sectionList.iterator();
    while (sectionIterator.hasNext()) {
        // section
        Section section = (Section) sectionIterator.next();
        List itemList = section.getItems();
        Iterator listIterator = itemList.iterator();
        while (listIterator.hasNext()) {
            // item
            Item item = (Item) listIterator.next();
            if ((filterOut && thisItem.getIdent().equals(item.getIdent())) || (!filterOut && !thisItem.getIdent().equals(item.getIdent()))) {
                continue;
            }
            // question
            Material material = item.getQuestion().getQuestion();
            if (material != null) {
                String htmlContent = material.renderAsHtmlForEditor();
                // parse filenames
                returnSet.addAll(getMediaFileNames(htmlContent));
            }
            // responses
            List responseList = item.getQuestion().getResponses();
            Iterator responseIterator = responseList.iterator();
            while (responseIterator.hasNext()) {
                Response response = (Response) responseIterator.next();
                Material responseMat = response.getContent();
                // parse filenames
                if (responseMat != null) {
                    returnSet.addAll(getMediaFileNames(responseMat.renderAsHtmlForEditor()));
                }
                // response-level feedback
                Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
                if (responseFeedbackMat != null) {
                    returnSet.addAll(getMediaFileNames(responseFeedbackMat.renderAsHtmlForEditor()));
                }
            }
            // feedback
            Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
            if (masteryMat != null) {
                returnSet.addAll(getMediaFileNames(masteryMat.renderAsHtmlForEditor()));
            }
            Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
            if (failureMat != null) {
                returnSet.addAll(getMediaFileNames(failureMat.renderAsHtmlForEditor()));
            }
        }
    }
    return returnSet;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material) Section(org.olat.ims.qti.editor.beecom.objects.Section) HashSet(java.util.HashSet)

Example 44 with Item

use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.

the class QTIEditorMainController method doConvertItemToQtiNode.

private GenericQtiNode doConvertItemToQtiNode(QuestionItemView qitemv) {
    VFSContainer editorContainer = qtiPackage.getBaseDir();
    Item theItem = qtiQpoolServiceProvider.exportToQTIEditor(qitemv, editorContainer);
    GenericQtiNode node = new ItemNode(theItem, qtiPackage);
    return node;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Example 45 with Item

use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.

the class QTIEditorMainController method doDelete.

private void doDelete(GenericQtiNode clickedNode) {
    // check if any media to delete as well
    if (clickedNode.getUnderlyingQTIObject() instanceof Item) {
        Item selectedItem = (Item) clickedNode.getUnderlyingQTIObject();
        deletableMediaFiles = QTIEditHelper.getDeletableMedia(qtiPackage.getQTIDocument(), selectedItem);
    }
    // remove from underlying model
    GenericQtiNode parentNode = (GenericQtiNode) clickedNode.getParent();
    parentNode.removeQTIObjectAt(clickedNode.getPosition());
    // remove from tree model
    clickedNode.removeFromParent();
    qtiPackage.serializeQTIDocument();
    menuTree.setSelectedNodeId(clickedNode.getParent().getIdent());
    parentNode.childNodeChanges();
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Aggregations

Item (org.olat.ims.qti.editor.beecom.objects.Item)92 VFSItem (org.olat.core.util.vfs.VFSItem)38 Section (org.olat.ims.qti.editor.beecom.objects.Section)28 ArrayList (java.util.ArrayList)24 VFSContainer (org.olat.core.util.vfs.VFSContainer)18 Control (org.olat.ims.qti.editor.beecom.objects.Control)18 Element (org.dom4j.Element)16 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)16 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)16 Translator (org.olat.core.gui.translator.Translator)14 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)14 Response (org.olat.ims.qti.editor.beecom.objects.Response)14 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)14 File (java.io.File)12 QuestionItem (org.olat.modules.qpool.QuestionItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)10 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)10 SectionNode (org.olat.ims.qti.editor.tree.SectionNode)10 StatisticItem (org.olat.ims.qti.statistics.model.StatisticItem)10