Search in sources :

Example 1 with IMSEntityResolver

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

the class QTIQPoolServiceProvider method extractTextContent.

@Override
public String extractTextContent(QuestionItemFull item) {
    String content = null;
    if (item.getRootFilename() != null) {
        String dir = item.getDirectory();
        VFSContainer container = qpoolFileStorage.getContainer(dir);
        VFSItem file = container.resolve(item.getRootFilename());
        if (file instanceof VFSLeaf) {
            VFSLeaf leaf = (VFSLeaf) file;
            InputStream is = leaf.getInputStream();
            QTI12SAXHandler handler = new QTI12SAXHandler();
            try {
                XMLReader parser = XMLReaderFactory.createXMLReader();
                parser.setContentHandler(handler);
                parser.setEntityResolver(new IMSEntityResolver());
                parser.setFeature("http://xml.org/sax/features/validation", false);
                parser.parse(new InputSource(is));
            } catch (Exception e) {
                log.error("", e);
            } finally {
                FileUtils.closeSafely(is);
            }
            return handler.toString();
        }
    }
    return content;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) XMLReader(org.xml.sax.XMLReader)

Example 2 with IMSEntityResolver

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

the class ItemFileResourceValidator method readDocument.

private Document readDocument(InputStream in) {
    try {
        SAXReader reader = new SAXReader();
        reader.setEntityResolver(new IMSEntityResolver());
        reader.setValidation(false);
        return reader.read(in, "");
    } catch (Exception e) {
        return null;
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 3 with IMSEntityResolver

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

the class QTIExportProcessor method readItemXml.

private Element 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");
        is.close();
        return item;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : InputStream(java.io.InputStream) Element(org.dom4j.Element) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) IOException(java.io.IOException)

Example 4 with IMSEntityResolver

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

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)

Example 5 with IMSEntityResolver

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

the class FilePersister method retreiveResultsReporting.

/**
 * Retreive results for this user/aiid
 *
 * @param type The type of results
 * @return
 */
public static Document retreiveResultsReporting(Identity subj, String type, long aiid) {
    File fUserdataRoot = new File(WebappHelper.getUserDataRoot());
    String path = RES_REPORTING + File.separator + subj.getName() + File.separator + type + File.separator + aiid + ".xml";
    File fDoc = new File(fUserdataRoot, path);
    Document doc = null;
    try {
        InputStream is = new FileInputStream(fDoc);
        BufferedInputStream bis = new BufferedInputStream(is);
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(bis, false);
        is.close();
        bis.close();
    } catch (Exception e) {
        throw new OLATRuntimeException(FilePersister.class, "Error retrieving results reporting for subject: '" + subj.getName() + "'; assessment id: '" + aiid + "'", e);
    }
    return doc;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser) File(java.io.File) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) 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