Search in sources :

Example 1 with VFSMediaResource

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

the class DialogElementController method doDownload.

private void doDownload(UserRequest ureq) {
    VFSLeaf file = dialogElmsMgr.getDialogLeaf(element);
    if (file != null) {
        ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(file));
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(element.getFilename()));
    } else {
        ureq.getDispatchResult().setResultingMediaResource(new NotFoundMediaResource());
        logError("No file to discuss: " + element, null);
    }
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 2 with VFSMediaResource

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

the class CheckboxEditController method doDownloadFile.

private void doDownloadFile(UserRequest ureq) {
    VFSContainer container = getFileContainer();
    VFSItem item = container.resolve(checkbox.getFilename());
    if (item instanceof VFSLeaf) {
        VFSMediaResource rsrc = new VFSMediaResource((VFSLeaf) item);
        rsrc.setDownloadable(true);
        ureq.getDispatchResult().setResultingMediaResource(rsrc);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 3 with VFSMediaResource

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

the class ProjectDetailsDisplayController method doFileDelivery.

private void doFileDelivery(UserRequest ureq, final Project project, final CourseEnvironment courseEnv, final CourseNode cNode) {
    // Create a mapper to deliver the auto-download of the file. We have to
    // create a dedicated mapper here
    // and can not reuse the standard briefcase way of file delivering, some
    // very old fancy code
    // Mapper is cleaned up automatically by basic controller
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
    VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
    if (item instanceof VFSLeaf) {
        VFSLeaf attachment = (VFSLeaf) item;
        MediaResource resource = new VFSMediaResource(attachment);
        ureq.getDispatchResult().setResultingMediaResource(resource);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 4 with VFSMediaResource

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

use of org.olat.core.util.vfs.VFSMediaResource 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)

Aggregations

VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)48 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)44 MediaResource (org.olat.core.gui.media.MediaResource)30 VFSItem (org.olat.core.util.vfs.VFSItem)28 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)24 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 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)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)4 Mapper (org.olat.core.dispatcher.mapper.Mapper)4 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)4 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Size (org.olat.core.commons.services.image.Size)2