Search in sources :

Example 1 with ContainerAndFile

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

the class CmdCreateFile method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the file
    fileName = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildLeaf(fileName);
    if (item == null) {
        status = FolderCommandStatus.STATUS_FAILED;
        notifyFinished(ureq);
    } else {
        if (item instanceof MetaTagged) {
            MetaInfo meta = ((MetaTagged) item).getMetaInfo();
            meta.setAuthor(ureq.getIdentity());
            if (licenseModule.isEnabled(licenseHandler)) {
                License license = licenseService.createDefaultLicense(licenseHandler, getIdentity());
                meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
                meta.setLicenseTypeName(license.getLicenseType().getName());
                meta.setLicensor(license.getLicensor());
                meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
            }
            meta.write();
        }
        // start HTML editor with the folders root folder as base and the file
        // path as a relative path from the root directory. But first check if the
        // root directory is wirtable at all (e.g. not the case in users personal
        // briefcase), and seach for the next higher directory that is writable.
        String relFilePath = "/" + fileName;
        // add current container path if not at root level
        if (!folderComponent.getCurrentContainerPath().equals("/")) {
            relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
        }
        VFSContainer writableRootContainer = folderComponent.getRootContainer();
        ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
        if (result != null) {
            writableRootContainer = result.getContainer();
            relFilePath = result.getFileName();
        } else {
            // use fallback that always work: current directory and current file
            relFilePath = fileName;
            writableRootContainer = folderComponent.getCurrentContainer();
        }
        if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
            editorCtr = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
            ((HTMLEditorController) editorCtr).setNewFile(true);
        } else {
            editorCtr = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) writableRootContainer.resolve(relFilePath), "utf-8", true, true, null);
        }
        listenTo(editorCtr);
        initialPanel.setContent(editorCtr.getInitialComponent());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) License(org.olat.core.commons.services.license.License) VFSItem(org.olat.core.util.vfs.VFSItem) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 2 with ContainerAndFile

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

the class CmdEditContent method execute.

