Search in sources :

Example 41 with MediaResource

use of org.olat.core.gui.media.MediaResource in project openolat by klemens.

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 42 with MediaResource

use of org.olat.core.gui.media.MediaResource in project openolat by klemens.

the class BinderPageListController method doExportBinderAsCP.

private void doExportBinderAsCP(UserRequest ureq) {
    MediaResource resource = new ExportBinderAsCPResource(binder, ureq, getLocale());
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : ExportBinderAsCPResource(org.olat.modules.portfolio.ui.export.ExportBinderAsCPResource) MediaResource(org.olat.core.gui.media.MediaResource)

Example 43 with MediaResource

use of org.olat.core.gui.media.MediaResource in project openolat by klemens.

the class QuestionListController method doExecuteExport.

private void doExecuteExport(UserRequest ureq, StepsRunContext runContext) {
    ExportFormatOptions format = (ExportFormatOptions) runContext.get("format");
    @SuppressWarnings("unchecked") List<QuestionItemShort> items = (List<QuestionItemShort>) runContext.get("itemsToExport");
    MediaResource mr = qpoolService.export(items, format, getLocale());
    if (mr != null) {
        ureq.getDispatchResult().setResultingMediaResource(mr);
    }
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList) MediaResource(org.olat.core.gui.media.MediaResource)

Example 44 with MediaResource

use of org.olat.core.gui.media.MediaResource in project openolat by klemens.

the class FileArtefactDetailsController method initFileView.

private void initFileView(VFSItem file, UserRequest ureq) {
    vC = createVelocityContainer("fileDetails");
    DownloadComponent downlC = new DownloadComponent("download", (VFSLeaf) file);
    vC.put("download", downlC);
    vC.contextPut("filename", fArtefact.getFilename());
    if (file instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) file).getMetaInfo();
        vC.contextPut("meta", meta);
        // show a preview thumbnail if possible
        if (meta.isThumbnailAvailable()) {
            VFSLeaf thumb = meta.getThumbnail(200, 200, false);
            if (thumb != null) {
                mr = new VFSMediaResource(thumb);
            }
            if (mr != null) {
                String thumbMapper = registerMapper(ureq, new Mapper() {

                    @Override
                    public MediaResource handle(String relPath, HttpServletRequest request) {
                        return mr;
                    }
                });
                vC.contextPut("thumbMapper", thumbMapper);
            }
        }
    }
    if (!readOnlyMode) {
        // allow to delete
        delLink = LinkFactory.createLink("delete.file", vC, this);
        delLink.setUserObject(file);
    }
    viewPanel.setContent(vC);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Mapper(org.olat.core.dispatcher.mapper.Mapper) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) DownloadComponent(org.olat.core.gui.components.download.DownloadComponent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 45 with MediaResource

use of org.olat.core.gui.media.MediaResource in project openolat by klemens.

the class RepositoryEntryRuntimeController method doDownload.

private void doDownload(UserRequest ureq) {
    if (handler == null) {
        StringBuilder sb = new StringBuilder(translate("error.download"));
        sb.append(": No download handler for repository entry: ").append(re.getKey());
        showError(sb.toString());
        return;
    }
    RepositoryEntry entry = repositoryService.loadByKey(re.getKey());
    OLATResourceable ores = entry.getOlatResource();
    if (ores == null) {
        showError("error.download");
        return;
    }
    boolean isAlreadyLocked = handler.isLocked(ores);
    try {
        lockResult = handler.acquireLock(ores, ureq.getIdentity());
        if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            MediaResource mr = handler.getAsMediaResource(ores, false);
            if (mr != null) {
                repositoryService.incrementDownloadCounter(entry);
                ureq.getDispatchResult().setResultingMediaResource(mr);
            } else {
                showError("error.export");
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        } else if (lockResult != null && lockResult.isSuccess() && isAlreadyLocked) {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked.bySameUser", fullName);
            // invalid lock, it was already locked
            lockResult = null;
        } else {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked", fullName);
        }
    } finally {
        if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            handler.releaseLock(lockResult);
            lockResult = null;
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryEntry(org.olat.repository.RepositoryEntry)

Aggregations

MediaResource (org.olat.core.gui.media.MediaResource)141 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)36 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)32 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)30 Identity (org.olat.core.id.Identity)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 File (java.io.File)16 ArrayList (java.util.ArrayList)16 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)16 IOException (java.io.IOException)13 FileMediaResource (org.olat.core.gui.media.FileMediaResource)12 List (java.util.List)10 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)8 AssertException (org.olat.core.logging.AssertException)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 InputStream (java.io.InputStream)6 OLATResourceable (org.olat.core.id.OLATResourceable)6