Search in sources :

Example 1 with OlatRelPathImpl

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

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

the class MetaInfoFormController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (isSubform) {
        setFormTitle("mf.metadata.title");
    }
    setFormContextHelp("Folders#_metadata");
    MetaInfo meta = item instanceof OlatRelPathImpl ? metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item) : null;
    // title
    String titleVal = (meta != null ? meta.getTitle() : null);
    title = uifactory.addTextElement("title", "mf.title", -1, titleVal, formLayout);
    // filename
    initialFilename = (item == null ? null : item.getName());
    filename = uifactory.addTextElement("filename", "mf.filename", -1, initialFilename, formLayout);
    filename.setEnabled(item == null || item.canRename() == VFSConstants.YES);
    filename.setNotEmptyCheck("mf.error.empty");
    filename.setMandatory(true);
    // comment/description
    String commentVal = (meta != null ? meta.getComment() : null);
    comment = uifactory.addTextAreaElement("comment", "mf.comment", -1, 3, 1, true, commentVal, formLayout);
    // license
    if (licenseModule.isEnabled(licenseHandler)) {
        License license = metaInfoFactory.getOrCreateLicense(meta, getIdentity());
        LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
        licenseEl = uifactory.addDropdownSingleselect("mf.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
        licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
        if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
            licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
        }
        licenseEl.addActionListener(FormEvent.ONCHANGE);
        licensorEl = uifactory.addTextElement("mf.licensor", 1000, license.getLicensor(), formLayout);
        String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
        licenseFreetextEl = uifactory.addTextAreaElement("mf.freetext", 4, 72, freetext, formLayout);
        LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
    }
    // creator
    String creatorVal = (meta != null ? meta.getCreator() : null);
    creator = uifactory.addTextElement("creator", "mf.creator", -1, creatorVal, formLayout);
    // publisher
    String publisherVal = (meta != null ? meta.getPublisher() : null);
    publisher = uifactory.addTextElement("publisher", "mf.publisher", -1, publisherVal, formLayout);
    // source/origin
    String sourceVal = (meta != null ? meta.getSource() : null);
    sourceEl = uifactory.addTextElement("source", "mf.source", -1, sourceVal, formLayout);
    // city
    String cityVal = (meta != null ? meta.getCity() : null);
    city = uifactory.addTextElement("city", "mf.city", -1, cityVal, formLayout);
    // publish date
    String datePage = velocity_root + "/date.html";
    FormLayoutContainer publicationDate = FormLayoutContainer.createCustomFormLayout("publicationDateLayout", getTranslator(), datePage);
    publicationDate.setLabel("mf.publishDate", null);
    formLayout.add(publicationDate);
    String[] pubDate = (meta != null ? meta.getPublicationDate() : new String[] { "", "" });
    publicationMonth = uifactory.addTextElement("publicationMonth", "mf.month", 2, StringHelper.escapeHtml(pubDate[1]), publicationDate);
    publicationMonth.setDomReplacementWrapperRequired(false);
    publicationMonth.setMaxLength(2);
    publicationMonth.setDisplaySize(2);
    publicationYear = uifactory.addTextElement("publicationYear", "mf.year", 4, StringHelper.escapeHtml(pubDate[0]), publicationDate);
    publicationYear.setDomReplacementWrapperRequired(false);
    publicationYear.setMaxLength(4);
    publicationYear.setDisplaySize(4);
    // number of pages
    String pageVal = (meta != null ? meta.getPages() : null);
    pages = uifactory.addTextElement("pages", "mf.pages", -1, pageVal, formLayout);
    // language
    String langVal = (meta != null ? meta.getLanguage() : null);
    language = uifactory.addTextElement("language", "mf.language", -1, langVal, formLayout);
    // url/link
    String urlVal = (meta != null ? meta.getUrl() : null);
    url = uifactory.addTextElement("url", "mf.url", -1, urlVal, formLayout);
    /* static fields */
    String sizeText, typeText;
    if (item instanceof VFSLeaf) {
        sizeText = Formatter.formatBytes(((VFSLeaf) item).getSize());
        typeText = FolderHelper.extractFileType(item.getName(), getLocale());
    } else {
        sizeText = "-";
        typeText = translate("mf.type.directory");
    }
    // Targets to hide
    metaFields = new HashSet<>();
    metaFields.add(creator);
    metaFields.add(publisher);
    metaFields.add(sourceEl);
    metaFields.add(city);
    metaFields.add(publicationDate);
    metaFields.add(pages);
    metaFields.add(language);
    metaFields.add(url);
    if (!hasMetadata(meta)) {
        moreMetaDataLink = uifactory.addFormLink("mf.more.meta.link", formLayout, Link.LINK_CUSTOM_CSS);
        setMetaFieldsVisible(false);
    }
    if (!isSubform) {
        if (meta != null && !meta.isDirectory()) {
            LockInfo lock = vfsLockManager.getLock(item);
            // locked
            String lockedTitle = getTranslator().translate("mf.locked");
            String unlockedTitle = getTranslator().translate("mf.unlocked");
            locked = uifactory.addRadiosHorizontal("locked", "mf.locked", formLayout, new String[] { "lock", "unlock" }, new String[] { lockedTitle, unlockedTitle });
            locked.setHelpText(getTranslator().translate("mf.locked.help"));
            if (vfsLockManager.isLocked(item)) {
                locked.select("lock", true);
            } else {
                locked.select("unlock", true);
            }
            boolean lockForMe = vfsLockManager.isLockedForMe(item, getIdentity(), roles);
            locked.setEnabled(!lockForMe);
            // locked by
            String lockedDetails = "";
            if (lock != null) {
                String user = userManager.getUserDisplayName(lock.getLockedBy());
                user = StringHelper.escapeHtml(user);
                String date = "";
                if (lock.getCreationDate() != null) {
                    date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()).format(lock.getCreationDate());
                }
                lockedDetails = getTranslator().translate("mf.locked.description", new String[] { user, date });
            } else {
                lockedDetails = getTranslator().translate("mf.unlocked.description");
            }
            uifactory.addStaticTextElement("mf.lockedBy", lockedDetails, formLayout);
        }
        // username
        String author = StringHelper.escapeHtml(meta == null ? "" : meta.getHTMLFormattedAuthor());
        uifactory.addStaticTextElement("mf.author", author, formLayout);
        // filesize
        uifactory.addStaticTextElement("mf.size", StringHelper.escapeHtml(sizeText), formLayout);
        // last modified date
        String lastModified = meta == null ? "" : StringHelper.formatLocaleDate(meta.getLastModified(), getLocale());
        uifactory.addStaticTextElement("mf.lastModified", lastModified, formLayout);
        // file type
        uifactory.addStaticTextElement("mf.type", StringHelper.escapeHtml(typeText), formLayout);
        String downloads = meta == null ? "" : String.valueOf(meta.getDownloadCount());
        uifactory.addStaticTextElement("mf.downloads", downloads, formLayout);
    }
    boolean xssErrors = false;
    if (item != null) {
        xssErrors = StringHelper.xssScanForErrors(item.getName());
    }
    if (StringHelper.containsNonWhitespace(resourceUrl) && !xssErrors) {
        String externalUrlPage = velocity_root + "/external_url.html";
        FormLayoutContainer extUrlCont = FormLayoutContainer.createCustomFormLayout("external.url", getTranslator(), externalUrlPage);
        extUrlCont.setLabel("external.url", null);
        extUrlCont.contextPut("resourceUrl", resourceUrl);
        extUrlCont.setRootForm(mainForm);
        formLayout.add(extUrlCont);
    }
    if (!isSubform && meta != null && meta.isDirectory()) {
        // Don't show any meta data except title and comment if the item is
        // a directory.
        // Hide the metadata.
        setMetaFieldsVisible(false);
        if (moreMetaDataLink != null)
            moreMetaDataLink.setVisible(false);
    }
    // save and cancel buttons
    if (!isSubform) {
        final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
        formLayout.add(buttonLayout);
        if (meta != null) {
            uifactory.addFormSubmitButton("submit", buttonLayout);
        }
        uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) LicenseSelectionConfig(org.olat.core.commons.services.license.ui.LicenseSelectionConfig) License(org.olat.core.commons.services.license.License) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) LockInfo(org.olat.core.util.vfs.lock.LockInfo)

