Search in sources :

Example 41 with VFSMediaResource

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

the class IFrameDeliveryMapper method deliverFile.

protected MediaResource deliverFile(HttpServletRequest httpRequest, String path, boolean isPopUp) {
    MediaResource mr;
    VFSLeaf vfsLeaf = null;
    VFSItem vfsItem = null;
    // if directory gets renamed root becomes null
    if (rootDir == null) {
        return new NotFoundMediaResource();
    } else {
        vfsItem = rootDir.resolve(path);
    }
    // only files are allowed, but somehow it happened that folders showed up here
    if (vfsItem instanceof VFSLeaf) {
        vfsLeaf = (VFSLeaf) rootDir.resolve(path);
    } else {
        mr = new NotFoundMediaResource();
    }
    if (vfsLeaf == null) {
        mr = new NotFoundMediaResource();
    } else {
        // 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);
            String pageEncoding = page.getEncoding();
            if (page.isUseLoadedPageString()) {
                mr = prepareMediaResource(httpRequest, page.getPage(), pageEncoding, page.getContentType(), isPopUp);
            } else {
                // found a new charset other than iso-8859-1, load string with proper encoding
                String content = FileUtils.load(vfsLeaf.getInputStream(), pageEncoding);
                mr = prepareMediaResource(httpRequest, content, pageEncoding, page.getContentType(), isPopUp);
            }
            if (contentEncoding == null) {
                contentEncoding = pageEncoding;
            }
        } 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 (contentEncoding != null) {
                vmr.setEncoding(contentEncoding);
            }
            mr = vmr;
        } else {
            // binary data: not .html, not .htm, not .js -> treated as is
            VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
            String filename = vfsLeaf.getName();
            // This is to prevent the login prompt in Excel, Word and PowerPoint
            if (filename.endsWith(".xlsx") || filename.endsWith(".pptx") || filename.endsWith(".docx")) {
                vmr.setDownloadable(true);
            }
            mr = vmr;
        }
    }
    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) StringMediaResource(org.olat.core.gui.media.StringMediaResource) 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 42 with VFSMediaResource

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

the class MailAttachmentMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (relPath != null && relPath.indexOf(ATTACHMENT_CONTEXT) >= 0) {
        int startIndex = relPath.indexOf(ATTACHMENT_CONTEXT);
        int endIndex = relPath.indexOf("/", startIndex + ATTACHMENT_CONTEXT.length());
        if (startIndex >= 0 && endIndex > startIndex) {
            String attachmentKey = relPath.substring(startIndex + ATTACHMENT_CONTEXT.length(), endIndex);
            try {
                Long key = new Long(attachmentKey);
                VFSLeaf datas = mailManager.getAttachmentDatas(key);
                MediaResource resource = new VFSMediaResource(datas);
                return resource;
            } catch (NumberFormatException e) {
                return new NotFoundMediaResource();
            }
        }
    }
    return new NotFoundMediaResource();
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 43 with VFSMediaResource

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

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 44 with VFSMediaResource

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

the class DialogElementListController method doFileDelivery.

/**
 * deliver the selected file and show in a popup
 *
 * @param ureq
 * @param command
 */
private void doFileDelivery(UserRequest ureq, DialogElement element) {
    VFSContainer forumContainer = dialogElementsManager.getDialogContainer(element);
    List<VFSItem> items = forumContainer.getItems(new VFSLeafFilter());
    if (items.size() > 0 && items.get(0) instanceof VFSLeaf) {
        VFSLeaf vl = (VFSLeaf) items.get(0);
        ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(vl));
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(vl.getName()));
    } else {
        logError("No file to discuss: " + forumContainer, null);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 45 with VFSMediaResource

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

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)

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