Search in sources :

Example 1 with LocalFolderImpl

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

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 2 with LocalFolderImpl

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

the class RichTextConfiguration method setDocumentMediaBase.

/**
 * Set the documents media base that is used to deliver media files
 * referenced by the content.
 *
 * @param documentBaseContainer
 *            the vfs container that contains the media files
 * @param relFilePath
 *            The file path of the HTML file relative to the
 *            documentBaseContainer
 * @param usess
 *            The user session
 */
private void setDocumentMediaBase(final VFSContainer documentBaseContainer, String relFilePath, UserSession usess) {
    linkBrowserRelativeFilePath = relFilePath;
    // get a usersession-local mapper for the file storage (and tinymce's references to images and such)
    Mapper contentMapper = new VFSContainerMapper(documentBaseContainer);
    // Register mapper for this user. This mapper is cleaned up in the
    // dispose method (RichTextElementImpl will clean it up)
    // Register mapper as cacheable
    String mapperID = VFSManager.getRealPath(documentBaseContainer);
    if (mapperID == null) {
        // Can't cache mapper, no cacheable context available
        contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, contentMapper);
    } else {
        // Add classname to the file path to remove conflicts with other
        // usages of the same file path
        mapperID = this.getClass().getSimpleName() + ":" + mapperID + ":" + CodeHelper.getRAMUniqueID();
        contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, mapperID, contentMapper);
    }
    if (relFilePath != null) {
        // remove filename, path must end with slash
        int lastSlash = relFilePath.lastIndexOf("/");
        if (lastSlash == -1) {
            relFilePath = "";
        } else if (lastSlash + 1 < relFilePath.length()) {
            relFilePath = relFilePath.substring(0, lastSlash + 1);
        } else {
            String containerPath = documentBaseContainer.getName();
            // try to get more information if it's a local folder impl
            if (documentBaseContainer instanceof LocalFolderImpl) {
                LocalFolderImpl folder = (LocalFolderImpl) documentBaseContainer;
                containerPath = folder.getBasefile().getAbsolutePath();
            }
            log.warn("Could not parse relative file path::" + relFilePath + " in container::" + containerPath);
        }
    } else {
        relFilePath = "";
        // set empty relative file path to prevent nullpointers later on
        linkBrowserRelativeFilePath = relFilePath;
    }
    mapperUri = contentMapperKey.getUrl() + "/" + relFilePath;
    setQuotedConfigValue(DOCUMENT_BASE_URL, mapperUri);
}
Also used : VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) Mapper(org.olat.core.dispatcher.mapper.Mapper) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 3 with LocalFolderImpl

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

the class GlossaryTermMapper 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();
    // security checks are done by MapperRegistry
    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("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
        return new NotFoundMediaResource();
    }
    VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
    if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
        logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
        return new NotFoundMediaResource();
    }
    // 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/javascript");
    // Get data
    String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
    resource.setData(glossaryArrayData);
    // UTF-8 encoding used in this js file since explicitly set in the ajax
    // call (usually js files are 8859-1)
    resource.setEncoding("utf-8");
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 4 with LocalFolderImpl

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

the class ZipUtil method unzipStrict.

/**
 * Unzip a file in the target dir with the restricted version
 * @param zipFile
 * @param targetDir
 * @return
 */
public static boolean unzipStrict(File zipFile, VFSContainer targetDir) {
    if (targetDir instanceof LocalFolderImpl) {
        String outdir = ((LocalFolderImpl) targetDir).getBasefile().getAbsolutePath();
        InputStream in = null;
        try {
            long s = System.currentTimeMillis();
            in = new FileInputStream(zipFile);
            xxunzip(in, outdir);
            log.info("unzip file=" + zipFile.getName() + " to=" + outdir + " t=" + Long.toString(System.currentTimeMillis() - s));
            return true;
        } catch (IOException e) {
            log.error("I/O failure while unzipping " + zipFile.getName() + " to " + outdir);
            return false;
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return false;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 5 with LocalFolderImpl

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

the class MailModule method getRootForAttachments.

public VFSContainer getRootForAttachments() {
    String root = folderModule.getCanonicalRoot() + attachmentsRoot;
    File rootFile = new File(root);
    if (!rootFile.exists()) {
        rootFile.mkdirs();
    }
    VFSContainer rootContainer = new LocalFolderImpl(rootFile);
    return rootContainer;
}
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