Search in sources :

Example 6 with VFSMediaResource

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

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 7 with VFSMediaResource

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

the class WikiHandler method getAsMediaResource.

@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
    VFSContainer rootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(res);
    VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(rootContainer);
    return new VFSMediaResource(wikiZip);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 8 with VFSMediaResource

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

the class CatalogEntryImageMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (relPath.startsWith("/")) {
        relPath = relPath.substring(1, relPath.length());
    }
    VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
    VFSItem image = categoryResources.resolve(relPath);
    MediaResource resource = null;
    if (image instanceof VFSLeaf) {
        if (image instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) image).getMetaInfo();
            if (info != null) {
                VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
                if (thumbnail != null) {
                    resource = new VFSMediaResource(thumbnail);
                }
            }
        }
        if (resource == null) {
            resource = new VFSMediaResource((VFSLeaf) image);
        }
    } else {
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 9 with VFSMediaResource

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

the class FileArtefactDetailsController method initFileView.

private void initFileView(VFSItem file, UserRequest ureq) {
    vC = createVelocityContainer("fileDetails");
    DownloadComponent downlC = new DownloadComponent("download", (VFSLeaf) file);
    vC.put("download", downlC);
    vC.contextPut("filename", fArtefact.getFilename());
    if (file instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) file).getMetaInfo();
        vC.contextPut("meta", meta);
        // show a preview thumbnail if possible
        if (meta.isThumbnailAvailable()) {
            VFSLeaf thumb = meta.getThumbnail(200, 200, false);
            if (thumb != null) {
                mr = new VFSMediaResource(thumb);
            }
            if (mr != null) {
                String thumbMapper = registerMapper(ureq, new Mapper() {

                    @Override
                    public MediaResource handle(String relPath, HttpServletRequest request) {
                        return mr;
                    }
                });
                vC.contextPut("thumbMapper", thumbMapper);
            }
        }
    }
    if (!readOnlyMode) {
        // allow to delete
        delLink = LinkFactory.createLink("delete.file", vC, this);
        delLink.setUserObject(file);
    }
    viewPanel.setContent(vC);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Mapper(org.olat.core.dispatcher.mapper.Mapper) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) DownloadComponent(org.olat.core.gui.components.download.DownloadComponent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 10 with VFSMediaResource

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

the class CmdServeResource method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
        throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
    // extract file
    String path = ureq.getModuleURI();
    MediaResource mr = null;
    VFSItem vfsitem = folderComponent.getRootContainer().resolve(path);
    if (vfsitem == null) {
        // double decoding of ++
        vfsitem = FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
    }
    if (vfsitem == null) {
        mr = new NotFoundMediaResource();
    } else if (!(vfsitem instanceof VFSLeaf)) {
        mr = new NotFoundMediaResource();
    } else {
        VFSLeaf vfsfile = (VFSLeaf) vfsitem;
        boolean forceDownload = FolderManager.isDownloadForcedFileType(vfsfile.getName());
        if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {
            // setCurrentURI(path);
            // set the http content-type and the encoding
            // try to load in iso-8859-1
            InputStream is = vfsfile.getInputStream();
            if (is == null) {
                mr = new NotFoundMediaResource();
            } else {
                String page = FileUtils.load(is, DEFAULT_ENCODING);
                // search for the <meta content="text/html; charset=utf-8"
                // http-equiv="Content-Type" /> tag
                // if none found, assume iso-8859-1
                String enc = DEFAULT_ENCODING;
                boolean useLoaded = false;
                // <meta.*charset=([^"]*)"
                Matcher m = PATTERN_ENCTYPE.matcher(page);
                boolean found = m.find();
                if (found) {
                    String htmlcharset = m.group(1);
                    enc = htmlcharset;
                    if (htmlcharset.equals(DEFAULT_ENCODING)) {
                        useLoaded = true;
                    }
                } else {
                    useLoaded = true;
                }
                // set the new encoding to remember for any following .js file loads
                g_encoding = enc;
                if (useLoaded) {
                    StringMediaResource smr = new StringMediaResource();
                    String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc;
                    smr.setContentType(mimetype);
                    smr.setEncoding(enc);
                    smr.setData(page);
                    if (forceDownload) {
                        smr.setDownloadable(true, vfsfile.getName());
                    }
                    mr = smr;
                } else {
                    // found a new charset other than iso-8859-1 -> let it load again
                    // as bytes (so we do not need to convert to string and back
                    // again)
                    VFSMediaResource vmr = new VFSMediaResource(vfsfile);
                    vmr.setEncoding(enc);
                    if (forceDownload) {
                        vmr.setDownloadable(true);
                    }
                    mr = vmr;
                }
            }
        } else if (path.endsWith(".js")) {
            // a javascript library
            VFSMediaResource vmr = new VFSMediaResource(vfsfile);
            // that loads the .js file
            if (g_encoding != null) {
                vmr.setEncoding(g_encoding);
            }
            if (forceDownload) {
                vmr.setDownloadable(true);
            }
            mr = vmr;
        } else if (path.endsWith(".txt")) {
            // text files created in OpenOLAT are utf-8, prefer this encoding
            VFSMediaResource vmr = new VFSMediaResource(vfsfile);
            vmr.setEncoding("utf-8");
            if (forceDownload) {
                vmr.setDownloadable(true);
            }
            mr = vmr;
        } else {
            // binary data: not .html, not .htm, not .js -> treated as is
            VFSMediaResource vmr = new VFSMediaResource(vfsfile);
            if (forceDownload) {
                vmr.setDownloadable(true);
            }
            mr = vmr;
        }
    }
    ThreadLocalUserActivityLogger.log(FolderLoggingAction.BC_FILE_READ, getClass(), CoreLoggingResourceable.wrapBCFile(path));
    ureq.getDispatchResult().setResultingMediaResource(mr);
    // update download counter
    if (vfsitem instanceof MetaTagged) {
        MetaTagged itemWithMeta = (MetaTagged) vfsitem;
        MetaInfo meta = itemWithMeta.getMetaInfo();
        meta.increaseDownloadCount();
        meta.write();
    }
    return null;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) StringMediaResource(org.olat.core.gui.media.StringMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) StringMediaResource(org.olat.core.gui.media.StringMediaResource) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)48 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)44 MediaResource (org.olat.core.gui.media.MediaResource)30 VFSItem (org.olat.core.util.vfs.VFSItem)28 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)24 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)10 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)10 StringMediaResource (org.olat.core.gui.media.StringMediaResource)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)4 Mapper (org.olat.core.dispatcher.mapper.Mapper)4 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)4 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Size (org.olat.core.commons.services.image.Size)2