Search in sources :

Example 6 with ParserManager

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

the class TestFileResource method getQTIDocument.

public static QTIDocument getQTIDocument(OLATResource resource) {
    File packageDir = FileResourceManager.getInstance().unzipFileResource(resource);
    File qtiFile = new File(packageDir, ImsRepositoryResolver.QTI_FILE);
    try (InputStream in = new FileInputStream(qtiFile)) {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(in, true);
        ParserManager parser = new ParserManager();
        QTIDocument document = (QTIDocument) parser.parse(doc);
        return document;
    } catch (Exception e) {
        log.error("Exception when parsing input QTI input stream for ", e);
        return null;
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLParser(org.olat.core.util.xml.XMLParser) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) File(java.io.File) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 7 with ParserManager

use of org.olat.ims.qti.editor.beecom.parser.ParserManager 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 8 with ParserManager

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

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

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

the class QTI12To21ConverterTest method loadDocument.

private QTIDocument loadDocument(String filename) {
    try (InputStream in = QTI12To21ConverterTest.class.getResourceAsStream(filename)) {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(in, true);
        ParserManager parser = new ParserManager();
        return (QTIDocument) parser.parse(doc);
    } catch (Exception e) {
        log.error("Exception when parsing input QTI input stream for " + filename, e);
        return null;
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) InputStream(java.io.InputStream) XMLParser(org.olat.core.util.xml.XMLParser) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) URISyntaxException(java.net.URISyntaxException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) ImsManifestException(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ImsManifestException) IOException(java.io.IOException)

Example 10 with ParserManager

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

the class TestFileResource method getQTIDocument.

public static QTIDocument getQTIDocument(OLATResource resource) {
    File packageDir = FileResourceManager.getInstance().unzipFileResource(resource);
    File qtiFile = new File(packageDir, ImsRepositoryResolver.QTI_FILE);
    try (InputStream in = new FileInputStream(qtiFile)) {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(in, true);
        ParserManager parser = new ParserManager();
        QTIDocument document = (QTIDocument) parser.parse(doc);
        return document;
    } catch (Exception e) {
        log.error("Exception when parsing input QTI input stream for ", e);
        return null;
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLParser(org.olat.core.util.xml.XMLParser) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) File(java.io.File) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

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