Search in sources :

Example 96 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class MessageListController method doDeliverAttachment.

private void doDeliverAttachment(UserRequest ureq, String cmd) {
    MediaResource res = null;
    try {
        int index = cmd.lastIndexOf("_");
        String attachmentPosition = cmd.substring(cmd.indexOf("_") + 1, index);
        String messageKey = cmd.substring(index + 1);
        int position = Integer.parseInt(attachmentPosition);
        Long key = new Long(messageKey);
        for (MessageView view : backupViews) {
            if (view.getKey().equals(key)) {
                List<VFSItem> attachments = view.getAttachments();
                // velocity counter start with 1
                VFSLeaf attachment = (VFSLeaf) attachments.get(position - 1);
                VFSMediaResource fileResource = new VFSMediaResource(attachment);
                // prevent XSS attack
                fileResource.setDownloadable(true);
                res = fileResource;
            }
        }
    } catch (Exception e) {
        logError("Cannot deliver message attachment", e);
    }
    if (res == null) {
        res = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(res);
}
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) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 97 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class ForumWebService method attachToPost.

protected Response attachToPost(Message mess, String filename, InputStream file, HttpServletRequest request) {
    Identity identity = getIdentity(request);
    if (identity == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identity.equalsByPersistableKey(mess.getCreator())) {
        if (mess.getModifier() == null || !identity.equalsByPersistableKey(mess.getModifier())) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
    VFSItem item = container.resolve(filename);
    VFSLeaf attachment = null;
    if (item == null) {
        attachment = container.createChildLeaf(filename);
    } else {
        filename = VFSManager.rename(container, filename);
        if (filename == null) {
            return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
        }
        attachment = container.createChildLeaf(filename);
    }
    OutputStream out = attachment.getOutputStream(false);
    try {
        IOUtils.copy(file, out);
    } catch (IOException e) {
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    } finally {
        FileUtils.closeSafely(out);
        FileUtils.closeSafely(file);
    }
    return Response.ok().build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity)

Example 98 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf 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 99 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class VideoDisplayController method reloadVideoPoster.

/**
 * Reload video poster when the video poster has been exchanged
 */
protected void reloadVideoPoster() {
    // Check for null-value posters
    VFSLeaf poster = videoManager.getPosterframe(entry.getOlatResource());
    mainVC.contextPut("usePoster", Boolean.valueOf(poster != null && poster.getSize() > 0));
    // avoid browser caching of poster resource
    mainVC.contextPut("nocache", "?t=" + CodeHelper.getRAMUniqueID());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf)

Example 100 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class VideoDisplayController method reloadVideo.

/**
 * Reload the video, e.g. when new captions or transcoded versions are available
 * @param ureq
 * @param currentTime The start time in seconds (optional)
 */
protected void reloadVideo(UserRequest ureq) {
    // load video as VFSLeaf
    VFSLeaf video = videoManager.getMasterVideoFile(entry.getOlatResource());
    loadVideo(ureq, video);
    mainVC.contextPut("addForceReload", "?t=" + CodeHelper.getRAMUniqueID());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34