Search in sources :

Example 26 with IMSEntityResolver

use of org.olat.ims.resources.IMSEntityResolver in project OpenOLAT by OpenOLAT.

the class QTIImportProcessor method readXml.

private Document readXml(InputStream in) {
    Document doc = null;
    try {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(in, false);
        return doc;
    } catch (Exception e) {
        return null;
    }
}
Also used : 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) NoSuchFileException(java.nio.file.NoSuchFileException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 27 with IMSEntityResolver

use of org.olat.ims.resources.IMSEntityResolver 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 28 with IMSEntityResolver

use of org.olat.ims.resources.IMSEntityResolver in project OpenOLAT by OpenOLAT.

the class CPManifestTreeModel method loadDocument.

private Document loadDocument(VFSLeaf documentF) throws IOException {
    InputStream in = null;
    Document doc = null;
    try {
        in = documentF.getInputStream();
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(in, false);
        in.close();
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException("could not read and parse from file " + documentF, e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return doc;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) AssertException(org.olat.core.logging.AssertException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 29 with IMSEntityResolver

use of org.olat.ims.resources.IMSEntityResolver 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)

Example 30 with IMSEntityResolver

use of org.olat.ims.resources.IMSEntityResolver in project openolat by klemens.

the class ScormCPManifestTreeModel method loadDocument.

private Document loadDocument(File documentF) {
    FileInputStream in = null;
    BufferedInputStream bis = null;
    Document doc = null;
    try {
        in = new FileInputStream(documentF);
        bis = new BufferedInputStream(in);
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(bis, false);
    } catch (IOException e) {
        throw new OLATRuntimeException(ScormCPManifestTreeModel.class, "could not read and parse from file " + documentF.getAbsolutePath(), e);
    } finally {
        try {
            if (in != null)
                in.close();
            if (bis != null)
                bis.close();
        } catch (Exception e) {
        // we did our best to close the inputStream
        }
    }
    return doc;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileInputStream(java.io.FileInputStream) AssertException(org.olat.core.logging.AssertException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Aggregations

IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)38 Document (org.dom4j.Document)30 XMLParser (org.olat.core.util.xml.XMLParser)30 InputStream (java.io.InputStream)28 IOException (java.io.IOException)22 File (java.io.File)14 VFSItem (org.olat.core.util.vfs.VFSItem)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)10 FileInputStream (java.io.FileInputStream)8 URL (java.net.URL)8 Node (org.dom4j.Node)8 Test (org.junit.Test)8 QuestionItem (org.olat.modules.qpool.QuestionItem)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)8 BufferedInputStream (java.io.BufferedInputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 Element (org.dom4j.Element)6 AssertException (org.olat.core.logging.AssertException)6