Search in sources :

Example 11 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 12 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 13 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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)

Example 14 with VFSContainer

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

the class FileCopyController method finishSuccessfullUpload.

private void finishSuccessfullUpload(String fileName, UserRequest ureq) {
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.resolve(fileName);
    if (item instanceof OlatRootFileImpl) {
        OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
        // create meta data
        MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPathItem);
        meta.setAuthor(ureq.getIdentity());
        // if overwrite an older file
        meta.clearThumbnails();
        meta.write();
    }
    ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_COPIED, getClass(), CoreLoggingResourceable.wrapUploadFile(fileName));
    // Notify listeners about upload
    fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, newFile.getName()));
    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 15 with VFSContainer

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

the class FolderComponentRenderer method renderList.

private void renderList(StringOutput target, FolderComponent fc, URLBuilder ubu, Translator translator, boolean iframePostEnabled) {
    VFSContainer currentContainer = fc.getCurrentContainer();
    boolean canWrite = currentContainer.canWrite() == VFSConstants.YES;
    boolean canCreateFolder = true;
    if (currentContainer.getLocalSecurityCallback() != null && !currentContainer.getLocalSecurityCallback().canCreateFolder()) {
        canCreateFolder = false;
    }
    boolean canDelete = false;
    boolean canVersion = FolderConfig.versionsEnabled(fc.getCurrentContainer());
    boolean canMail = fc.isCanMail();
    for (Iterator<VFSItem> iter = fc.getCurrentContainerChildren().iterator(); iter.hasNext(); ) {
        VFSItem child = iter.next();
        if (child.canDelete() == VFSConstants.YES) {
            canDelete = true;
            break;
        }
    }
    String formName = "folder" + CodeHelper.getRAMUniqueID();
    target.append("<form  method=\"post\" id=\"").append(formName).append("\" action=\"");
    ubu.buildURI(target, new String[] { VelocityContainer.COMMAND_ID }, new String[] { FolderRunController.FORM_ACTION }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    target.append("\" ");
    if (iframePostEnabled) {
        // add ajax iframe target
        target.append("\" onsubmit=\"o_XHRSubmit('").append(formName).append("');\">");
        target.append("<input id=\"o_mai_").append(formName).append("\" type=\"hidden\" name=\"multi_action_identifier\" value=\"\"").append(" />");
    } else {
        target.append("\" onsubmit=\"if ( b_briefcase_isChecked('").append(formName).append("', '").append(Formatter.escapeSingleAndDoubleQuotes(StringHelper.escapeHtml(translator.translate("alert")).toString())).append("')) { if(o_info.linkbusy) return false; else o_beforeserver(); return true; } else {return false; }\">");
    }
    target.append("<div class=\"o_bc_createactions clearfix\"><ul class='nav navbar-nav navbar-right'>");
    if (canWrite) {
        if (canVersion) {
            // deleted files
            target.append("<li><a class=\"o_bc_deletedfiles\"");
            ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "dfiles")).append("><i class='o_icon o_icon_recycle o_icon-fw'></i> ").append(translator.translate("dfiles")).append("</a></li>");
        }
        if (canWrite) {
            if (fc.getExternContainerForCopy() != null && (fc.getExternContainerForCopy().getLocalSecurityCallback() == null || fc.getExternContainerForCopy().getLocalSecurityCallback().canCopy())) {
                // option copy file
                target.append("<li><a class=\"o_bc_copy\" ");
                ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "copyfile")).append("><i class='o_icon o_icon_copy o_icon-fw'></i> ").append(translator.translate("copyfile")).append("</a></li>");
            }
            // option upload
            target.append("<li><a class='o_bc_upload' ");
            ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "ul")).append("><i class='o_icon o_icon_upload o_icon-fw'></i> ").append(translator.translate("ul")).append("</a></li>");
            if (canCreateFolder) {
                // option new folder
                target.append("<li><a class=\"b_bc_newfolder\" ");
                ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "cf")).append("><i class='o_icon o_icon_new_folder o_icon-fw'></i> ").append(translator.translate("cf")).append("</a></li>");
            }
            // option new file
            target.append("<li><a class=\"b_bc_newfile\" ");
            ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "cfile")).append("><i class='o_icon o_icon_new_document o_icon-fw'></i> ").append(translator.translate("cfile")).append("</a></li>");
        }
    }
    // placeholder for the search
    target.append("</ul></div>");
    // add current file bread crumb path
    crumbRenderer.render(fc, target, ubu, iframePostEnabled);
    // add file listing for current folder
    target.append("<div class='o_table_wrapper'>");
    listRenderer.render(fc, target, ubu, translator, iframePostEnabled);
    if (fc.getCurrentContainerChildren().size() > 0) {
        target.append("<div class='o_table_footer'>").append("<div class=\"o_table_checkall input-sm\">").append("<label class='checkbox-inline'><a href=\"#\" onclick=\"javascript:b_briefcase_toggleCheck('").append(formName).append("', true)\">").append("<input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\" />").append(translator.translate("checkall")).append("</a></label> <label class='checkbox-inline'><a href=\"#\" onclick=\"javascript:b_briefcase_toggleCheck('").append(formName).append("', false)\">").append("<input type=\"checkbox\" disabled=\"disabled\" />").append(translator.translate("uncheckall")).append("</a></label></div>").append("<div class='o_table_buttons'>");
        if (canMail) {
            target.append("<button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_MAIL).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("send"))).append("</span></button>");
        }
        target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_DOWNLOAD_ZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("download"))).append("</span></button>");
        if (canDelete) {
            // delete
            target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_DEL).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("del"))).append("</span></button>");
        }
        if (canWrite) {
            // move
            target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_MOVE).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("move"))).append("</span></button>");
            // copy
            target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_COPY).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("copy"))).append("</span></button>");
            // zip
            target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_ZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("zip"))).append("</span></button>");
            // unzip
            target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_UNZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("unzip"))).append("</span></button>");
        }
        target.append("</div></div>");
    }
    target.append("</div></form>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34