Search in sources :

Example 11 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class XStreamHelper method readObject.

/**
 * Read an object from the given leaf using the xStream object. It is
 * usefull to add field and attribute mappers to the stream.
 *
 * @param xStream
 *            The (configured) xStream.
 * @param file
 * @return
 */
public static Object readObject(XStream xStream, VFSLeaf file) {
    InputStream fis = null;
    BufferedInputStream bis = null;
    try {
        fis = file.getInputStream();
        bis = new BufferedInputStream(fis);
        return readObject(xStream, bis);
    } catch (Exception e) {
        throw new OLATRuntimeException(XStreamHelper.class, "could not read Object from file: " + file.getName(), e);
    } finally {
        try {
            if (fis != null)
                fis.close();
            if (bis != null)
                bis.close();
        } catch (Exception e) {
        // we did our best to close the inputStream
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 12 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class XStreamHelper method writeObject.

/**
 * Write a an object to an output stream. UTF-8 is used as encoding in the
 * XML declaration. It is useful to set attribute and field mappers to
 * allow later refactoring of the class!
 *
 * @param xStream
 *            The (configured) xStream.
 * @param os
 * @param obj
 *            the object to be serialized
 */
public static void writeObject(XStream xStream, OutputStream os, Object obj) {
    try {
        OutputStreamWriter osw = new OutputStreamWriter(os, ENCODING);
        String data = xStream.toXML(obj);
        data = "<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>\n" + // give a decent header with the encoding used
        data;
        osw.write(data);
        osw.close();
    } catch (Exception e) {
        throw new OLATRuntimeException(XStreamHelper.class, "Could not write object to stream.", e);
    } finally {
        FileUtils.closeSafely(os);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 13 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method getOrCreateDataExportDirectory.

/**
 * Returns the data export directory. If the directory does not yet exist the
 * directory will be created
 *
 * @param ureq The user request
 * @param courseName The course name or title. Will be used as directory name
 * @return The file representing the dat export directory
 */
public static File getOrCreateDataExportDirectory(Identity identity, String courseName) {
    String courseFolder = StringHelper.transformDisplayNameToFileSystemName(courseName);
    // folder where exported user data should be put
    File exportFolder = new File(FolderConfig.getCanonicalRoot() + FolderConfig.getUserHomes() + "/" + identity.getName() + "/private/archive/" + courseFolder);
    if (exportFolder.exists()) {
        if (!exportFolder.isDirectory()) {
            throw new OLATRuntimeException(ExportUtil.class, "File " + exportFolder.getAbsolutePath() + " already exists but it is not a folder!", null);
        }
    } else {
        exportFolder.mkdirs();
    }
    return exportFolder;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Example 14 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class NodeExportVisitor method prepareFilesystem.

/**
 * Prepares the filesystem for this course.
 */
private void prepareFilesystem() {
    // generate course base path
    String relPath = File.separator + COURSE_ROOT_DIR_NAME + File.separator + getResourceableId().longValue();
    courseRootContainer = new OlatRootFolderImpl(relPath, null);
    File fBasePath = courseRootContainer.getBasefile();
    if (!fBasePath.exists() && !fBasePath.mkdirs())
        throw new OLATRuntimeException(this.getClass(), "Could not create course base path:" + courseRootContainer, null);
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Example 15 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class NodeExportVisitor method getIsolatedCourseFolder.

protected OlatRootFolderImpl getIsolatedCourseFolder() {
    // create local course folder
    OlatRootFolderImpl isolatedCourseFolder = new OlatRootFolderImpl(courseRootContainer.getRelPath() + File.separator + COURSEFOLDER, null);
    // generate course folder
    File fCourseFolder = isolatedCourseFolder.getBasefile();
    if (!fCourseFolder.exists() && !fCourseFolder.mkdirs()) {
        throw new OLATRuntimeException(this.getClass(), "could not create course's coursefolder path:" + fCourseFolder.getAbsolutePath(), null);
    }
    FullAccessWithQuotaCallback secCallback = new FullAccessWithLazyQuotaCallback(isolatedCourseFolder.getRelPath(), QuotaConstants.IDENTIFIER_DEFAULT_COURSE);
    isolatedCourseFolder.setLocalSecurityCallback(secCallback);
    return isolatedCourseFolder;
}
Also used : FullAccessWithLazyQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithLazyQuotaCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FullAccessWithQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12