Search in sources :

Example 6 with FileSelection

use of org.olat.core.commons.modules.bc.FileSelection in project openolat by klemens.

the class CmdMoveCopy method execute.

@Override
public Controller execute(FolderComponent fc, UserRequest ureq, WindowControl windowControl, Translator trans) {
    this.folderComponent = fc;
    this.translator = trans;
    this.fileSelection = new FileSelection(ureq, fc.getCurrentContainerPath());
    VelocityContainer main = new VelocityContainer("mc", VELOCITY_ROOT + "/movecopy.html", translator, this);
    main.contextPut("fileselection", fileSelection);
    // check if command is executed on a file list containing invalid filenames or paths
    if (fileSelection.getInvalidFileNames().size() > 0) {
        main.contextPut("invalidFileNames", fileSelection.getInvalidFileNames());
    }
    selTree = new MenuTree(null, "seltree", this);
    FolderTreeModel ftm = new FolderTreeModel(ureq.getLocale(), fc.getRootContainer(), true, false, true, fc.getRootContainer().canWrite() == VFSConstants.YES, new EditableFilter());
    selTree.setTreeModel(ftm);
    selectButton = LinkFactory.createButton(move ? "move" : "copy", main, this);
    cancelButton = LinkFactory.createButton("cancel", main, this);
    main.put("seltree", selTree);
    if (move) {
        main.contextPut("move", Boolean.TRUE);
    }
    setInitialComponent(main);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) MenuTree(org.olat.core.gui.components.tree.MenuTree) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 7 with FileSelection

use of org.olat.core.commons.modules.bc.FileSelection in project openolat by klemens.

the class CmdZip method execute.

@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator trans) {
    setTranslator(trans);
    currentContainer = folderComponent.getCurrentContainer();
    if (currentContainer.canWrite() != VFSConstants.YES) {
        throw new AssertException("Cannot write to current folder.");
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    initForm(ureq);
    mainVC = createVelocityContainer("createZipPanel");
    mainVC.contextPut("fileselection", selection);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) AssertException(org.olat.core.logging.AssertException)

Example 8 with FileSelection

use of org.olat.core.commons.modules.bc.FileSelection in project openolat by klemens.

the class SendDocumentsByEMailController method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSContainer rootContainer = folderComponent.getRootContainer();
    if (!VFSManager.exists(currentContainer)) {
        status = FolderCommandStatus.STATUS_FAILED;
        showError(translator.translate("FileDoesNotExist"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    boolean selectionWithContainer = false;
    List<String> filenames = selection.getFiles();
    List<VFSLeaf> leafs = new ArrayList<VFSLeaf>();
    for (String file : filenames) {
        VFSItem item = currentContainer.resolve(file);
        if (item instanceof VFSContainer) {
            selectionWithContainer = true;
        } else if (item instanceof VFSLeaf) {
            leafs.add((VFSLeaf) item);
        }
    }
    if (selectionWithContainer) {
        if (leafs.isEmpty()) {
            wControl.setError(getTranslator().translate("send.mail.noFileSelected"));
            return null;
        } else {
            setFormWarning(getTranslator().translate("send.mail.selectionContainsFolder"));
        }
    }
    setFiles(rootContainer, leafs);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 9 with FileSelection

use of org.olat.core.commons.modules.bc.FileSelection in project OpenOLAT by OpenOLAT.

the class CmdZip method execute.

@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator trans) {
    setTranslator(trans);
    currentContainer = folderComponent.getCurrentContainer();
    if (currentContainer.canWrite() != VFSConstants.YES) {
        throw new AssertException("Cannot write to current folder.");
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    initForm(ureq);
    mainVC = createVelocityContainer("createZipPanel");
    mainVC.contextPut("fileselection", selection);
    return this;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) AssertException(org.olat.core.logging.AssertException)

Example 10 with FileSelection

use of org.olat.core.commons.modules.bc.FileSelection in project openolat by klemens.

the class CmdUnzip method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wContr, Translator trans) {
    this.translator = trans;
    FileSelection selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    if (!(currentContainer.canWrite() == VFSConstants.YES))
        throw new AssertException("Cannot unzip to folder. Writing denied.");
    // check if command is executed on a file containing invalid filenames or paths - checks if the resulting folder has a valid name
    if (selection.getInvalidFileNames().size() > 0) {
        status = FolderCommandStatus.STATUS_INVALID_NAME;
        return null;
    }
    List<String> lockedFiles = new ArrayList<String>();
    for (String sItem : selection.getFiles()) {
        VFSItem vfsItem = currentContainer.resolve(sItem);
        if (vfsItem instanceof VFSLeaf) {
            try {
                Roles roles = ureq.getUserSession().getRoles();
                lockedFiles.addAll(checkLockedFiles((VFSLeaf) vfsItem, currentContainer, ureq.getIdentity(), roles));
            } catch (Exception e) {
                String name = vfsItem == null ? "NULL" : vfsItem.getName();
                getWindowControl().setError(translator.translate("FileUnzipFailed", new String[] { name }));
            }
        }
    }
    if (!lockedFiles.isEmpty()) {
        String msg = FolderCommandHelper.renderLockedMessageAsHtml(trans, lockedFiles);
        List<String> buttonLabels = Collections.singletonList(trans.translate("ok"));
        lockedFiledCtr = activateGenericDialog(ureq, trans.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
        return null;
    }
    VFSItem currentVfsItem = null;
    try {
        boolean fileNotExist = false;
        for (String sItem : selection.getFiles()) {
            currentVfsItem = currentContainer.resolve(sItem);
            if (currentVfsItem != null && (currentVfsItem instanceof VFSLeaf)) {
                if (!doUnzip((VFSLeaf) currentVfsItem, currentContainer, ureq, wContr)) {
                    status = FolderCommandStatus.STATUS_FAILED;
                    break;
                }
            } else {
                fileNotExist = true;
                break;
            }
        }
        if (fileNotExist) {
            status = FolderCommandStatus.STATUS_FAILED;
            getWindowControl().setError(translator.translate("FileDoesNotExist"));
        }
        VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(folderComponent.getRootContainer());
        if (inheritingCont != null) {
            VFSSecurityCallback secCallback = inheritingCont.getLocalSecurityCallback();
            if (secCallback != null) {
                SubscriptionContext subsContext = secCallback.getSubscriptionContext();
                if (subsContext != null) {
                    NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        logError("Corrupted ZIP", e);
        String name = currentVfsItem == null ? "NULL" : currentVfsItem.getName();
        getWindowControl().setError(translator.translate("FileUnzipFailed", new String[] { name }));
    }
    return null;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) Roles(org.olat.core.id.Roles) AssertException(org.olat.core.logging.AssertException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Aggregations

FileSelection (org.olat.core.commons.modules.bc.FileSelection)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 ArrayList (java.util.ArrayList)4 AssertException (org.olat.core.logging.AssertException)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 MenuTree (org.olat.core.gui.components.tree.MenuTree)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 FolderTreeModel (org.olat.core.gui.control.generic.folder.FolderTreeModel)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Roles (org.olat.core.id.Roles)2 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)2