Search in sources :

Example 26 with XMLParser

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

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

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

the class IMSLoader method loadIMSDocument.

public static Document loadIMSDocument(Path documentPath) {
    Document doc = null;
    try (InputStream in = Files.newInputStream(documentPath)) {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        doc = xmlParser.parse(in, false);
    } catch (Exception e) {
        return null;
    }
    return doc;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser)

Example 29 with XMLParser

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

the class IMSLoader method loadIMSDocument.

/**
 * Reads an IMS XML Document if supported by /org/olat/ims/resources.
 * @param documentF
 * @return document
 */
public static Document loadIMSDocument(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 (Exception e) {
        return null;
    } 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) Document(org.dom4j.Document) XMLParser(org.olat.core.util.xml.XMLParser) FileInputStream(java.io.FileInputStream)

Example 30 with XMLParser

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

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