Search in sources :

Example 1 with XMLParser

use of org.olat.core.util.xml.XMLParser 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 2 with XMLParser

use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.

the class CPManagerImpl method load.

/**
 * @see org.olat.ims.cp.CPManager#load(org.olat.core.util.vfs.VFSContainer)
 */
public ContentPackage load(VFSContainer directory, OLATResourceable ores) {
    XMLParser parser = new XMLParser();
    ContentPackage cp;
    VFSLeaf file = (VFSLeaf) directory.resolve("imsmanifest.xml");
    if (file != null) {
        try {
            DefaultDocument doc = (DefaultDocument) parser.parse(file.getInputStream(), false);
            cp = new ContentPackage(doc, directory, ores);
            // identifier.
            if (cp.getLastError() == null) {
                if (cp.isOLATContentPackage() && CPCore.OLAT_ORGANIZATION_IDENTIFIER.equals(cp.getFirstOrganizationInManifest().getIdentifier())) {
                    setUniqueOrgaIdentifier(cp);
                }
            }
        } catch (OLATRuntimeException e) {
            cp = new ContentPackage(null, directory, ores);
            logError("Reading imsmanifest failed. Dir: " + directory.getName() + ". Ores: " + ores.getResourceableId(), e);
            cp.setLastError("Exception reading XML for IMS CP: invalid xml-file ( " + directory.getName() + ")");
        }
    } else {
        cp = new ContentPackage(null, directory, ores);
        cp.setLastError("Exception reading XML for IMS CP: IMS-Manifest not found in " + directory.getName());
        logError("IMS manifiest xml couldn't be found in dir " + directory.getName() + ". Ores: " + ores.getResourceableId(), null);
        throw new OLATRuntimeException(CPManagerImpl.class, "The imsmanifest.xml file was not found.", new IOException());
    }
    return cp;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) DefaultDocument(org.dom4j.tree.DefaultDocument) IOException(java.io.IOException) XMLParser(org.olat.core.util.xml.XMLParser)

Example 3 with XMLParser

use of org.olat.core.util.xml.XMLParser 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 4 with XMLParser

use of org.olat.core.util.xml.XMLParser 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)

Example 5 with XMLParser

use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.

the class CPManifestTreeModel method loadDocument.

private Document loadDocument(String documentStr) throws IOException {
    InputStream in = null;
    Document doc = null;
    try {
        in = new ByteArrayInputStream(documentStr.getBytes());
        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 string " + documentStr, e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return doc;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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)

Aggregations

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