Search in sources :

Example 1 with FeedManager

use of org.olat.modules.webFeed.manager.FeedManager in project OpenOLAT by OpenOLAT.

the class FeedMediaDispatcher method deliverFile.

/**
 * Dispatch and deliver the requested file given in the path.
 *
 * @param request
 * @param response
 * @param feed
 * @param path
 */
private void deliverFile(HttpServletRequest request, HttpServletResponse response, OLATResourceable feed, Path path) {
    // OLAT-5243 related: deliverFile can last arbitrary long, which can cause the open db connection to timeout and cause errors,
    // hence we need to do an intermediateCommit here
    DBFactory.getInstance().intermediateCommit();
    // Create the resource to be delivered
    MediaResource resource = null;
    FeedManager manager = FeedManager.getInstance();
    if (path.isFeedType()) {
        // Only create feed if modified. Send not modified response else.
        Identity identity = getIdentity(path.getIdentityKey());
        long sinceModifiedMillis = request.getDateHeader("If-Modified-Since");
        Feed feedLight = manager.loadFeed(feed);
        long lastModifiedMillis = -1;
        if (feedLight != null) {
            lastModifiedMillis = feedLight.getLastModified().getTime();
        }
        if (sinceModifiedMillis >= (lastModifiedMillis / 1000L) * 1000L) {
            // Send not modified response
            response.setDateHeader("last-modified", lastModifiedMillis);
            try {
                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            } catch (IOException e) {
                // Send not modified failed
                log.error("Send not modified failed", e);
                return;
            }
        } else {
            resource = manager.createFeedFile(feed, identity, path.getCourseId(), path.getNodeId());
        }
    } else if (path.isItemType()) {
        resource = manager.createItemMediaFile(feed, path.getItemId(), path.getItemFileName());
    } else if (path.isIconType()) {
        Size thumbnailSize = null;
        String thumbnail = request.getParameter("thumbnail");
        if (StringHelper.containsNonWhitespace(thumbnail)) {
            thumbnailSize = Size.parseString(thumbnail);
        }
        VFSLeaf resourceFile = manager.createFeedMediaFile(feed, path.getIconFileName(), thumbnailSize);
        if (resourceFile != null) {
            resource = new VFSMediaResource(resourceFile);
        }
    }
    // Eventually deliver the requested resource
    ServletUtil.serveResource(request, response, resource);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FeedManager(org.olat.modules.webFeed.manager.FeedManager) Size(org.olat.core.commons.services.image.Size) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) Feed(org.olat.modules.webFeed.Feed) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 2 with FeedManager

use of org.olat.modules.webFeed.manager.FeedManager in project openolat by klemens.

the class FeedMediaDispatcher method deliverFile.

/**
 * Dispatch and deliver the requested file given in the path.
 *
 * @param request
 * @param response
 * @param feed
 * @param path
 */
private void deliverFile(HttpServletRequest request, HttpServletResponse response, OLATResourceable feed, Path path) {
    // OLAT-5243 related: deliverFile can last arbitrary long, which can cause the open db connection to timeout and cause errors,
    // hence we need to do an intermediateCommit here
    DBFactory.getInstance().intermediateCommit();
    // Create the resource to be delivered
    MediaResource resource = null;
    FeedManager manager = FeedManager.getInstance();
    if (path.isFeedType()) {
        // Only create feed if modified. Send not modified response else.
        Identity identity = getIdentity(path.getIdentityKey());
        long sinceModifiedMillis = request.getDateHeader("If-Modified-Since");
        Feed feedLight = manager.loadFeed(feed);
        long lastModifiedMillis = -1;
        if (feedLight != null) {
            lastModifiedMillis = feedLight.getLastModified().getTime();
        }
        if (sinceModifiedMillis >= (lastModifiedMillis / 1000L) * 1000L) {
            // Send not modified response
            response.setDateHeader("last-modified", lastModifiedMillis);
            try {
                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            } catch (IOException e) {
                // Send not modified failed
                log.error("Send not modified failed", e);
                return;
            }
        } else {
            resource = manager.createFeedFile(feed, identity, path.getCourseId(), path.getNodeId());
        }
    } else if (path.isItemType()) {
        resource = manager.createItemMediaFile(feed, path.getItemId(), path.getItemFileName());
    } else if (path.isIconType()) {
        Size thumbnailSize = null;
        String thumbnail = request.getParameter("thumbnail");
        if (StringHelper.containsNonWhitespace(thumbnail)) {
            thumbnailSize = Size.parseString(thumbnail);
        }
        VFSLeaf resourceFile = manager.createFeedMediaFile(feed, path.getIconFileName(), thumbnailSize);
        if (resourceFile != null) {
            resource = new VFSMediaResource(resourceFile);
        }
    }
    // Eventually deliver the requested resource
    ServletUtil.serveResource(request, response, resource);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FeedManager(org.olat.modules.webFeed.manager.FeedManager) Size(org.olat.core.commons.services.image.Size) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) Feed(org.olat.modules.webFeed.Feed) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

IOException (java.io.IOException)2 Size (org.olat.core.commons.services.image.Size)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Identity (org.olat.core.id.Identity)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)2 Feed (org.olat.modules.webFeed.Feed)2 FeedManager (org.olat.modules.webFeed.manager.FeedManager)2