use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class CollaborationTools method archiveForum.
private void archiveForum(String archivFilePath) {
Property forumKeyProperty = NarrowedPropertyManager.getInstance(ores).findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
if (forumKeyProperty != null) {
VFSContainer archiveContainer = new LocalFolderImpl(new File(archivFilePath));
String archiveForumName = "del_forum_" + forumKeyProperty.getLongValue();
VFSContainer archiveForumContainer = archiveContainer.createChildContainer(archiveForumName);
ForumFormatter ff = new ForumRTFFormatter(archiveForumContainer, false, I18nModule.getDefaultLocale());
ForumArchiveManager.getInstance().applyFormatter(ff, forumKeyProperty.getLongValue(), null);
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class CollaborationTools method deleteTools.
/**
* delete all CollaborationTools stuff from the database, which is related to
* the calling OLATResourceable.
*/
public void deleteTools(BusinessGroup businessGroupTodelete) {
NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
/*
* delete the forum, if existing
*/
ForumManager fom = ForumManager.getInstance();
Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
if (forumKeyProperty != null) {
// if there was a forum, delete it
Long forumKey = forumKeyProperty.getLongValue();
if (forumKey == null)
throw new AssertException("property had no longValue, prop:" + forumKeyProperty);
fom.deleteForum(forumKey);
}
/*
* delete the folder, if existing
*/
OlatRootFolderImpl vfsContainer = new OlatRootFolderImpl(getFolderRelPath(), null);
File fFolderRoot = vfsContainer.getBasefile();
if (fFolderRoot.exists()) {
FileUtils.deleteDirsAndFiles(fFolderRoot, true, true);
}
/*
* delete the wiki if existing
*/
VFSContainer rootContainer = WikiManager.getInstance().getWikiRootContainer(ores);
if (rootContainer != null)
rootContainer.delete();
/*
* Delete calendar if exists
*/
if (businessGroupTodelete != null) {
CoreSpringFactory.getImpl(ImportToCalendarManager.class).deleteGroupImportedCalendars(businessGroupTodelete);
CoreSpringFactory.getImpl(CalendarManager.class).deleteGroupCalendar(businessGroupTodelete);
}
/*
* delete chatRoom
*/
// no cleanup needed, automatically done when last user exits the room
/*
* delete all Properties defining enabled/disabled CollabTool XY and the
* news content
*/
npm.deleteProperties(null, null, PROP_CAT_BG_COLLABTOOLS, null);
/*
* Delete OpenMeetings room
*/
OpenMeetingsModule omModule = CoreSpringFactory.getImpl(OpenMeetingsModule.class);
if (omModule.isEnabled()) {
OpenMeetingsManager omManager = CoreSpringFactory.getImpl(OpenMeetingsManager.class);
try {
omManager.deleteAll(ores, null, null);
} catch (OpenMeetingsException e) {
log.error("A room could not be deleted for group: " + ores, e);
}
}
/*
* and last but not least the cache is reseted
*/
cacheToolStates.clear();
this.dirty = true;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class CollaborationTools method archiveWiki.
private void archiveWiki(String archivFilePath) {
VFSContainer wikiContainer = WikiManager.getInstance().getWikiRootContainer(ores);
VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(wikiContainer);
String exportFileName = "del_wiki_" + ores.getResourceableId() + ".zip";
File archiveDir = new File(archivFilePath);
if (!archiveDir.exists()) {
archiveDir.mkdir();
}
String fullFilePath = archivFilePath + File.separator + exportFileName;
try {
FileUtils.bcopy(wikiZip.getInputStream(), new File(fullFilePath), "archive wiki");
} catch (FileNotFoundException e) {
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
} catch (IOException ioe) {
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class FileCreatorController method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean isFileNmaeValid = true;
boolean isSubDirValid = true;
// 1: Check sub path
String subPath = targetSubPath.getValue();
if (subPath != null) {
// Cleanup first
subPath = subPath.toLowerCase().trim();
if (!validSubPathPattern.matcher(subPath).matches()) {
targetSubPath.setErrorKey("subpath.error.characters", null);
isSubDirValid = false;
} else {
// Fix mess with slashes and dots
// reduce doubled slashes with single slash
subPath = subPath.replaceAll("\\.*\\/+\\.*", "\\/");
// do it a second time to catch the double slashes created by previous replacement
subPath = subPath.replaceAll("\\/+", "\\/");
// remove slash at end
if (subPath.endsWith("/")) {
subPath = subPath.substring(0, subPath.length() - 1);
}
// single slash means no sub-directory
if (subPath.length() == 1 && subPath.startsWith("/")) {
subPath = "";
}
// fix missing slash at start
if (subPath.length() > 0 && !subPath.startsWith("/")) {
subPath = "/" + subPath;
}
// update in GUI so user sees how we optimized
targetSubPath.setValue(subPath);
}
// Now check if this path does not already exist
if (isSubDirValid && StringHelper.containsNonWhitespace(subPath)) {
// Try to resolve given rel path from current container
VFSItem uploadDir = baseContainer.resolve(subPath);
if (uploadDir != null) {
// already exists. this is fine, as long as it is a directory and not a file
if (!(uploadDir instanceof VFSContainer)) {
// error
targetSubPath.setErrorKey("subpath.error.dir.is.file", new String[] { subPath });
isSubDirValid = false;
}
}
}
if (isSubDirValid) {
targetSubPath.clearError();
}
}
// 2: Check file name
String fileName = fileNameElement.getValue();
if (!StringHelper.containsNonWhitespace(fileName)) {
fileNameElement.setErrorKey("mf.error.filename.empty", new String[0]);
isFileNmaeValid = false;
} else {
fileName = fileName.toLowerCase().trim();
if (!FileUtils.validateFilename(fileName)) {
fileNameElement.setErrorKey("mf.error.filename.invalidchars", new String[0]);
isFileNmaeValid = false;
} else if (!fileName.endsWith(".html") && !fileName.endsWith(".htm")) {
fileName = fileName + ".html";
}
// update in GUI so user sees how we optimized
fileNameElement.setValue(fileName);
// check if it already exists
String filePath = fileName;
if (filePath.startsWith("/")) {
filePath = "/" + filePath;
}
if (StringHelper.containsNonWhitespace(targetSubPath.getValue())) {
filePath = targetSubPath.getValue() + filePath;
}
VFSItem vfsItem = baseContainer.resolve(filePath);
if (vfsItem != null) {
fileNameElement.setErrorKey("mf.error.filename.exists", new String[] { filePath });
isFileNmaeValid = false;
}
}
if (isFileNmaeValid) {
fileNameElement.clearError();
}
return isFileNmaeValid && isSubDirValid;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class LinkFileCombiCalloutController method doOpenWysiwygEditor.
// ///////////////// helper methods to implement event loop
private void doOpenWysiwygEditor(UserRequest ureq) {
if (relFilPathIsProposal) {
file = VFSManager.resolveOrCreateLeafFromPath(baseContainer, relFilePath);
}
if (file == null) {
// huh? no idea what happend, do nothing and log error
logError("Could not load or create file with relFilePath::" + relFilePath + " in baseContainer::" + VFSManager.getRealPath(baseContainer), null);
return;
}
// Configure editor depending on limitEditorToRelativeFiles flag
// either based on baseContainer or the files direct parent
VFSContainer editorBaseContainer = baseContainer;
String editorRelPath = relFilePath;
if (!allowEditorRelativeLinks && relFilePath.indexOf("/", 1) != 0) {
editorBaseContainer = file.getParentContainer();
editorRelPath = file.getName();
}
// Open HTML editor in dialog
Controller wysiwygCtr = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), editorBaseContainer, editorRelPath, true, customLinkTreeModel);
displayModal(wysiwygCtr);
}
Aggregations