Search in sources :

Example 6 with FileMediaResource

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

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 7 with FileMediaResource

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

the class ResourcesMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    String filename = null;
    MediaResource resource = null;
    try {
        File root = new File(assessmentObjectUri.getPath());
        String href = request.getParameter("href");
        if (StringHelper.containsNonWhitespace(href)) {
            filename = href;
        } else if (StringHelper.containsNonWhitespace(relPath)) {
            filename = relPath;
            if (filename.startsWith("/")) {
                filename = filename.substring(1, filename.length());
            }
        }
        File file = new File(root.getParentFile(), filename);
        if (file.exists()) {
            if (file.getName().endsWith(".xml")) {
                resource = new ForbiddenMediaResource();
            } else if (FileUtils.isInSubDirectory(root.getParentFile(), file)) {
                resource = new FileMediaResource(file, true);
            } else {
                resource = new ForbiddenMediaResource();
            }
        } else if (filename.endsWith("/raw/_noversion_/images/transparent.gif")) {
            String realPath = request.getServletContext().getRealPath("/static/images/transparent.gif");
            resource = new FileMediaResource(new File(realPath), true);
        } else {
            String submissionName = null;
            File storage = null;
            if (filename.startsWith("submissions/")) {
                String submission = filename.substring("submissions/".length());
                int candidateSessionIndex = submission.indexOf('/');
                if (candidateSessionIndex > 0) {
                    submissionName = submission.substring(candidateSessionIndex + 1);
                    if (submissionDirectory != null) {
                        storage = submissionDirectory;
                    } else if (submissionDirectoryMaps != null) {
                        String sessionKey = submission.substring(0, candidateSessionIndex);
                        if (StringHelper.isLong(sessionKey)) {
                            try {
                                storage = submissionDirectoryMaps.get(new Long(sessionKey));
                            } catch (Exception e) {
                                log.error("", e);
                            }
                        }
                    }
                }
            }
            if (storage != null && StringHelper.containsNonWhitespace(submissionName)) {
                File submissionFile = new File(storage, submissionName);
                if (submissionFile.exists()) {
                    resource = new FileMediaResource(submissionFile, true);
                } else {
                    resource = new NotFoundMediaResource();
                }
            } else {
                resource = new NotFoundMediaResource();
            }
        }
    } catch (Exception e) {
        log.error("", e);
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) File(java.io.File)

Example 8 with FileMediaResource

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

the class LogoMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    File logo = layoutModule.getLogo();
    File dir = layoutModule.getLogoDirectory();
    File scaledLogo = new File(dir, relPath);
    if (lastModified < logo.lastModified() || !scaledLogo.exists()) {
        ImageService imageService = CoreSpringFactory.getImpl(ImageService.class);
        File logo1x = new File(dir, "oo-logo@1x.png");
        imageService.scaleImage(logo, "png", logo1x, 104, 50, false);
        File logo2x = new File(dir, "oo-logo@2x.png");
        imageService.scaleImage(logo, "png", logo2x, 208, 50, false);
    }
    return new FileMediaResource(scaledLogo);
}
Also used : FileMediaResource(org.olat.core.gui.media.FileMediaResource) File(java.io.File) ImageService(org.olat.core.commons.services.image.ImageService)

Example 9 with FileMediaResource

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

the class DisplayPortraitManager method getPortrait.

/**
 * @param identity
 * @return imageResource portrait
 */
public MediaResource getPortrait(File uploadDir, String portraitName) {
    FileMediaResource imageResource = null;
    File imgFile = new File(uploadDir, portraitName);
    if (imgFile.exists()) {
        imageResource = new FileMediaResource(imgFile);
        imageResource.setCacheControlDuration(ServletUtil.CACHE_ONE_DAY);
    }
    return imageResource;
}
Also used : FileMediaResource(org.olat.core.gui.media.FileMediaResource) File(java.io.File)

Example 10 with FileMediaResource

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

the class LogoMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    File logo = layoutModule.getLogo();
    File dir = layoutModule.getLogoDirectory();
    File scaledLogo = new File(dir, relPath);
    if (lastModified < logo.lastModified() || !scaledLogo.exists()) {
        ImageService imageService = CoreSpringFactory.getImpl(ImageService.class);
        File logo1x = new File(dir, "oo-logo@1x.png");
        imageService.scaleImage(logo, "png", logo1x, 104, 50, false);
        File logo2x = new File(dir, "oo-logo@2x.png");
        imageService.scaleImage(logo, "png", logo2x, 208, 50, false);
    }
    return new FileMediaResource(scaledLogo);
}
Also used : FileMediaResource(org.olat.core.gui.media.FileMediaResource) File(java.io.File) ImageService(org.olat.core.commons.services.image.ImageService)

Aggregations

FileMediaResource (org.olat.core.gui.media.FileMediaResource)16 File (java.io.File)14 MediaResource (org.olat.core.gui.media.MediaResource)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 CustomStaticFolderManager (org.olat.admin.sysinfo.manager.CustomStaticFolderManager)2 SinglePageController (org.olat.core.commons.modules.singlepage.SinglePageController)2 ImageService (org.olat.core.commons.services.image.ImageService)2 IFrameDisplayController (org.olat.core.gui.control.generic.iframe.IFrameDisplayController)2 ForbiddenMediaResource (org.olat.core.gui.media.ForbiddenMediaResource)2 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)2 ZippedDirectoryMediaResource (org.olat.fileresource.ZippedDirectoryMediaResource)2