Search in sources :

Example 31 with LocalFolderImpl

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();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 32 with LocalFolderImpl

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 33 with LocalFolderImpl

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 34 with LocalFolderImpl

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 35 with LocalFolderImpl

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());
    }
}
Also used : ForumArtefact(org.olat.modules.fo.portfolio.ForumArtefact) VFSContainer(org.olat.core.util.vfs.VFSContainer) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) Test(org.junit.Test)

Aggregations

LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)122 File (java.io.File)82 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 VFSItem (org.olat.core.util.vfs.VFSItem)38 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)30 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 Document (org.dom4j.Document)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Document (org.apache.lucene.document.Document)6 Element (org.dom4j.Element)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)6 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)6 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6