Search in sources :

Example 61 with MediaResource

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

the class QTIEditorMainController method doExportDocx.

private void doExportDocx(UserRequest ureq) {
    AssessmentNode rootNode = (AssessmentNode) menuTreeModel.getRootNode();
    VFSContainer editorContainer = qtiPackage.getBaseDir();
    exportLatch = new CountDownLatch(1);
    MediaResource mr = new QTIWordExport(rootNode, editorContainer, getLocale(), "UTF-8", exportLatch);
    ureq.getDispatchResult().setResultingMediaResource(mr);
}
Also used : AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) MediaResource(org.olat.core.gui.media.MediaResource) CountDownLatch(java.util.concurrent.CountDownLatch) QTIWordExport(org.olat.ims.qti.export.QTIWordExport)

Example 62 with MediaResource

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

the class PageRunController method doExportBinderAsPdf.

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

Example 63 with MediaResource

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

the class CourseWebService method getRepoFileById.

/**
 * Export the course
 * @response.representation.200.mediaType application/zip
 * @response.representation.200.doc The course as a ZIP file
 * @response.representation.401.doc Not authorized to export the course
 * @response.representation.404.doc The course not found
 * @return It returns the <code>CourseVO</code> object representing the course.
 */
@GET
@Path("file")
@Produces({ "application/zip", MediaType.APPLICATION_OCTET_STREAM })
public Response getRepoFileById(@Context HttpServletRequest request) {
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    RepositoryHandler typeToDownload = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    if (typeToDownload == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(request);
    boolean canDownload = re.getCanDownload() && typeToDownload.supportsDownload();
    if (isAdmin(request) || RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identity, re)) {
        canDownload = true;
    } else if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    if (!canDownload) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResource ores = OLATResourceManager.getInstance().findResourceable(re.getOlatResource());
    if (ores == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    boolean isAlreadyLocked = typeToDownload.isLocked(ores);
    LockResult lockResult = null;
    try {
        lockResult = typeToDownload.acquireLock(ores, identity);
        if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            MediaResource mr = typeToDownload.getAsMediaResource(ores, false);
            if (mr != null) {
                rs.incrementDownloadCounter(re);
                // success
                return Response.ok(mr.getInputStream()).cacheControl(cc).build();
            } else {
                return Response.serverError().status(Status.NO_CONTENT).build();
            }
        } else {
            return Response.serverError().status(Status.CONFLICT).build();
        }
    } finally {
        if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            typeToDownload.releaseLock(lockResult);
        }
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) OLATResource(org.olat.resource.OLATResource) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 64 with MediaResource

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

the class UserAvatarMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    MediaResource rsrc = null;
    if (relPath != null && relPath.endsWith(POSTFIX_LARGE) || relPath.endsWith(POSTFIX_SMALL)) {
        if (relPath.startsWith("/")) {
            relPath = relPath.substring(1, relPath.length());
        }
        int endKeyIndex = relPath.indexOf('/');
        if (endKeyIndex > 0) {
            String idKey = relPath.substring(0, endKeyIndex);
            Long key = Long.parseLong(idKey);
            String username = userManager.getUsername(key);
            if (useLarge) {
                rsrc = portraitManager.getBigPortraitResource(username);
            } else {
                rsrc = portraitManager.getSmallPortraitResource(username);
                if (rsrc == null) {
                    rsrc = portraitManager.getBigPortraitResource(username);
                }
            }
        }
    }
    return rsrc;
}
Also used : MediaResource(org.olat.core.gui.media.MediaResource)

Example 65 with MediaResource

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

the class FeedManagerImpl method createFeedFile.

@Override
public MediaResource createFeedFile(OLATResourceable ores, Identity identity, Long courseId, String nodeId) {
    MediaResource media = null;
    Feed feed = loadFeed(ores);
    if (feed != null) {
        SyndFeed rssFeed = new RSSFeed(feed, identity, courseId, nodeId);
        media = new SyndFeedMediaResource(rssFeed);
    }
    return media;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) RSSFeed(org.olat.modules.webFeed.RSSFeed) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) SyndFeedMediaResource(org.olat.modules.webFeed.SyndFeedMediaResource) SyndFeedMediaResource(org.olat.modules.webFeed.SyndFeedMediaResource) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) RSSFeed(org.olat.modules.webFeed.RSSFeed)

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