Search in sources :

Example 86 with MediaResource

use of org.olat.core.gui.media.MediaResource 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 87 with MediaResource

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

the class MediaResourceMapper method handle.

public MediaResource handle(String relPath, HttpServletRequest request) {
    if (mediaResource == null)
        throw new AssertException("mr already served, relPath =" + relPath + ",");
    MediaResource r = mediaResource;
    mediaResource = null;
    return r;
}
Also used : AssertException(org.olat.core.logging.AssertException) MediaResource(org.olat.core.gui.media.MediaResource)

Example 88 with MediaResource

use of org.olat.core.gui.media.MediaResource 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 89 with MediaResource

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

the class QTI21AssessmentTestStatisticsController method doDownloadRawData.

private void doDownloadRawData(UserRequest ureq) {
    String label;
    if (courseNode == null) {
        label = StringHelper.transformDisplayNameToFileSystemName(resourceResult.getTestEntry().getDisplayname());
    } else {
        label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName());
    }
    label += "_" + Formatter.formatDatetimeFilesystemSave(new Date()) + ".xlsx";
    MediaResource resource = new QTI21StatisticsResource(resourceResult, label, getLocale());
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : MediaResource(org.olat.core.gui.media.MediaResource) StatisticFormatter.getModeString(org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString) Date(java.util.Date)

Example 90 with MediaResource

use of org.olat.core.gui.media.MediaResource 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)

Aggregations

MediaResource (org.olat.core.gui.media.MediaResource)141 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)36 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)32 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)30 Identity (org.olat.core.id.Identity)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 File (java.io.File)16 ArrayList (java.util.ArrayList)16 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)16 IOException (java.io.IOException)13 FileMediaResource (org.olat.core.gui.media.FileMediaResource)12 List (java.util.List)10 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)8 AssertException (org.olat.core.logging.AssertException)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 InputStream (java.io.InputStream)6 OLATResourceable (org.olat.core.id.OLATResourceable)6