Search in sources :

Example 96 with LocalFolderImpl

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

the class RepositoryEntryImageMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (rootContainer == null) {
        rootContainer = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    }
    if (relPath.startsWith("/")) {
        relPath = relPath.substring(1, relPath.length());
    }
    MediaResource resource = null;
    VFSItem image = rootContainer.resolve(relPath);
    if (image instanceof VFSLeaf) {
        if (image instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) image).getMetaInfo();
            if (info != null) {
                // 121 is needed to fill the div
                VFSLeaf thumbnail = info.getThumbnail(180, 120, true);
                if (thumbnail != null) {
                    resource = new VFSMediaResource(thumbnail);
                }
            }
        }
        if (resource == null) {
            resource = new VFSMediaResource((VFSLeaf) image);
        }
    }
    return resource;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 97 with LocalFolderImpl

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

the class IQManager method getIdentitiesWithQtiSerEntry.

/**
 * Get identities with exists qti.ser file.
 * @param resourceableId
 * @param ident
 * @return
 */
public List<Identity> getIdentitiesWithQtiSerEntry(Long resourceableId, String ident) {
    List<Identity> identities = new ArrayList<Identity>();
    LocalFolderImpl item = new LocalFolderImpl(new File(FilePersister.getFullPathToCourseNodeDirectory(Long.toString(resourceableId), ident)));
    if (VFSManager.exists(item)) {
        for (VFSItem identityFolder : item.getItems()) {
            Identity identity = BaseSecurityManager.getInstance().findIdentityByName(identityFolder.getName());
            if (identity != null)
                identities.add(identity);
        }
    }
    return identities;
}
Also used : ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 98 with LocalFolderImpl

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

the class GlossaryItemManager method upgradeAndDeleteOldGlossary.

/**
 * upgrades the old textmarker-format into the new DocBook-glossary-format
 *
 * @param folderContainingGlossary
 * @param textMarkerFile
 */
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
    // check if a new glossary exists, warn
    if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
        logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
    } else {
        // upgrade it
        TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
        List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
        Collections.sort(textMarkerList);
        ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
        for (TextMarker tm : textMarkerList) {
            String glossTerm = tm.getMarkedMainText();
            String glossDef = tm.getHooverText();
            GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
            // handle alias -> save as synonyms
            String aliasString = tm.getMarkedAliasText();
            if (StringHelper.containsNonWhitespace(aliasString)) {
                String[] aliasArr = aliasString.split(";");
                ArrayList<String> glossSynonyms = new ArrayList<String>();
                glossSynonyms.addAll(Arrays.asList(aliasArr));
                glossItem.setGlossSynonyms(glossSynonyms);
            }
            glossaryItemArr.add(glossItem);
        }
        VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
        saveToFile(glossaryFile, glossaryItemArr);
        // keep a backup in debug mode:
        if (Settings.isDebuging()) {
            File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
            File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
            FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
        }
        textMarkerFile.delete();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) TextMarkerManager(org.olat.core.gui.control.generic.textmarker.TextMarkerManager) TextMarker(org.olat.core.gui.control.generic.textmarker.TextMarker) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) File(java.io.File)

Example 99 with LocalFolderImpl

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

the class IframePortletRunController method initEditButton.

/**
 * Helper to build the editor button and initialize some variables needed by
 * the editor
 *
 * @param ureq
 * @param editFilePath
 */
private boolean initEditButton(String editFilePath) {
    if (editFilePath == null) {
        log.warn("initEditButton: editFilePath was null");
        return false;
    }
    File editFile = new File(editFilePath);
    File parent = editFile.getParentFile();
    if (parent == null) {
        log.warn("initEditButton: no parent folder for " + editFilePath);
        return false;
    }
    if (!editFile.getParentFile().exists()) {
        log.warn("editFilePath is wrong, not even parent dir exists::" + editFile.getParentFile().getAbsolutePath());
        return false;
    }
    if (!editFile.canWrite()) {
        log.warn("Can not write to file::" + editFile.getAbsolutePath());
        return false;
    }
    if (!editFile.exists()) {
        try {
            editFile.createNewFile();
        } catch (IOException e) {
            log.error("Cannot create file::" + editFile.getAbsolutePath());
            return false;
        }
    }
    // now as we have a writable file we initialize the path to this file
    // and the edit button
    fileName = editFile.getName();
    rootDir = new LocalFolderImpl(editFile.getParentFile());
    return true;
}
Also used : IOException(java.io.IOException) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 100 with LocalFolderImpl

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

the class CourseLayoutHelper method getThemeBaseFolder.

/**
 * get path according to type of theme
 * @param courseEnvironment
 * @param cssSet
 * @return
 */
public static VFSContainer getThemeBaseFolder(CourseEnvironment courseEnvironment, String cssSet) {
    VFSContainer courseBase = courseEnvironment.getCourseBaseContainer();
    // the hidden-dir CSS in "/coursecss/xy.css"
    if (StringHelper.containsNonWhitespace(cssSet) && cssSet.contains(COURSEFOLDER_CSS_BASE) && cssSet.startsWith("/") && cssSet.lastIndexOf("/") > 0) {
        if (courseEnvironment.getCourseFolderContainer().resolve(COURSEFOLDER_CSS_BASE) != null) {
            return courseEnvironment.getCourseFolderContainer();
        } else
            return null;
    } else if (!StringHelper.containsNonWhitespace(cssSet) || cssSet.startsWith("/")) {
        // the old legacy format "/blibla.css"
        return (VFSContainer) courseBase.resolve("coursefolder");
    } else if (cssSet.equals(CONFIG_KEY_CUSTOM)) {
        return (VFSContainer) courseBase.resolve(LAYOUT_COURSE_SUBFOLDER + "/custom");
    } else if (CONFIG_KEY_PREDEFINED.equals(cssSet)) {
        return (VFSContainer) courseBase.resolve(LAYOUT_COURSE_SUBFOLDER + "/predefined");
    } else if (cssSet.startsWith(CONFIG_KEY_TEMPLATE)) {
        String selTheme = cssSet.substring(CONFIG_KEY_TEMPLATE.length());
        // 1. check if it's a layout from the OLAT-theme
        VFSContainer themeContainer = getOLATThemeCourseLayoutFolder();
        if (themeContainer != null) {
            themeContainer = (VFSContainer) themeContainer.resolve("/" + selTheme);
            return themeContainer;
        }
        // 2. check if it's system-default
        String staticAbsPath = WebappHelper.getContextRealPath("/static/coursethemes/");
        File themesFile = new File(staticAbsPath + selTheme);
        if (themesFile.exists() && themesFile.isDirectory())
            return new LocalFolderImpl(themesFile);
    }
    // default was set
    return null;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Aggregations

LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)122 File (java.io.File)82 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 VFSItem (org.olat.core.util.vfs.VFSItem)38 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)30 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 Document (org.dom4j.Document)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Document (org.apache.lucene.document.Document)6 Element (org.dom4j.Element)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)6 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)6 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6