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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations