Search in sources :

Example 21 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class IFrameDeliveryMapper method deliverFile.

protected MediaResource deliverFile(HttpServletRequest httpRequest, String path, boolean isPopUp) {
    MediaResource mr;
    VFSLeaf vfsLeaf = null;
    VFSItem vfsItem = null;
    // if directory gets renamed root becomes null
    if (rootDir == null) {
        return new NotFoundMediaResource();
    } else {
        vfsItem = rootDir.resolve(path);
    }
    // only files are allowed, but somehow it happened that folders showed up here
    if (vfsItem instanceof VFSLeaf) {
        vfsLeaf = (VFSLeaf) rootDir.resolve(path);
    } else {
        mr = new NotFoundMediaResource();
    }
    if (vfsLeaf == null) {
        mr = new NotFoundMediaResource();
    } else {
        // and accept positions of this string at length-3 or length-4
        if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (path.length() - 4)) {
            // set the http content-type and the encoding
            Page page = loadPageWithGuess(vfsLeaf);
            String pageEncoding = page.getEncoding();
            if (page.isUseLoadedPageString()) {
                mr = prepareMediaResource(httpRequest, page.getPage(), pageEncoding, page.getContentType(), isPopUp);
            } else {
                // found a new charset other than iso-8859-1, load string with proper encoding
                String content = FileUtils.load(vfsLeaf.getInputStream(), pageEncoding);
                mr = prepareMediaResource(httpRequest, content, pageEncoding, page.getContentType(), isPopUp);
            }
            if (contentEncoding == null) {
                contentEncoding = pageEncoding;
            }
        } else if (path.endsWith(FILE_SUFFIX_JS)) {
            // a javascript library
            VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
            // that loads the .js file
            if (jsEncoding != null) {
                vmr.setEncoding(jsEncoding);
            } else if (contentEncoding != null) {
                vmr.setEncoding(contentEncoding);
            }
            mr = vmr;
        } else {
            // binary data: not .html, not .htm, not .js -> treated as is
            VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
            String filename = vfsLeaf.getName();
            // This is to prevent the login prompt in Excel, Word and PowerPoint
            if (filename.endsWith(".xlsx") || filename.endsWith(".pptx") || filename.endsWith(".docx")) {
                vmr.setDownloadable(true);
            }
            mr = vmr;
        }
    }
    return mr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 22 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class CertificateDispatcher method execute.

@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
    final String origUri = request.getRequestURI();
    String uuid = origUri.substring(uriPrefix.length());
    int indexSuffix = uuid.indexOf('/');
    if (indexSuffix > 0) {
        uuid = uuid.substring(0, indexSuffix);
    }
    MediaResource resource;
    Certificate certificate = certificatesManager.getCertificateByUuid(uuid);
    if (certificate == null) {
        resource = new NotFoundMediaResource();
    } else {
        VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
        resource = new VFSMediaResource(certificateFile);
    }
    ServletUtil.serveResource(request, response, resource);
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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 23 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class HtmlStaticMapper method handle.

public MediaResource handle(String relPath, HttpServletRequest request) {
    if (log.isDebug())
        log.debug("CPComponent Mapper relPath=" + relPath);
    VFSItem currentItem = mapperRootContainer.resolve(relPath);
    if (currentItem == null || (currentItem instanceof VFSContainer)) {
        return new NotFoundMediaResource();
    }
    VFSMediaResource vmr = new VFSMediaResource((VFSLeaf) currentItem);
    String encoding = SimpleHtmlParser.extractHTMLCharset(((VFSLeaf) currentItem));
    if (log.isDebug())
        log.debug("CPComponent Mapper set encoding=" + encoding);
    // 
    vmr.setEncoding(encoding);
    return vmr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 24 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class HtmlStaticPageComponent method getAsyncMediaResource.

/**
 * @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
 */
public MediaResource getAsyncMediaResource(UserRequest ureq) {
    // is the path to the desired resource (put together by the webbrowser by
    // combining latesturl and relative link)
    String moduleURI = ureq.getModuleURI();
    MediaResource mr = null;
    if (moduleURI != null) {
        // 1. check for an olat command (special link to indicate a command)
        if (moduleURI.startsWith(OLAT_CMD_PREFIX)) {
            String cmdAndSub = moduleURI.substring(OLAT_CMD_PREFIX.length());
            int slpos = cmdAndSub.indexOf('/');
            if (slpos != -1) {
                String cmd = cmdAndSub.substring(0, slpos);
                String subcmd = cmdAndSub.substring(slpos + 1);
                OlatCmdEvent aev = new OlatCmdEvent(cmd, subcmd);
                fireEvent(ureq, aev);
                // Mediaresourse)
                if (aev.isAccepted())
                    return null;
            }
        // else ignore (syntax error in command
        }
        // make sure moduleURI does not contain ".." or such (hack attempt)
        // -> ok, userrequest class asserts this.
        VFSItem sourceItem = rootContainer.resolve(moduleURI);
        // return 404 if the requested file does not exist
        if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
            return new NotFoundMediaResource();
        }
        // we know the file exists.
        boolean checkRegular = true;
        // check for special case: render the follwing link in a new (server) window and all following clicks as well
        if ((ureq.getParameter("olatsite") != null) || ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") != null))) {
            log.debug("moduleURI=" + moduleURI);
            ExternalSiteEvent ese = new ExternalSiteEvent(moduleURI);
            fireEvent(ureq, ese);
            if (ese.isAccepted()) {
                mr = ese.getResultingMediaResource();
                log.debug("ExternalSiteEvent is accepted");
                checkRegular = false;
            } else {
                // it is a html page with olatraw parameter => redirect to mapper
                Mapper mapper = new HtmlStaticMapper(rootContainer);
                // NOTE: do not deregister this mapper, since it could be used a lot later (since it is opened in a new browser window)
                // Register mapper as cacheable
                String mapperID = VFSManager.getRealPath(rootContainer);
                if (mapperID == null) {
                    // Can't cache mapper, no cacheable context available
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapper);
                } else {
                    // Add classname to the file path to remove conflicts with other
                    // usages of the same file path
                    mapperID = this.getClass().getSimpleName() + ":" + mapperID;
                    amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapperID, mapper);
                }
                String path = amapPath.getUrl() + "/" + moduleURI;
                ese.setResultingMediaResource(new RedirectMediaResource(path));
                if (log.isDebug())
                    log.debug("RedirectMediaResource=" + path);
                ese.accept();
                mr = ese.getResultingMediaResource();
                checkRegular = false;
            }
        }
        if (checkRegular) {
            // mediaresource (raw inputstream)
            if ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") == null)) {
                // we remember what to render inline later and return null to indicate
                // inline rendering
                currentURI = moduleURI;
                getFileContent((VFSLeaf) sourceItem);
                fireEvent(ureq, new NewInlineUriEvent(currentURI));
            } else {
                // it is indeed an image or such -> serve it
                mr = new VFSMediaResource((VFSLeaf) sourceItem);
            }
        }
    }
    // -> do a normal inline rendering (reload)
    return mr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Mapper(org.olat.core.dispatcher.mapper.Mapper) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 25 with NotFoundMediaResource

use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.

the class CPPrintMapper method deliverFile.

protected MediaResource deliverFile(HttpServletRequest httpRequest, String path) {
    // if directory gets renamed root becomes null
    if (rootDir == null) {
        return new NotFoundMediaResource();
    }
    VFSLeaf vfsLeaf = null;
    VFSItem vfsItem = rootDir.resolve(path);
    // only files are allowed, but somehow it happened that folders showed up here
    if (vfsItem instanceof VFSLeaf) {
        vfsLeaf = (VFSLeaf) vfsItem;
    } else {
        return new NotFoundMediaResource();
    }
    MediaResource mr;
    // and accept positions of this string at length-3 or length-4
    if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (path.length() - 4)) {
        // set the http content-type and the encoding
        Page page = loadPageWithGuess(vfsLeaf);
        g_encoding = page.getEncoding();
        if (page.isUseLoadedPageString()) {
            mr = prepareMediaResource(httpRequest, page.getPage(), g_encoding, page.getContentType());
        } else {
            // found a new charset other than iso-8859-1, load string with proper encoding
            String content = FileUtils.load(vfsLeaf.getInputStream(), g_encoding);
            mr = prepareMediaResource(httpRequest, content, g_encoding, page.getContentType());
        }
    } else if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_CSS) >= (path.length() - 4)) {
        // set the http content-type and the encoding
        mr = deliverCssFile(vfsLeaf, httpRequest);
    } else if (path.endsWith(FILE_SUFFIX_JS)) {
        // a javascript library
        VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
        // that loads the .js file
        if (jsEncoding != null)
            vmr.setEncoding(jsEncoding);
        else if (g_encoding != null)
            vmr.setEncoding(g_encoding);
        mr = vmr;
    } else {
        // binary data: not .html, not .htm, not .js -> treated as is
        mr = new VFSMediaResource(vfsLeaf);
    }
    return mr;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) StringMediaResource(org.olat.core.gui.media.StringMediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)38 MediaResource (org.olat.core.gui.media.MediaResource)26 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)24 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)24 VFSItem (org.olat.core.util.vfs.VFSItem)16 StringMediaResource (org.olat.core.gui.media.StringMediaResource)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 File (java.io.File)8 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)6 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 GlossaryItemManager (org.olat.core.commons.modules.glossary.GlossaryItemManager)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2