Search in sources :

Example 21 with VFSMediaResource

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

the class FeedManagerImpl method createItemMediaFile.

@Override
public MediaResource createItemMediaFile(OLATResourceable feed, String itemId, String fileName) {
    VFSMediaResource mediaResource = null;
    // Brute force method for fast delivery
    try {
        VFSItem item = feedFileStorage.getOrCreateFeedItemsContainer(feed);
        item = item.resolve(itemId);
        item = item.resolve(MEDIA_DIR);
        item = item.resolve(fileName);
        if (item instanceof VFSLeaf) {
            mediaResource = new VFSMediaResource((VFSLeaf) item);
        }
    } catch (NullPointerException e) {
        log.debug("Media resource could not be created from file: ", fileName);
    }
    return mediaResource;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 22 with VFSMediaResource

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

the class DisclaimerController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == this.downloadLink) {
        ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(this.downloadFile));
        // Prevent "do not press reload" message.
        this.downloadLink.setDirty(false);
    }
}
Also used : VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 23 with VFSMediaResource

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

the class CmdServeThumbnailResource method execute.

@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
        throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
    // extract file
    String path = ureq.getModuleURI();
    MediaResource mr = null;
    VFSLeaf vfsfile = (VFSLeaf) folderComponent.getRootContainer().resolve(path);
    if (vfsfile == null) {
        // double decoding of ++
        vfsfile = (VFSLeaf) FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
    }
    if (vfsfile instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged) vfsfile).getMetaInfo();
        if (info != null && info.isThumbnailAvailable()) {
            VFSLeaf thumbnail = info.getThumbnail(200, 200, false);
            if (thumbnail != null) {
                mr = new VFSMediaResource(thumbnail);
            }
        }
    }
    if (mr == null) {
        mr = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(mr);
    return null;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 24 with VFSMediaResource

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

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

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

the class CPDisplayController method switchToPage.

public void switchToPage(UserRequest ureq, TreeNode tn) {
    String identifierRes = (String) tn.getUserObject();
    OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck("path=" + identifierRes, 0l);
    addToHistory(ureq, ores, null);
    // security check
    if (identifierRes.indexOf("../") != -1)
        throw new AssertException("a non-normalized url encountered in a manifest item:" + identifierRes);
    // Check also for XML resources that use XSLT for rendering
    if (identifierRes.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (identifierRes.length() - 4) || identifierRes.toLowerCase().endsWith(FILE_SUFFIX_XML)) {
        // display html files inline or in an iframe
        if (cpContentCtr != null)
            cpContentCtr.setCurrentURI(identifierRes);
        if (cpComponent != null)
            cpComponent.setCurrentURI(identifierRes);
    } else {
        // initialized. Delegates displaying to the browser (and its plugins).
        if (cpContentCtr != null) {
            cpContentCtr.setCurrentURI(identifierRes);
        } else {
            // if an entry in a manifest points e.g. to a pdf file and the iframe
            // controller has not been initialized display it non-inline
            VFSItem currentItem = rootContainer.resolve(identifierRes);
            MediaResource mr;
            if (currentItem == null || !(currentItem instanceof VFSLeaf))
                mr = new NotFoundMediaResource();
            else
                mr = new VFSMediaResource((VFSLeaf) currentItem);
            ureq.getDispatchResult().setResultingMediaResource(mr);
            // Prevent 'don't reload' warning
            cpTree.setDirty(false);
        }
    }
    updateNextPreviousLink(tn);
    ThreadLocalUserActivityLogger.log(CourseLoggingAction.CP_GET_FILE, getClass(), LoggingResourceable.wrapCpNode(identifierRes));
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) 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)

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