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
}
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations