Search in sources :

Example 1 with VFSItemSuffixFilter

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

the class VersionsFileManager method getDeletedFiles.

@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
    List<Versions> deletedRevisions = new ArrayList<Versions>();
    VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
    if (versionContainer != null) {
        Set<String> currentNames = new HashSet<String>();
        for (VFSItem item : container.getItems(new VFSLeafFilter())) {
            currentNames.add(item.getName() + ".xml");
        }
        List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
        for (VFSItem versionItem : versionItems) {
            String name = versionItem.getName();
            if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
                Versions versions = readVersions(null, (VFSLeaf) versionItem);
                if (versions != null) {
                    List<VFSRevision> revisions = versions.getRevisions();
                    if (!revisions.isEmpty()) {
                        deletedRevisions.add(versions);
                    }
                }
            }
        }
    }
    return deletedRevisions;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter)

Example 2 with VFSItemSuffixFilter

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

the class CourseLayoutGeneratorController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("tab.layout.title");
    List<String> keys = new ArrayList<String>();
    List<String> vals = new ArrayList<String>();
    List<String> csss = new ArrayList<String>();
    String actualCSSSettings = courseConfig.getCssLayoutRef();
    // add a default option
    keys.add(CourseLayoutHelper.CONFIG_KEY_DEFAULT);
    vals.add(translate("course.layout.default"));
    csss.add("");
    // check for old legacy template, only available if yet one set
    if (actualCSSSettings.startsWith("/") && actualCSSSettings.lastIndexOf("/") == 0) {
        keys.add(actualCSSSettings);
        vals.add(translate("course.layout.legacy", actualCSSSettings));
        csss.add("");
    }
    // add css from hidden coursecss-folder
    VFSContainer coursecssCont = (VFSContainer) courseEnvironment.getCourseFolderContainer().resolve(CourseLayoutHelper.COURSEFOLDER_CSS_BASE);
    if (coursecssCont != null) {
        coursecssCont.setDefaultItemFilter(new VFSItemSuffixFilter(new String[] { "css" }));
        List<VFSItem> coursecssStyles = coursecssCont.getItems();
        if (coursecssStyles != null) {
            for (VFSItem vfsItem : coursecssStyles) {
                keys.add(CourseLayoutHelper.COURSEFOLDER_CSS_BASE + "/" + vfsItem.getName());
                vals.add(translate("course.layout.legacy", vfsItem.getName()));
                csss.add("");
            }
        }
    }
    // get the olat-wide templates
    List<VFSItem> templates = CourseLayoutHelper.getCourseThemeTemplates();
    if (templates != null) {
        for (VFSItem vfsItem : templates) {
            if (CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) vfsItem)) {
                keys.add(CourseLayoutHelper.CONFIG_KEY_TEMPLATE + vfsItem.getName());
                String name = translate("course.layout.template", vfsItem.getName());
                vals.add(name);
                csss.add("");
            }
        }
    }
    // get the predefined template for this course if any
    VFSItem predefCont = courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER + "/" + CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
    if (predefCont != null && CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) predefCont)) {
        keys.add(CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
        vals.add(translate("course.layout.predefined"));
        csss.add("");
    }
    // add option for customizing
    keys.add(CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    vals.add(translate("course.layout.custom"));
    csss.add("");
    String[] theKeys = ArrayHelper.toArray(keys);
    String[] theValues = ArrayHelper.toArray(vals);
    String[] theCssClasses = ArrayHelper.toArray(csss);
    styleSel = uifactory.addDropdownSingleselect("course.layout.selector", formLayout, theKeys, theValues, theCssClasses);
    styleSel.addActionListener(FormEvent.ONCHANGE);
    styleSel.setEnabled(editable);
    if (keys.contains(actualCSSSettings)) {
        styleSel.select(actualCSSSettings, true);
    } else {
        styleSel.select(CourseLayoutHelper.CONFIG_KEY_DEFAULT, true);
    }
    previewImgFlc = FormLayoutContainer.createCustomFormLayout("preview.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(previewImgFlc);
    previewImgFlc.setLabel("preview.image.label", null);
    refreshPreviewImage(ureq, actualCSSSettings);
    logoImgFlc = FormLayoutContainer.createCustomFormLayout("logo.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(logoImgFlc);
    logoImgFlc.setLabel("logo.image.label", null);
    refreshLogoImage(ureq);
    // offer upload for 2nd logo
    if (editable) {
        logoUpl = uifactory.addFileElement(getWindowControl(), "upload.second.logo", formLayout);
        logoUpl.addActionListener(FormEvent.ONCHANGE);
        Set<String> mimeTypes = new HashSet<String>();
        mimeTypes.add("image/*");
        logoUpl.limitToMimeType(mimeTypes, "logo.file.type.error", null);
        logoUpl.setMaxUploadSizeKB(2048, "logo.size.error", null);
    }
    // prepare the custom layouter
    styleFlc = FormLayoutContainer.createCustomFormLayout("style", getTranslator(), velocity_root + "/style.html");
    formLayout.add(styleFlc);
    styleFlc.setLabel(null, null);
    enableDisableCustom(CourseLayoutHelper.CONFIG_KEY_CUSTOM.equals(actualCSSSettings));
    if (editable) {
        uifactory.addFormSubmitButton("course.layout.save", formLayout);
    }
}
Also used : VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet)

Example 3 with VFSItemSuffixFilter

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

the class VideoManagerImpl method getAllTracks.

/**
 * get all tracks saved in the video metadata as map
 */
@Override
public Map<String, VFSLeaf> getAllTracks(OLATResource videoResource) {
    Map<String, VFSLeaf> tracks = new HashMap<>();
    VFSContainer vfsContainer = getMasterContainer(videoResource);
    for (VFSItem item : vfsContainer.getItems(new VFSItemSuffixFilter(new String[] { FILETYPE_SRT }))) {
        String itemname = item.getName();
        String key = itemname.substring(itemname.indexOf("_") + 1, itemname.indexOf("."));
        tracks.put(key, resolveFromMasterContainer(videoResource, itemname));
    }
    // }
    return tracks;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) HashMap(java.util.HashMap) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 4 with VFSItemSuffixFilter

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

the class CourseLayoutGeneratorController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("tab.layout.title");
    List<String> keys = new ArrayList<String>();
    List<String> vals = new ArrayList<String>();
    List<String> csss = new ArrayList<String>();
    String actualCSSSettings = courseConfig.getCssLayoutRef();
    // add a default option
    keys.add(CourseLayoutHelper.CONFIG_KEY_DEFAULT);
    vals.add(translate("course.layout.default"));
    csss.add("");
    // check for old legacy template, only available if yet one set
    if (actualCSSSettings.startsWith("/") && actualCSSSettings.lastIndexOf("/") == 0) {
        keys.add(actualCSSSettings);
        vals.add(translate("course.layout.legacy", actualCSSSettings));
        csss.add("");
    }
    // add css from hidden coursecss-folder
    VFSContainer coursecssCont = (VFSContainer) courseEnvironment.getCourseFolderContainer().resolve(CourseLayoutHelper.COURSEFOLDER_CSS_BASE);
    if (coursecssCont != null) {
        coursecssCont.setDefaultItemFilter(new VFSItemSuffixFilter(new String[] { "css" }));
        List<VFSItem> coursecssStyles = coursecssCont.getItems();
        if (coursecssStyles != null) {
            for (VFSItem vfsItem : coursecssStyles) {
                keys.add(CourseLayoutHelper.COURSEFOLDER_CSS_BASE + "/" + vfsItem.getName());
                vals.add(translate("course.layout.legacy", vfsItem.getName()));
                csss.add("");
            }
        }
    }
    // get the olat-wide templates
    List<VFSItem> templates = CourseLayoutHelper.getCourseThemeTemplates();
    if (templates != null) {
        for (VFSItem vfsItem : templates) {
            if (CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) vfsItem)) {
                keys.add(CourseLayoutHelper.CONFIG_KEY_TEMPLATE + vfsItem.getName());
                String name = translate("course.layout.template", vfsItem.getName());
                vals.add(name);
                csss.add("");
            }
        }
    }
    // get the predefined template for this course if any
    VFSItem predefCont = courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER + "/" + CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
    if (predefCont != null && CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) predefCont)) {
        keys.add(CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
        vals.add(translate("course.layout.predefined"));
        csss.add("");
    }
    // add option for customizing
    keys.add(CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    vals.add(translate("course.layout.custom"));
    csss.add("");
    String[] theKeys = ArrayHelper.toArray(keys);
    String[] theValues = ArrayHelper.toArray(vals);
    String[] theCssClasses = ArrayHelper.toArray(csss);
    styleSel = uifactory.addDropdownSingleselect("course.layout.selector", formLayout, theKeys, theValues, theCssClasses);
    styleSel.addActionListener(FormEvent.ONCHANGE);
    styleSel.setEnabled(editable);
    if (keys.contains(actualCSSSettings)) {
        styleSel.select(actualCSSSettings, true);
    } else {
        styleSel.select(CourseLayoutHelper.CONFIG_KEY_DEFAULT, true);
    }
    previewImgFlc = FormLayoutContainer.createCustomFormLayout("preview.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(previewImgFlc);
    previewImgFlc.setLabel("preview.image.label", null);
    refreshPreviewImage(ureq, actualCSSSettings);
    logoImgFlc = FormLayoutContainer.createCustomFormLayout("logo.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(logoImgFlc);
    logoImgFlc.setLabel("logo.image.label", null);
    refreshLogoImage(ureq);
    // offer upload for 2nd logo
    if (editable) {
        logoUpl = uifactory.addFileElement(getWindowControl(), "upload.second.logo", formLayout);
        logoUpl.addActionListener(FormEvent.ONCHANGE);
        Set<String> mimeTypes = new HashSet<String>();
        mimeTypes.add("image/*");
        logoUpl.limitToMimeType(mimeTypes, "logo.file.type.error", null);
        logoUpl.setMaxUploadSizeKB(2048, "logo.size.error", null);
    }
    // prepare the custom layouter
    styleFlc = FormLayoutContainer.createCustomFormLayout("style", getTranslator(), velocity_root + "/style.html");
    formLayout.add(styleFlc);
    styleFlc.setLabel(null, null);
    enableDisableCustom(CourseLayoutHelper.CONFIG_KEY_CUSTOM.equals(actualCSSSettings));
    if (editable) {
        uifactory.addFormSubmitButton("course.layout.save", formLayout);
    }
}
Also used : VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet)

Example 5 with VFSItemSuffixFilter

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

the class WikiManager method getOrLoadWiki.

/**
 * @param ores
 * @return a wiki loaded from cache or the fileSystem
 */
public Wiki getOrLoadWiki(final OLATResourceable ores) {
    final String wikiKey = OresHelper.createStringRepresenting(ores);
    // cluster_OK by guido
    if (wikiCache == null) {
        wikiCache = coordinator.getCoordinator().getCacher().getCache(WikiManager.class.getSimpleName(), "wiki");
    }
    return wikiCache.computeIfAbsent(wikiKey, (key) -> {
        long start = 0;
        // wiki not in cache load form filesystem
        if (log.isDebug()) {
            log.debug("wiki not in cache. Loading wiki from filesystem. Ores: " + ores.getResourceableId());
            start = System.currentTimeMillis();
        }
        VFSContainer folder = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
        // wiki in group context
        if (folder == null) {
            // createWikiforExistingResource(ores);
            createFolders(ores);
            folder = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
        }
        // folders should be present, create the wiki
        Wiki wiki = new Wiki(getWikiRootContainer(ores));
        // filter for xyz.properties files
        List<VFSItem> wikiLeaves = folder.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
        for (Iterator<VFSItem> iter = wikiLeaves.iterator(); iter.hasNext(); ) {
            VFSLeaf propertiesFile = (VFSLeaf) iter.next();
            WikiPage page = Wiki.assignPropertiesToPage(propertiesFile);
            if (page == null) {
                // broken pages get automatically cleaned from filesystem
                String contentFileToBeDeleted = (propertiesFile.getName().substring(0, propertiesFile.getName().length() - WikiManager.WIKI_PROPERTIES_SUFFIX.length()) + WikiManager.WIKI_FILE_SUFFIX);
                folder.resolve(contentFileToBeDeleted).delete();
                propertiesFile.delete();
                continue;
            }
            // index and menu page are loaded by default
            if (page.getPageName().equals(WikiPage.WIKI_INDEX_PAGE) || page.getPageName().equals(WikiPage.WIKI_MENU_PAGE)) {
                VFSLeaf leaf = (VFSLeaf) folder.resolve(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
                page.setContent(FileUtils.load(leaf.getInputStream(), "utf-8"));
            }
            // due to a bug we have to rename some pages that start with an non
            // ASCII lowercase letter
            String idOutOfFileName = propertiesFile.getName().substring(0, propertiesFile.getName().indexOf("."));
            if (!page.matchIds(idOutOfFileName)) {
                // rename corrupt prop file
                propertiesFile.rename(page.getPageId() + "." + WikiManager.WIKI_PROPERTIES_SUFFIX);
                // load content and delete corrupt content file
                VFSLeaf contentFile = (VFSLeaf) folder.resolve(idOutOfFileName + "." + WikiManager.WIKI_FILE_SUFFIX);
                contentFile.rename(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
            }
            wiki.addPage(page);
        }
        // if index and menu page not present create the first page and save it
        if (wiki.getNumberOfPages() == 0) {
            WikiPage indexPage = new WikiPage(WikiPage.WIKI_INDEX_PAGE);
            WikiPage menuPage = new WikiPage(WikiPage.WIKI_MENU_PAGE);
            indexPage.setCreationTime(System.currentTimeMillis());
            wiki.addPage(indexPage);
            menuPage.setCreationTime(System.currentTimeMillis());
            menuPage.setContent("* [[Index]]\n* [[Index|Your link]]");
            wiki.addPage(menuPage);
            saveWikiPage(ores, indexPage, false, wiki);
            saveWikiPage(ores, menuPage, false, wiki);
        }
        // add pages internally used for displaying dynamic data, they are not persisted
        WikiPage recentChangesPage = new WikiPage(WikiPage.WIKI_RECENT_CHANGES_PAGE);
        WikiPage a2zPage = new WikiPage(WikiPage.WIKI_A2Z_PAGE);
        wiki.addPage(recentChangesPage);
        wiki.addPage(a2zPage);
        if (log.isDebug()) {
            long stop = System.currentTimeMillis();
            log.debug("loading of wiki from filessystem took (ms) " + (stop - start));
        }
        return wiki;
    });
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)10 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSItemSuffixFilter (org.olat.core.util.vfs.filters.VFSItemSuffixFilter)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)2 VFSLeafFilter (org.olat.core.util.vfs.filters.VFSLeafFilter)2