Example 3 with OlatRelPathImpl

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

the class OlatRootFolderTreeModel method makeChildren.

/**
 * Add children to the node
 *
 * @param node
 * @param root
 */
protected void makeChildren(OlatRootFolderTreeNode node, OlatRootFolderImpl root) {
    List<VFSItem> children = root.getItems(filter);
    if (comparator != null) {
        Collections.sort(children, comparator);
    }
    for (VFSItem child : children) {
        // create a node for each child and add it
        if (child instanceof OlatRelPathImpl) {
            OlatRootFolderTreeNode childNode = createNode((OlatRelPathImpl) child);
            node.addChild(childNode);
            if (child instanceof OlatRootFolderImpl) {
                // add the child's children recursively
                makeChildren(childNode, (OlatRootFolderImpl) child);
            }
        }
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 4 with OlatRelPathImpl

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

the class CmdMoveCopy method doMove.

private void doMove(UserRequest ureq) {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    if (selectedPath == null) {
        abortFailed(ureq, "failed");
        return;
    }
    VFSStatus vfsStatus = VFSConstants.SUCCESS;
    VFSContainer rootContainer = folderComponent.getRootContainer();
    VFSItem vfsItem = rootContainer.resolve(selectedPath);
    if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
        abortFailed(ureq, "failed");
        return;
    }
    // copy the files
    VFSContainer target = (VFSContainer) vfsItem;
    List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
    if (sources == null)
        return;
    boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
    for (VFSItem vfsSource : sources) {
        if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
            // copy the metainfo first
            MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
            if (meta != null) {
                meta.moveCopyToDir((OlatRelPathImpl) target, move);
            }
        }
        VFSItem targetFile = target.resolve(vfsSource.getName());
        if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
            // add a new version to the file
            ((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
        } else {
            vfsStatus = target.copyFrom(vfsSource);
        }
        if (vfsStatus != VFSConstants.SUCCESS) {
            String errorKey = "failed";
            if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
                errorKey = "QuotaExceeded";
            abortFailed(ureq, errorKey);
            return;
        }
        if (move) {
            // if move, delete the source. Note that meta source
            // has already been delete (i.e. moved)
            vfsSource.delete();
        }
    }
    // after a copy or a move, notify the subscribers
    VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (secCallback != null) {
        SubscriptionContext subsContext = secCallback.getSubscriptionContext();
        if (subsContext != null) {
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        }
    }
    fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
    notifyFinished(ureq);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) 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) VFSItem(org.olat.core.util.vfs.VFSItem) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 5 with OlatRelPathImpl

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

