use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class DialogCourseNodeRunController method doUploadFile.
private void doUploadFile(UserRequest ureq) {
removeAsListenerAndDispose(fileUplCtr);
VFSContainer tmpContainer = new LocalFolderImpl(new File(WebappHelper.getTmpDir(), "poster_" + UUID.randomUUID()));
fileUplCtr = new FileUploadController(getWindowControl(), tmpContainer, ureq, FolderConfig.getLimitULKB(), Quota.UNLIMITED, null, false, false, false, false, true, false);
listenTo(fileUplCtr);
cmc = new CloseableModalController(getWindowControl(), "close", fileUplCtr.getInitialComponent(), true, translate("dialog.upload.file"));
listenTo(cmc);
cmc.activate();
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class RepositoryManager method getImage.
public VFSLeaf getImage(OLATResourceable re) {
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
String imageName = re.getResourceableId() + ".jpg";
VFSItem image = repositoryHome.resolve(imageName);
if (image instanceof VFSLeaf) {
return (VFSLeaf) image;
}
imageName = re.getResourceableId() + ".png";
image = repositoryHome.resolve(imageName);
if (image instanceof VFSLeaf) {
return (VFSLeaf) image;
}
return null;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class RepositoryManager method setImage.
public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
VFSLeaf currentImage = getImage(re);
if (currentImage != null) {
if (currentImage instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
if (info != null) {
info.clearThumbnails();
}
}
currentImage.delete();
}
if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
return false;
}
String targetExtension = ".png";
String extension = FileUtils.getFileSuffix(newImageFile.getName());
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
targetExtension = ".jpg";
}
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
Size newImageSize = imageHelper.getSize(newImageFile, extension);
if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
boolean success = VFSManager.copyContent(newImageFile, repoImage);
return success;
}
}
Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
return size != null;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class RepositoryManager method copyImage.
/**
* Copy the repo entry image from the source to the target repository entry.
* If the source repo entry does not exists, nothing will happen
*
* @param src
* @param target
* @return
*/
public boolean copyImage(RepositoryEntry source, RepositoryEntry target) {
VFSLeaf srcFile = getImage(source);
if (srcFile == null) {
return false;
}
VFSLeaf targetFile = getImage(target);
if (targetFile != null) {
targetFile.delete();
}
String sourceImageSuffix = FileUtils.getFileSuffix(srcFile.getName());
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
VFSLeaf newImage = repositoryHome.createChildLeaf(target.getResourceableId() + "." + sourceImageSuffix);
if (newImage != null) {
return VFSManager.copyContent(srcFile, newImage);
}
return false;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class EPArtefactManagerTest method testCreateForumArtefact.
@Test
public void testCreateForumArtefact() {
EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler("Forum");
AbstractArtefact artefact = handler.createArtefact();
artefact.setAuthor(ident1);
assertNotNull(artefact);
assertTrue(artefact instanceof ForumArtefact);
// update the artefact
AbstractArtefact persistedArtefact = epFrontendManager.updateArtefact(artefact);
assertNotNull(persistedArtefact);
assertTrue(persistedArtefact instanceof ForumArtefact);
dbInstance.commitAndCloseSession();
// reload the artefact
AbstractArtefact loadedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
assertNotNull(loadedArtefact);
assertTrue(loadedArtefact instanceof ForumArtefact);
// get the VFS container of the artefact
VFSContainer container = epFrontendManager.getArtefactContainer(loadedArtefact);
assertNotNull(container);
if (container instanceof LocalFolderImpl) {
LocalFolderImpl folder = (LocalFolderImpl) container;
assertNotNull(folder.getBasefile());
assertTrue(folder.getBasefile().exists());
assertTrue(folder.getBasefile().isDirectory());
}
}
Aggregations