Search in sources :

Example 91 with MediaResource

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

the class StaticServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final String pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        // huh? What's this, send not found, don't know what to do here
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else if (pathInfo.indexOf(NOVERSION) != -1) {
        // no version provided - only remove mapper
        String staticRelPath = pathInfo.substring(NOVERSION.length() + 1, pathInfo.length());
        String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
        if (normalizedRelPath == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } else if (normalizedRelPath.endsWith("transparent.gif")) {
            deliverStatic(request, response, pathInfo, normalizedRelPath, true);
        } else {
            deliverStatic(request, response, pathInfo, normalizedRelPath, false);
        }
    } else if (pathInfo.startsWith(STATIC_DIR_NAME)) {
        String staticRelPath = pathInfo.substring(STATIC_DIR_NAME.length() + 1, pathInfo.length());
        // customizing
        CustomStaticFolderManager folderManager = CoreSpringFactory.getImpl(CustomStaticFolderManager.class);
        File file = new File(folderManager.getRootFile(), staticRelPath);
        if (file.exists()) {
            if (file.isDirectory()) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
            } else {
                MediaResource resource = new FileMediaResource(file);
                ServletUtil.serveResource(request, response, resource);
            }
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } else {
        // version provided - remove it
        int start = pathInfo.indexOf("/", 2);
        int end = pathInfo.length();
        if (start <= end) {
            String staticRelPath = pathInfo.substring(start, end);
            String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
            if (normalizedRelPath == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            } else {
                boolean expiration = !Settings.isDebuging();
                deliverStatic(request, response, pathInfo, normalizedRelPath, expiration);
            }
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
Also used : CustomStaticFolderManager(org.olat.admin.sysinfo.manager.CustomStaticFolderManager) FileMediaResource(org.olat.core.gui.media.FileMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) File(java.io.File)

Example 92 with MediaResource

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

the class CPPrintMapper method deliverCompositePage.

private MediaResource deliverCompositePage(HttpServletRequest request) {
    List<NekoHtmlPageHandler> parsedPages = composePrintPage(selectedNodeIds);
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>");
    for (NekoHtmlPageHandler page : parsedPages) {
        sb.append("<!-- Header of -->");
        sb.append(page.getHeader()).append("\n\n");
    }
    injectJavascriptAndCss(sb);
    sb.append("</head><body onload='window.focus();window.print()'>");
    for (NekoHtmlPageHandler page : parsedPages) {
        if (page.isEmpty()) {
            String title = page.getTitle();
            if (StringHelper.containsNonWhitespace(title)) {
                int level = page.getLevel() + 1;
                level = Math.min(level, 6);
                sb.append("<h").append(level).append(">").append(page.getTitle()).append("</h").append(level).append(">");
            }
        } else {
            bodyDecorator(page, sb);
        }
    }
    sb.append("</body></html>");
    MediaResource mr = prepareMediaResource(request, sb.toString(), g_encoding, "text/html");
    return mr;
}
Also used : 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)

Example 93 with MediaResource

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

Example 94 with MediaResource

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

the class QuestionListController method doExecuteExport.

private void doExecuteExport(UserRequest ureq, StepsRunContext runContext) {
    ExportFormatOptions format = (ExportFormatOptions) runContext.get("format");
    @SuppressWarnings("unchecked") List<QuestionItemShort> items = (List<QuestionItemShort>) runContext.get("itemsToExport");
    MediaResource mr = qpoolService.export(items, format, getLocale());
    if (mr != null) {
        ureq.getDispatchResult().setResultingMediaResource(mr);
    }
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList) MediaResource(org.olat.core.gui.media.MediaResource)

Example 95 with MediaResource

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

the class BinderPageListController method doExportBinderAsPdf.

private void doExportBinderAsPdf(UserRequest ureq) {
    MediaResource resource = new ExportBinderAsPDFResource(binder, ureq, getLocale());
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : ExportBinderAsPDFResource(org.olat.modules.portfolio.ui.export.ExportBinderAsPDFResource) MediaResource(org.olat.core.gui.media.MediaResource)

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