Search in sources :

Example 31 with License

use of org.olat.core.commons.services.license.License in project openolat by klemens.

the class MetaInfoController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("mf.metadata.title");
    setFormContextHelp("Folders#_metadata");
    // filename
    uifactory.addStaticTextElement("mf.filename", item.getName(), formLayout);
    MetaInfo meta = item == null ? null : CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor((OlatRelPathImpl) item);
    // title
    String titleVal = StringHelper.escapeHtml(meta != null ? meta.getTitle() : null);
    uifactory.addStaticTextElement("mf.title", titleVal, formLayout);
    // comment/description
    String commentVal = StringHelper.xssScan(meta != null ? meta.getComment() : null);
    uifactory.addStaticTextElement("mf.comment", commentVal, formLayout);
    // license
    if (licenseModule.isEnabled(licenseHandler)) {
        MetaInfoFactory metaInfoFactory = CoreSpringFactory.getImpl(MetaInfoFactory.class);
        License license = metaInfoFactory.getOrCreateLicense(meta, getIdentity());
        boolean isNoLicense = !licenseService.isNoLicense(license.getLicenseType());
        boolean isFreetext = licenseService.isFreetext(license.getLicenseType());
        licenseEl = uifactory.addStaticTextElement("mf.license", LicenseUIFactory.translate(license.getLicenseType(), getLocale()), formLayout);
        if (isNoLicense) {
            licensorEl = uifactory.addStaticTextElement("mf.licensor", license.getLicensor(), formLayout);
        }
        if (isFreetext) {
            licenseFreetextEl = uifactory.addStaticTextElement("mf.freetext", LicenseUIFactory.getFormattedLicenseText(license), formLayout);
        }
        ;
        // creator
        String creatorVal = StringHelper.escapeHtml(meta != null ? meta.getCreator() : null);
        creator = uifactory.addStaticTextElement("mf.creator", creatorVal, formLayout);
        // publisher
        String publisherVal = StringHelper.escapeHtml(meta != null ? meta.getPublisher() : null);
        publisher = uifactory.addStaticTextElement("mf.publisher", publisherVal, formLayout);
        // source/origin
        String sourceVal = StringHelper.escapeHtml(meta != null ? meta.getSource() : null);
        sourceEl = uifactory.addStaticTextElement("mf.source", sourceVal, formLayout);
        // city
        String cityVal = StringHelper.escapeHtml(meta != null ? meta.getCity() : null);
        city = uifactory.addStaticTextElement("mf.city", cityVal, formLayout);
        String[] pubDate = (meta != null ? meta.getPublicationDate() : new String[] { "", "" });
        String publicationDate = new StringBuilder().append(translate("mf.month")).append(pubDate[0]).append(", ").append(translate("mf.year")).append(pubDate[1]).toString();
        publicationDateEl = uifactory.addStaticTextElement("mf.publishDate", publicationDate, formLayout);
        // number of pages
        String pageVal = StringHelper.escapeHtml(meta != null ? meta.getPages() : null);
        pages = uifactory.addStaticTextElement("mf.pages", pageVal, formLayout);
        // language
        String langVal = StringHelper.escapeHtml(meta != null ? meta.getLanguage() : null);
        language = uifactory.addStaticTextElement("mf.language", langVal, formLayout);
        // url/link
        String urlVal = StringHelper.escapeHtml(meta != null ? meta.getUrl() : null);
        url = uifactory.addStaticTextElement("mf.url", 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(publicationDateEl);
    metaFields.add(pages);
    metaFields.add(language);
    metaFields.add(url);
    if (licenseEl != null) {
        metaFields.add(licenseEl);
    }
    if (licensorEl != null) {
        metaFields.add(licensorEl);
    }
    if (licenseFreetextEl != null) {
        metaFields.add(licenseFreetextEl);
    }
    if (!hasMetadata(meta)) {
        moreMetaDataLink = uifactory.addFormLink("mf.more.meta.link", formLayout, Link.LINK_CUSTOM_CSS);
        setMetaFieldsVisible(false);
    }
    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 });
        if (vfsLockManager.isLocked(item)) {
            locked.select("lock", true);
        } else {
            locked.select("unlock", true);
        }
        locked.setEnabled(false);
        // 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 });
            if (lock.isWebDAVLock()) {
                lockedDetails += " (WebDAV)";
            }
        } else {
            lockedDetails = getTranslator().translate("mf.unlocked.description");
        }
        uifactory.addStaticTextElement("mf.lockedBy", lockedDetails, formLayout);
        // username
        String author = StringHelper.escapeHtml(meta.getHTMLFormattedAuthor());
        uifactory.addStaticTextElement("mf.author", author, formLayout);
        // filesize
        uifactory.addStaticTextElement("mf.size", StringHelper.escapeHtml(sizeText), formLayout);
        // last modified date
        String lastModified = StringHelper.formatLocaleDate(meta.getLastModified(), getLocale());
        uifactory.addStaticTextElement("mf.lastModified", lastModified, formLayout);
        // file type
        uifactory.addStaticTextElement("mf.type", StringHelper.escapeHtml(typeText), formLayout);
        String downloads = String.valueOf(meta.getDownloadCount());
        uifactory.addStaticTextElement("mf.downloads", downloads, formLayout);
    } else {
        setMetaFieldsVisible(false);
        if (moreMetaDataLink != null) {
            moreMetaDataLink.setVisible(false);
        }
    }
    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);
    }
    // cancel buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) 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 32 with License

