Search in sources :

Example 11 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.

the class QTIDocumentParser method parse.

public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("questestinterop");
    QTIDocument qtiDocument = new QTIDocument();
    Object tmp = null;
    Element qticomment = element.element("qticomment");
    qtiDocument.setQticomment((QTIObject) parserManager.parse(qticomment));
    Element objectbank = element.element("objectbank");
    tmp = parserManager.parse(objectbank);
    if (tmp != null) {
        qtiDocument.setObjectbank((QTIObject) tmp);
    }
    Element assesment = element.element("assessment");
    tmp = parserManager.parse(assesment);
    if (tmp != null) {
        qtiDocument.setAssessment((Assessment) tmp);
    }
    return qtiDocument;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) Element(org.dom4j.Element) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject)

Example 12 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument 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)

Example 13 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.

the class TestFileResource method getQTIEditorPackageReader.

public static QTIReaderPackage getQTIEditorPackageReader(OLATResource resource) {
    VFSContainer baseDir = FileResourceManager.getInstance().unzipContainerResource(resource);
    QTIDocument document = getQTIDocument(resource);
    return new QTIReaderPackage(baseDir, document);
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 14 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.

the class QTI12ResultDetailsController method checkEssay.

private boolean checkEssay() {
    QTIDocument doc = TestFileResource.getQTIDocument(repositoryEntry.getOlatResource());
    if (doc != null && doc.getAssessment() != null) {
        Assessment ass = doc.getAssessment();
        // Sections with their Items
        List<Section> sections = ass.getSections();
        for (Section section : sections) {
            List<Item> items = section.getItems();
            for (Item item : items) {
                String ident = item.getIdent();
                if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) Item(org.olat.ims.qti.editor.beecom.objects.Item) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 15 with QTIDocument

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

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)

Aggregations

QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)18 Document (org.dom4j.Document)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 ParserManager (org.olat.ims.qti.editor.beecom.parser.ParserManager)6 File (java.io.File)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 XMLParser (org.olat.core.util.xml.XMLParser)4 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)4 FileInputStream (java.io.FileInputStream)2 URISyntaxException (java.net.URISyntaxException)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 Metadata (org.olat.ims.qti.editor.beecom.objects.Metadata)2 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2