the class OlatRootFolderTreeModel method makeChildren.

/**
 * Add children to the node
 *
 * @param node
 * @param root
 */
protected void makeChildren(OlatRootFolderTreeNode node, OlatRootFolderImpl root) {
    List<VFSItem> children = root.getItems(filter);
    if (comparator != null) {
        Collections.sort(children, comparator);
    }
    for (VFSItem child : children) {
        // create a node for each child and add it
        if (child instanceof OlatRelPathImpl) {
            OlatRootFolderTreeNode childNode = createNode((OlatRelPathImpl) child);
            node.addChild(childNode);
            if (child instanceof OlatRootFolderImpl) {
                // add the child's children recursively
                makeChildren(childNode, (OlatRootFolderImpl) child);
            }
        }
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)10 VFSItem (org.olat.core.util.vfs.VFSItem)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)4 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)4 License (org.olat.core.commons.services.license.License)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 LockInfo (org.olat.core.util.vfs.lock.LockInfo)4 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 LicenseSelectionConfig (org.olat.core.commons.services.license.ui.LicenseSelectionConfig)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 FolderTreeModel (org.olat.core.gui.control.generic.folder.FolderTreeModel)2 VFSStatus (org.olat.core.util.vfs.VFSStatus)2 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)2 Versionable (org.olat.core.util.vfs.version.Versionable)2