use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class CheckListStepRunnerCallback method execute.
@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
GeneratorData data = (GeneratorData) runContext.get("data");
List<Checkbox> templateCheckbox = data.getCheckboxList();
ModuleConfiguration templateConfig = data.getModuleConfiguration();
ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
CourseEnvironment courseEnv = course.getCourseEnvironment();
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
CourseNode structureNode = createCourseNode(data.getStructureShortTitle(), data.getStructureTitle(), data.getStructureObjectives(), "st");
CourseEditorTreeNode parentNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
course.getEditorTreeModel().addCourseNode(structureNode, parentNode.getCourseNode());
List<CheckListNode> nodes = data.getNodes();
List<String> nodesIdent = new ArrayList<>();
for (CheckListNode node : nodes) {
String title = node.getTitle();
CheckListCourseNode checkNode = (CheckListCourseNode) createCourseNode(title, title, null, "checklist");
nodesIdent.add(checkNode.getIdent());
ModuleConfiguration config = checkNode.getModuleConfiguration();
config.putAll(templateConfig);
CheckboxList checkboxList = new CheckboxList();
List<Checkbox> boxes = new ArrayList<>();
for (Checkbox templateBox : templateCheckbox) {
Checkbox checkbox = templateBox.clone();
boxes.add(checkbox);
if (StringHelper.containsNonWhitespace(templateBox.getFilename())) {
File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
VFSContainer tmpContainer = new LocalFolderImpl(path);
VFSItem item = tmpContainer.resolve(templateBox.getFilename());
if (item instanceof VFSLeaf) {
VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
VFSManager.copyContent(tmpContainer, container);
tmpContainer.deleteSilently();
}
}
}
checkboxList.setList(boxes);
config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, checkboxList);
boolean dueDate = node.getDueDate() != null;
if (dueDate) {
config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
}
config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
}
setScoreCalculation(data, (STCourseNode) structureNode, nodesIdent);
return StepsMainRunController.DONE_MODIFIED;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class FileElementImpl method moveUploadFileTo.
@Override
public VFSLeaf moveUploadFileTo(VFSContainer destinationContainer, boolean crop) {
VFSLeaf targetLeaf = null;
if (tempUploadFile != null && tempUploadFile.exists()) {
// Check if such a file does already exist, if yes rename new file
VFSItem existsChild = destinationContainer.resolve(uploadFilename);
if (existsChild != null) {
// Use standard rename policy
uploadFilename = VFSManager.rename(destinationContainer, uploadFilename);
}
// Create target leaf file now and delete original temp file
if (destinationContainer instanceof LocalFolderImpl) {
// Optimize for local files (don't copy, move instead)
LocalFolderImpl folderContainer = (LocalFolderImpl) destinationContainer;
File destinationDir = folderContainer.getBasefile();
File targetFile = new File(destinationDir, uploadFilename);
Crop cropSelection = previewEl == null ? null : previewEl.getCropSelection();
if (crop && cropSelection != null) {
CoreSpringFactory.getImpl(ImageService.class).cropImage(tempUploadFile, targetFile, cropSelection);
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else if (FileUtils.copyFileToFile(tempUploadFile, targetFile, true)) {
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else {
log.error("Error after copying content from temp file, cannot copy file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
if (targetLeaf == null) {
log.error("Error after copying content from temp file, cannot resolve copied file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
} else {
// Copy stream in case the destination is a non-local container
VFSLeaf leaf = destinationContainer.createChildLeaf(uploadFilename);
boolean success = false;
try {
success = VFSManager.copyContent(new FileInputStream(tempUploadFile), leaf);
} catch (FileNotFoundException e) {
log.error("Error while copying content from temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()), e);
}
if (success) {
// Delete original temp file after copy to simulate move
// behavior
tempUploadFile.delete();
targetLeaf = leaf;
}
}
} else if (log.isDebug()) {
log.debug("Error while copying content from temp file, no temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()));
}
return targetLeaf;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class GlossaryDefinitionMapper method handle.
/**
* @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
* javax.servlet.http.HttpServletRequest)
*/
public MediaResource handle(String relPath, HttpServletRequest request) {
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
String[] parts = relPath.split("/");
String glossaryId = parts[1];
String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
File glossaryFolderFile = new File(glossaryFolderString);
if (!glossaryFolderFile.isDirectory()) {
logWarn("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
String glossaryMainTerm = parts[2];
if (parts.length > 2) {
// this handle / or \ in a term
for (int i = 3; i < parts.length; i++) {
glossaryMainTerm += "/" + parts[i];
}
}
// cut away ".html" if necessary
if (glossaryMainTerm.endsWith(".html")) {
glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
}
glossaryMainTerm = glossaryMainTerm.toLowerCase();
Set<String> alternatives = new HashSet<>();
prepareAlternatives(glossaryMainTerm, alternatives);
// Create a media resource
StringMediaResource resource = new StringMediaResource() {
@Override
public void prepare(HttpServletResponse hres) {
// don't use normal string media headers which prevent caching,
// use standard browser caching based on last modified timestamp
}
};
resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
resource.setContentType("text/html");
List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
GlossaryItem foundItem = null;
for (GlossaryItem glossaryItem : glossItems) {
String item = glossaryItem.getGlossTerm().toLowerCase();
if (alternatives.contains(item)) {
foundItem = glossaryItem;
break;
}
}
if (foundItem == null) {
return new NotFoundMediaResource();
}
StringBuilder sb = new StringBuilder();
sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
resource.setData(sb.toString());
resource.setEncoding("utf-8");
if (isLogDebugEnabled())
logDebug("loaded definition for " + glossaryMainTerm, null);
return resource;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class CourseLayoutHelper method getCourseThemeTemplates.
/**
* get a list of system wide course theme templates
* they need to be in webapp/static/coursethemes/XY
* @return
*/
public static List<VFSItem> getCourseThemeTemplates() {
List<VFSItem> courseThemes = new ArrayList<VFSItem>();
// 1. add the system-defaults
String staticAbsPath = WebappHelper.getContextRealPath("/static");
File themesFile = new File(staticAbsPath);
VFSContainer cThemeCont = new LocalFolderImpl(themesFile);
cThemeCont = (VFSContainer) cThemeCont.resolve("/coursethemes");
if (cThemeCont != null) {
courseThemes = cThemeCont.getItems(themeNamesFilter);
}
// 2. now add the additional Templates from the current Theme
VFSContainer addThCont = CourseLayoutHelper.getOLATThemeCourseLayoutFolder();
if (addThCont != null) {
List<VFSItem> additionalThemes = addThCont.getItems(themeNamesFilter);
courseThemes.addAll(additionalThemes);
}
return courseThemes;
}
Aggregations