use of org.olat.core.commons.services.license.License in project openolat by klemens.

the class MetaInfoFactory method getOrCreateLicense.

/**
 * Get the license of the MetaInfo or create a new default license:
 *
 * @param meta
 * @param itentity the current user
 * @return
 */
public License getOrCreateLicense(MetaInfo meta, Identity itentity) {
    LicenseHandler licenseHandler = CoreSpringFactory.getImpl(FolderLicenseHandler.class);
    LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
    License license = getLicense(meta);
    if (license == null) {
        license = licenseService.createDefaultLicense(licenseHandler, itentity);
    }
    return license;
}
Also used : FolderLicenseHandler(org.olat.core.commons.modules.bc.FolderLicenseHandler) LicenseHandler(org.olat.core.commons.services.license.LicenseHandler) LicenseService(org.olat.core.commons.services.license.LicenseService) License(org.olat.core.commons.services.license.License)

Example 33 with License

use of org.olat.core.commons.services.license.License in project openolat by klemens.

the class MetaInfoFormController method getMetaInfo.

public MetaInfo getMetaInfo(MetaInfo meta) {
    meta.setCreator(creator.getValue());
    meta.setComment(comment.getValue());
    meta.setTitle(title.getValue());
    meta.setPublisher(publisher.getValue());
    meta.setPublicationDate(publicationMonth.getValue(), publicationYear.getValue());
    meta.setCity(city.getValue());
    meta.setLanguage(language.getValue());
    meta.setSource(sourceEl.getValue());
    meta.setUrl(url.getValue());
    meta.setPages(pages.getValue());
    License license = getLicenseFromFormItems();
    meta.setLicenseTypeKey(license.getLicenseType() != null ? String.valueOf(license.getLicenseType().getKey()) : "");
    meta.setLicenseTypeName(license.getLicenseType() != null ? license.getLicenseType().getName() : "");
    meta.setLicensor(license.getLicensor() != null ? license.getLicensor() : "");
    meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
    return meta;
}
Also used : License(org.olat.core.commons.services.license.License)

Example 34 with License

use of org.olat.core.commons.services.license.License in project openolat by klemens.

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 35 with License

use of org.olat.core.commons.services.license.License in project openolat by klemens.

the class MetaInfoFormController method getLicenseFromFormItems.

private License getLicenseFromFormItems() {
    License license = licenseService.createLicense(null);
    String licensor = "";
    String freetext = "";
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        if (licensorEl != null && licensorEl.isVisible() && StringHelper.containsNonWhitespace(licensorEl.getValue())) {
            licensor = licensorEl.getValue();
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible() && StringHelper.containsNonWhitespace(licenseFreetextEl.getValue())) {
            freetext = licenseFreetextEl.getValue();
        }
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    license.setLicensor(licensor);
    license.setFreetext(freetext);
    return license;
}
Also used : License(org.olat.core.commons.services.license.License) LicenseType(org.olat.core.commons.services.license.LicenseType)

Aggregations

License (org.olat.core.commons.services.license.License)38 LicenseType (org.olat.core.commons.services.license.LicenseType)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 Test (org.junit.Test)8 Date (java.util.Date)6 LicenseService (org.olat.core.commons.services.license.LicenseService)6 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)6 LicenseImpl (org.olat.core.commons.services.license.model.LicenseImpl)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 LockInfo (org.olat.core.util.vfs.lock.LockInfo)6 File (java.io.File)4 FolderLicenseHandler (org.olat.core.commons.modules.bc.FolderLicenseHandler)4 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)4 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 GroupRoles (org.olat.basesecurity.GroupRoles)2