/**
 * @see org.olat.modules.bc.commands.FolderCommand#execute(org.olat.modules.bc.components.FolderComponent, org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl, org.olat.core.gui.translator.Translator)
 */
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    this.folderComponent = folderComponent;
    String pos = ureq.getParameter(ListRenderer.PARAM_CONTENTEDITID);
    if (!StringHelper.containsNonWhitespace(pos)) {
        // somehow parameter did not make it to us
        status = FolderCommandStatus.STATUS_FAILED;
        getWindowControl().setError(translator.translate("failed"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_SUCCESS) {
        currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
        status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
    }
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    // do fileEditSanityCheck
    // OO-57
    status = FolderCommandHelper.fileEditSanityCheck(currentItem);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        // this should no longer happen, since folderComponent -> ListRenderer does not display edit-link for folders
        logWarn("Given VFSItem is not a file, can't edit it: " + folderComponent.getCurrentContainerPath() + "/" + currentItem.getName(), null);
        getWindowControl().setError(translator.translate("FileEditFailed"));
        return null;
    }
    if (vfsLockManager.isLockedForMe(currentItem, ureq.getIdentity(), ureq.getUserSession().getRoles())) {
        List<String> lockedFiles = Collections.singletonList(currentItem.getName());
        String msg = FolderCommandHelper.renderLockedMessageAsHtml(translator, lockedFiles);
        List<String> buttonLabels = Collections.singletonList(translator.translate("ok"));
        lockedFiledCtr = activateGenericDialog(ureq, translator.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
        return null;
    }
    // start HTML editor with the folders root folder as base and the file
    // path as a relative path from the root directory. But first check if the
    // root directory is wirtable at all (e.g. not the case in users personal
    // briefcase), and seach for the next higher directory that is writable.
    String relFilePath = "/" + currentItem.getName();
    // add current container path if not at root level
    if (!folderComponent.getCurrentContainerPath().equals("/")) {
        relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
    }
    VFSContainer writableRootContainer = folderComponent.getRootContainer();
    ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
    if (result != null) {
        if (currentItem.getParentContainer() != null) {
            writableRootContainer = currentItem.getParentContainer();
            relFilePath = currentItem.getName();
        } else {
            writableRootContainer = result.getContainer();
        }
    } else {
        // use fallback that always work: current directory and current file
        relFilePath = currentItem.getName();
        writableRootContainer = folderComponent.getCurrentContainer();
    }
    // launch plaintext or html editor depending on file type
    if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
        CustomLinkTreeModel customLinkTreeModel = folderComponent.getCustomLinkTreeModel();
        if (customLinkTreeModel != null) {
            editorc = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), writableRootContainer, relFilePath, true, customLinkTreeModel);
            ((HTMLEditorController) editorc).setNewFile(false);
        } else {
            editorc = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
            ((HTMLEditorController) editorc).setNewFile(false);
        }
    } else {
        editorc = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) currentItem, "utf-8", true, false, null);
    }
    listenTo(editorc);
    putInitialPanel(editorc.getInitialComponent());
    return this;
}
Also used : CustomLinkTreeModel(org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 3 with ContainerAndFile

use of org.olat.core.util.vfs.util.ContainerAndFile in project openolat by klemens.

the class CmdEditContent method execute.

/**
 * @see org.olat.modules.bc.commands.FolderCommand#execute(org.olat.modules.bc.components.FolderComponent, org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl, org.olat.core.gui.translator.Translator)
 */
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    this.folderComponent = folderComponent;
    String pos = ureq.getParameter(ListRenderer.PARAM_CONTENTEDITID);
    if (!StringHelper.containsNonWhitespace(pos)) {
        // somehow parameter did not make it to us
        status = FolderCommandStatus.STATUS_FAILED;
        getWindowControl().setError(translator.translate("failed"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_SUCCESS) {
        currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
        status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
    }
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    // do fileEditSanityCheck
    // OO-57
    status = FolderCommandHelper.fileEditSanityCheck(currentItem);
    if (status == FolderCommandStatus.STATUS_FAILED) {
        // this should no longer happen, since folderComponent -> ListRenderer does not display edit-link for folders
        logWarn("Given VFSItem is not a file, can't edit it: " + folderComponent.getCurrentContainerPath() + "/" + currentItem.getName(), null);
        getWindowControl().setError(translator.translate("FileEditFailed"));
        return null;
    }
    if (vfsLockManager.isLockedForMe(currentItem, ureq.getIdentity(), ureq.getUserSession().getRoles())) {
        List<String> lockedFiles = Collections.singletonList(currentItem.getName());
        String msg = FolderCommandHelper.renderLockedMessageAsHtml(translator, lockedFiles);
        List<String> buttonLabels = Collections.singletonList(translator.translate("ok"));
        lockedFiledCtr = activateGenericDialog(ureq, translator.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
        return null;
    }
    // start HTML editor with the folders root folder as base and the file
    // path as a relative path from the root directory. But first check if the
    // root directory is wirtable at all (e.g. not the case in users personal
    // briefcase), and seach for the next higher directory that is writable.
    String relFilePath = "/" + currentItem.getName();
    // add current container path if not at root level
    if (!folderComponent.getCurrentContainerPath().equals("/")) {
        relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
    }
    VFSContainer writableRootContainer = folderComponent.getRootContainer();
    ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
    if (result != null) {
        if (currentItem.getParentContainer() != null) {
            writableRootContainer = currentItem.getParentContainer();
            relFilePath = currentItem.getName();
        } else {
            writableRootContainer = result.getContainer();
        }
    } else {
        // use fallback that always work: current directory and current file
        relFilePath = currentItem.getName();
        writableRootContainer = folderComponent.getCurrentContainer();
    }
    // launch plaintext or html editor depending on file type
    if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
        CustomLinkTreeModel customLinkTreeModel = folderComponent.getCustomLinkTreeModel();
        if (customLinkTreeModel != null) {
            editorc = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), writableRootContainer, relFilePath, true, customLinkTreeModel);
            ((HTMLEditorController) editorc).setNewFile(false);
        } else {
            editorc = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
            ((HTMLEditorController) editorc).setNewFile(false);
        }
    } else {
        editorc = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) currentItem, "utf-8", true, false, null);
    }
    listenTo(editorc);
    putInitialPanel(editorc.getInitialComponent());
    return this;
}
Also used : CustomLinkTreeModel(org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 4 with ContainerAndFile

use of org.olat.core.util.vfs.util.ContainerAndFile in project openolat by klemens.

the class CmdCreateFile method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the file
    fileName = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildLeaf(fileName);
    if (item == null) {
        status = FolderCommandStatus.STATUS_FAILED;
        notifyFinished(ureq);
    } else {
        if (item instanceof MetaTagged) {
            MetaInfo meta = ((MetaTagged) item).getMetaInfo();
            meta.setAuthor(ureq.getIdentity());
            if (licenseModule.isEnabled(licenseHandler)) {
                License license = licenseService.createDefaultLicense(licenseHandler, getIdentity());
                meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
                meta.setLicenseTypeName(license.getLicenseType().getName());
                meta.setLicensor(license.getLicensor());
                meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
            }
            meta.write();
        }
        // start HTML editor with the folders root folder as base and the file
        // path as a relative path from the root directory. But first check if the
        // root directory is wirtable at all (e.g. not the case in users personal
        // briefcase), and seach for the next higher directory that is writable.
        String relFilePath = "/" + fileName;
        // add current container path if not at root level
        if (!folderComponent.getCurrentContainerPath().equals("/")) {
            relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
        }
        VFSContainer writableRootContainer = folderComponent.getRootContainer();
        ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
        if (result != null) {
            writableRootContainer = result.getContainer();
            relFilePath = result.getFileName();
        } else {
            // use fallback that always work: current directory and current file
            relFilePath = fileName;
            writableRootContainer = folderComponent.getCurrentContainer();
        }
        if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
            editorCtr = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
            ((HTMLEditorController) editorCtr).setNewFile(true);
        } else {
            editorCtr = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) writableRootContainer.resolve(relFilePath), "utf-8", true, true, null);
        }
        listenTo(editorCtr);
        initialPanel.setContent(editorCtr.getInitialComponent());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) License(org.olat.core.commons.services.license.License) VFSItem(org.olat.core.util.vfs.VFSItem) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Aggregations

HTMLEditorController (org.olat.core.commons.editor.htmleditor.HTMLEditorController)4 PlainTextEditorController (org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 ContainerAndFile (org.olat.core.util.vfs.util.ContainerAndFile)4 CustomLinkTreeModel (org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 License (org.olat.core.commons.services.license.License)2 VFSItem (org.olat.core.util.vfs.VFSItem)2