use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class SharedFolderManager method getAsMediaResource.
public MediaResource getAsMediaResource(OLATResourceable res) {
String exportFileName = res.getResourceableId() + ".zip";
File fExportZIP = new File(WebappHelper.getTmpDir() + "/" + exportFileName);
VFSContainer sharedFolder = getSharedFolder(res);
// OLAT-5368: do intermediate commit to avoid transaction timeout
// discussion intermediatecommit vs increased transaction timeout:
// pro intermediatecommit: not much
// pro increased transaction timeout: would fix OLAT-5368 but only move the problem
// @TODO OLAT-2597: real solution is a long-running background-task concept...
DBFactory.getInstance().intermediateCommit();
ZipUtil.zip(sharedFolder.getItems(), new LocalFileImpl(fExportZIP), false);
return new CleanupAfterDeliveryFileMediaResource(fExportZIP);
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ItemFormController method fileUploaded.
/**
* Helper to process a uploaded file. Adjust the filename and the file
* suffix. Guess the width and height and fill the appropriate fields.
*/
private void fileUploaded() {
file.clearError();
if (file.isUploadSuccess()) {
String newFilename = file.getUploadFileName().toLowerCase().replaceAll(" ", "_");
file.setUploadFileName(newFilename);
VFSLeaf movie = new LocalFileImpl(file.getUploadFile());
if (newFilename.endsWith("mov") || newFilename.endsWith("m4v")) {
// when uploading a video from an iOS device.
if (movieService.isMP4(movie, newFilename)) {
newFilename = newFilename.substring(0, newFilename.length() - 3) + "mp4";
file.setUploadFileName(newFilename);
}
}
if (validateFilename(newFilename)) {
// try to detect width and height for movies, prefill for user if possible
Size size = movieService.getSize(movie, FileUtils.getFileSuffix(newFilename));
if (size != null) {
if (size.getWidth() > 1) {
widthEl.setValue(Integer.toString(size.getWidth()));
}
if (size.getHeight() > 1) {
heightEl.setValue(Integer.toString(size.getHeight()));
}
}
}
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class RepositoryEntryImportExport method exportDoExportProperties.
/**
* Export metadata of a repository entry to a file.
* Only one repository entry's metadata may be exported into a directory. The
* file name of the properties file will be the same for all repository entries!
*/
public void exportDoExportProperties() {
// save repository entry properties
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(new File(baseDirectory, PROPERTIES_FILE));
XStream xstream = getXStream();
RepositoryEntryImport imp = new RepositoryEntryImport(re);
RepositoryManager rm = RepositoryManager.getInstance();
VFSLeaf image = rm.getImage(re);
if (image instanceof LocalFileImpl) {
imp.setImageName(image.getName());
FileUtils.copyFileToDir(((LocalFileImpl) image).getBasefile(), baseDirectory, "");
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
VFSLeaf movie = repositoryService.getIntroductionMovie(re);
if (movie instanceof LocalFileImpl) {
imp.setMovieName(movie.getName());
FileUtils.copyFileToDir(((LocalFileImpl) movie).getBasefile(), baseDirectory, "");
}
addLicenseInformations(imp, re);
xstream.toXML(imp, fOut);
} catch (IOException ioe) {
throw new OLATRuntimeException("Error writing repo properties.", ioe);
} finally {
FileUtils.closeSafely(fOut);
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class RepositoryEntryImportExport method importContent.
public RepositoryEntry importContent(RepositoryEntry newEntry, VFSContainer mediaContainer) {
if (!anyExportedPropertiesAvailable())
return newEntry;
RepositoryManager repositoryManager = CoreSpringFactory.getImpl(RepositoryManager.class);
if (StringHelper.containsNonWhitespace(getImageName())) {
File newFile = new File(baseDirectory, getImageName());
VFSLeaf newImage = new LocalFileImpl(newFile);
repositoryManager.setImage(newImage, newEntry);
}
if (StringHelper.containsNonWhitespace(getMovieName())) {
String movieName = getMovieName();
String extension = FileUtils.getFileSuffix(movieName);
File newFile = new File(baseDirectory, movieName);
try (InputStream inStream = new FileInputStream(newFile)) {
VFSLeaf movieLeaf = mediaContainer.createChildLeaf(newEntry.getKey() + "." + extension);
VFSManager.copyContent(inStream, movieLeaf);
} catch (IOException e) {
log.error("", e);
}
}
return setRepoEntryPropertiesFromImport(newEntry);
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class RepositoryEditDescriptionController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == dateTypesEl) {
updateDatesVisibility();
} else if (source == licenseEl) {
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
;
} else if (source == fileUpload) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
fileUpload.clearError();
VFSLeaf img = repositoryManager.getImage(repositoryEntry);
if (fileUpload.getUploadFile() != null && fileUpload.getUploadFile() != fileUpload.getInitialFile()) {
fileUpload.reset();
if (img != null) {
fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
}
} else if (img != null) {
repositoryManager.deleteImage(repositoryEntry);
fileUpload.setInitialFile(null);
}
flc.setDirty(true);
}
} else if (source == movieUpload) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
movieUpload.clearError();
VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
if (movieUpload.getUploadFile() != null && movieUpload.getUploadFile() != movieUpload.getInitialFile()) {
movieUpload.reset();
if (movie != null) {
movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
}
} else if (movie != null) {
movie.delete();
movieUpload.setInitialFile(null);
}
flc.setDirty(true);
}
}
super.formInnerEvent(ureq, source, event);
}
Aggregations