Search in sources :

Example 46 with VFSContainer

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);
    }
}
Also used : ForumFormatter(org.olat.modules.fo.archiver.formatters.ForumFormatter) ForumRTFFormatter(org.olat.modules.fo.archiver.formatters.ForumRTFFormatter) VFSContainer(org.olat.core.util.vfs.VFSContainer) Property(org.olat.properties.Property) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 47 with VFSContainer

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;
}
Also used : AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenMeetingsModule(org.olat.modules.openmeetings.OpenMeetingsModule) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ForumManager(org.olat.modules.fo.manager.ForumManager) OpenMeetingsException(org.olat.modules.openmeetings.manager.OpenMeetingsException) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) File(java.io.File) OpenMeetingsManager(org.olat.modules.openmeetings.manager.OpenMeetingsManager)

Example 48 with VFSContainer

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());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 49 with VFSContainer

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;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 50 with VFSContainer

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);
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) LayoutMain3ColsPreviewController(org.olat.core.commons.fullWebApp.LayoutMain3ColsPreviewController) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController) SinglePageController(org.olat.core.commons.modules.singlepage.SinglePageController) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34