Search in sources :

Example 1 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager in project OpenOLAT by OpenOLAT.

the class QTIQPoolServiceProvider method exportToEditorPackage.

public void exportToEditorPackage(QTIEditorPackageImpl editorPackage, List<QuestionItemShort> items, boolean newTest) {
    VFSContainer editorContainer = editorPackage.getBaseDir();
    List<Long> itemKeys = toKeys(items);
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
    Section section = editorPackage.getQTIDocument().getAssessment().getSections().get(0);
    if (newTest) {
        // remove autogenerated question
        section.getItems().clear();
    }
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    for (QuestionItemFull fullItem : fullItems) {
        Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
        Item item = (Item) new ParserManager().parse(itemEl);
        item.setIdent(QTIEditHelper.generateNewIdent(item.getIdent()));
        section.getItems().add(item);
    }
}
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) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 2 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager in project OpenOLAT by OpenOLAT.

the class QTIQPoolServiceProvider method exportToQTIEditor.

/**
 * Export to QTI editor an item from the pool. The ident of the item
 * is always regenerated as an UUID.
 * @param qitem
 * @param editorContainer
 * @return
 */
public Item exportToQTIEditor(QuestionItemShort qitem, VFSContainer editorContainer) {
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    QuestionItemFull fullItem = questionItemDao.loadById(qitem.getKey());
    Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
    Item exportedItem = (Item) new ParserManager().parse(itemEl);
    exportedItem.setIdent(QTIEditHelper.generateNewIdent(exportedItem.getIdent()));
    return exportedItem;
}
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) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) Element(org.dom4j.Element)

Example 3 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager in project OpenOLAT by OpenOLAT.

the class QTIEditorPackageImpl method getQTIDocument.

/**
 * @return Reutrns the QTIDocument structure
 */
public QTIDocument getQTIDocument() {
    if (qtiDocument == null) {
        if (hasSerializedQTIDocument()) {
            qtiDocument = loadSerializedQTIDocument();
            resumed = true;
        } else {
            unzipPackage();
            Document doc = loadQTIDocument();
            if (doc != null) {
                ParserManager parser = new ParserManager();
                qtiDocument = (QTIDocument) parser.parse(doc);
                // grab assessment type
                Metadata meta = qtiDocument.getAssessment().getMetadata();
                String assessType = meta.getField(AssessmentInstance.QMD_LABEL_TYPE);
                if (assessType != null) {
                    qtiDocument.setSurvey(assessType.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY));
                }
                resumed = false;
            } else {
                qtiDocument = null;
            }
        }
    }
    return qtiDocument;
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) Metadata(org.olat.ims.qti.editor.beecom.objects.Metadata) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument)

Example 4 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager in project OpenOLAT by OpenOLAT.

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 5 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager in project openolat by klemens.

the class QTIQPoolServiceProvider method exportToQTIEditor.

/**
 * Export to QTI editor an item from the pool. The ident of the item
 * is always regenerated as an UUID.
 * @param qitem
 * @param editorContainer
 * @return
 */
public Item exportToQTIEditor(QuestionItemShort qitem, VFSContainer editorContainer) {
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    QuestionItemFull fullItem = questionItemDao.loadById(qitem.getKey());
    Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
    Item exportedItem = (Item) new ParserManager().parse(itemEl);
    exportedItem.setIdent(QTIEditHelper.generateNewIdent(exportedItem.getIdent()));
    return exportedItem;
}
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) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) Element(org.dom4j.Element)

Aggregations

ParserManager (org.olat.ims.qti.editor.beecom.parser.ParserManager)12 Document (org.dom4j.Document)8 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)8 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Element (org.dom4j.Element)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 XMLParser (org.olat.core.util.xml.XMLParser)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)6 QuestionItem (org.olat.modules.qpool.QuestionItem)4 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 URISyntaxException (java.net.URISyntaxException)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 Metadata (org.olat.ims.qti.editor.beecom.objects.Metadata)2 Section (org.olat.ims.qti.editor.beecom.objects.Section)2 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)2 ImsManifestException (uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ImsManifestException)2