Search in sources :

Example 11 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class FolderManager method getFileInfosRecursively.

private static void getFileInfosRecursively(OlatRelPathImpl relPath, List<FileInfo> fileInfos, long newerThan, int basePathlen) {
    if (relPath instanceof VFSLeaf) {
        // is a file
        long lastModified = ((VFSLeaf) relPath).getLastModified();
        if (lastModified > newerThan) {
            MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPath);
            String bcrootPath = relPath.getRelPath();
            String bcRelPath = bcrootPath.substring(basePathlen);
            fileInfos.add(new FileInfo(bcRelPath, meta, new Date(lastModified)));
        }
    } else {
        // is a folder
        OlatRootFolderImpl container = (OlatRootFolderImpl) relPath;
        for (VFSItem item : container.getItems(new SystemItemFilter())) {
            getFileInfosRecursively((OlatRelPathImpl) item, fileInfos, newerThan, basePathlen);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date)

Example 12 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class FolderRunController method activatePath.

public void activatePath(UserRequest ureq, String path) {
    if (path != null && path.length() > 0) {
        VFSItem vfsItem = folderComponent.getRootContainer().resolve(path.endsWith("/") ? path.substring(0, path.length() - 1) : path);
        if (vfsItem instanceof VFSLeaf) {
            // could be a file - create the mapper - otherwise don't create one if it's a directory
            // Create a mapper to deliver the auto-download of the file. We have to
            // create a dedicated mapper here
            // and can not reuse the standard briefcase way of file delivering, some
            // very old fancy code
            // Mapper is cleaned up automatically by basic controller
            String baseUrl = registerMapper(ureq, new VFSContainerMapper(folderComponent.getRootContainer()));
            // Trigger auto-download
            DisplayOrDownloadComponent dordc = new DisplayOrDownloadComponent("downloadcomp", baseUrl + path);
            folderContainer.put("autoDownloadComp", dordc);
            if (path.lastIndexOf("/") > 0) {
                String dirPath = path.substring(0, path.lastIndexOf("/"));
                if (StringHelper.containsNonWhitespace(dirPath)) {
                    folderComponent.setCurrentContainerPath(dirPath);
                }
            }
        } else if (vfsItem instanceof VFSContainer) {
            if (StringHelper.containsNonWhitespace(path)) {
                folderComponent.setCurrentContainerPath(path);
            }
        }
        updatePathResource(ureq);
    }
}
Also used : VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) DisplayOrDownloadComponent(org.olat.core.gui.components.download.DisplayOrDownloadComponent) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 13 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class FolderRunController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    String path = BusinessControlFactory.getInstance().getPath(entries.get(0));
    VFSItem vfsItem = folderComponent.getRootContainer().resolve(path);
    if (vfsItem instanceof VFSContainer) {
        folderComponent.setCurrentContainerPath(path);
        updatePathResource(ureq);
    } else {
        activatePath(ureq, path);
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 14 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class CmdCreateFolder method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the folder
    String name = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildContainer(name);
    if (item instanceof OlatRelPathImpl) {
        // update meta data
        MetaInfo meta = metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item);
        meta.setAuthor(ureq.getIdentity());
        meta.write();
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FOLDER_EVENT, folderName));
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    } else {
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 15 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class FileCopyController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source instanceof FileLinkChooserController) {
        if (event == Event.DONE_EVENT || event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        } else if (event instanceof URLChoosenEvent) {
            URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
            String url = choosenEvent.getURL();
            if (url.indexOf("://") < 0) {
                VFSContainer cContainer = folderComponent.getExternContainerForCopy();
                VFSItem item = cContainer.resolve(url);
                if (item instanceof VFSLeaf) {
                    sourceLeaf = (VFSLeaf) item;
                    String filename = sourceLeaf.getName();
                    VFSContainer tContainer = folderComponent.getCurrentContainer();
                    newFile = tContainer.createChildLeaf(filename);
                    if (newFile == null) {
                        existingVFSItem = (VFSLeaf) tContainer.resolve(filename);
                        fileAlreadyExists(ureq);
                    } else {
                        finishUpload(ureq);
                    }
                } else {
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                }
            } else {
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            }
        }
    } else if (source == overwriteDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            if (buttonClickedEvent.getPosition() == 0) {
                // ok
                if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
                    // new version
                    String relPath = null;
                    if (existingVFSItem instanceof OlatRootFileImpl) {
                        relPath = ((OlatRootFileImpl) existingVFSItem).getRelPath();
                    }
                    int maxNumOfRevisions = FolderConfig.versionsAllowed(relPath);
                    if (maxNumOfRevisions == 0) {
                        // someone play with the configuration
                        // Overwrite...
                        String fileName = existingVFSItem.getName();
                        existingVFSItem.delete();
                        newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
                        // ... and notify listeners.
                        finishUpload(ureq);
                    } else {
                        removeAsListenerAndDispose(commentVersionCtr);
                        boolean locked = vfsLockManager.isLocked(existingVFSItem);
                        commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
                        listenTo(commentVersionCtr);
                        removeAsListenerAndDispose(commentVersionDialogBox);
                        commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
                        listenTo(commentVersionDialogBox);
                        commentVersionDialogBox.activate();
                    }
                } else {
                    // if the file is locked, ask for unlocking it
                    if (vfsLockManager.isLocked(existingVFSItem)) {
                        removeAsListenerAndDispose(unlockCtr);
                        unlockCtr = new VersionCommentController(ureq, getWindowControl(), true, false);
                        listenTo(unlockCtr);
                        removeAsListenerAndDispose(unlockDialogBox);
                        unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
                        listenTo(unlockDialogBox);
                        unlockDialogBox.activate();
                    } else {
                        // Overwrite...
                        String fileName = existingVFSItem.getName();
                        existingVFSItem.delete();
                        newFile = folderComponent.getCurrentContainer().createChildLeaf(fileName);
                        // ... and notify listeners.
                        finishUpload(ureq);
                    }
                }
            } else if (buttonClickedEvent.getPosition() == 1) {
                // not ok
                // make newFile with the proposition of filename
                newFile = folderComponent.getCurrentContainer().createChildLeaf(renamedFilename);
                // ... and notify listeners.
                finishUpload(ureq);
            } else if (buttonClickedEvent.getPosition() == 2) {
            // cancel
            // cancel -> do nothing
            } else {
                throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
            }
        }
    } else if (source == lockedFileDialog) {
        if (event instanceof ButtonClickedEvent) {
            ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
            switch(buttonClickedEvent.getPosition()) {
                case 0:
                    {
                        // ... and notify listeners.
                        newFile = existingVFSItem;
                        finishUpload(ureq);
                        break;
                    }
                case 1:
                    {
                        // cancel
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                        break;
                    }
                default:
                    throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
            }
        }
    } else if (source == commentVersionCtr) {
        String comment = commentVersionCtr.getComment();
        Roles roles = ureq.getUserSession().getRoles();
        boolean locked = vfsLockManager.isLocked(existingVFSItem);
        if (locked && !commentVersionCtr.keepLocked()) {
            vfsLockManager.unlock(existingVFSItem, getIdentity(), roles);
        }
        commentVersionDialogBox.deactivate();
        if (revisionListDialogBox != null) {
            revisionListDialogBox.deactivate();
        }
        // ok, new version of the file
        Versionable existingVersionableItem = (Versionable) existingVFSItem;
        boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), comment, sourceLeaf.getInputStream());
        if (ok) {
            newFile = existingVFSItem;
        }
        finishSuccessfullUpload(existingVFSItem.getName(), ureq);
    } else if (source == unlockCtr) {
        // Overwrite...
        if (!unlockCtr.keepLocked()) {
            vfsLockManager.unlock(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
        }
        unlockDialogBox.deactivate();
        newFile = existingVFSItem;
        // ... and notify listeners.
        finishSuccessfullUpload(existingVFSItem.getName(), ureq);
    } else if (source == revisionListCtr) {
        if (FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
            revisionListDialogBox.deactivate();
            // don't want to delete revisions
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        } else {
            if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
                revisionListDialogBox.deactivate();
                Versionable versionable = (Versionable) existingVFSItem;
                Versions versions = versionable.getVersions();
                int maxNumOfRevisions = FolderConfig.versionsAllowed(null);
                if (maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
                    removeAsListenerAndDispose(commentVersionCtr);
                    boolean locked = vfsLockManager.isLocked(existingVFSItem);
                    commentVersionCtr = new VersionCommentController(ureq, getWindowControl(), locked, true);
                    listenTo(commentVersionCtr);
                    removeAsListenerAndDispose(commentVersionDialogBox);
                    commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
                    listenTo(commentVersionDialogBox);
                    commentVersionDialogBox.activate();
                } else {
                    removeAsListenerAndDispose(revisionListCtr);
                    revisionListCtr = new RevisionListController(ureq, getWindowControl(), versionable, false);
                    listenTo(revisionListCtr);
                    removeAsListenerAndDispose(revisionListDialogBox);
                    revisionListDialogBox = new CloseableModalController(getWindowControl(), translate("delete"), revisionListCtr.getInitialComponent());
                    listenTo(revisionListDialogBox);
                    revisionListDialogBox.activate();
                }
            }
        }
    }
}
Also used : ButtonClickedEvent(org.olat.core.gui.control.generic.modal.ButtonClickedEvent) FileLinkChooserController(org.olat.core.commons.controllers.linkchooser.FileLinkChooserController) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Roles(org.olat.core.id.Roles) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) RevisionListController(org.olat.core.commons.modules.bc.version.RevisionListController) Versionable(org.olat.core.util.vfs.version.Versionable) VersionCommentController(org.olat.core.commons.modules.bc.version.VersionCommentController) Versions(org.olat.core.util.vfs.version.Versions) URLChoosenEvent(org.olat.core.commons.controllers.linkchooser.URLChoosenEvent)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20