Search in sources :

Example 51 with MediaResource

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

the class DirectoryController method doBulkdownload.

private void doBulkdownload(UserRequest ureq) {
    MediaResource mdr = new ZippedDirectoryMediaResource(zipName, documentsDir);
    ureq.getDispatchResult().setResultingMediaResource(mdr);
}
Also used : ZippedDirectoryMediaResource(org.olat.fileresource.ZippedDirectoryMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) ZippedDirectoryMediaResource(org.olat.fileresource.ZippedDirectoryMediaResource)

Example 52 with MediaResource

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

the class GoToRecordingController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == downloadLink) {
        String url = recording.getDownloadUrl();
        MediaResource downloadUrl = new RedirectMediaResource(url);
        ureq.getDispatchResult().setResultingMediaResource(downloadUrl);
    }
}
Also used : RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource)

Example 53 with MediaResource

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

the class StaticServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final String pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        // huh? What's this, send not found, don't know what to do here
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else if (pathInfo.indexOf(NOVERSION) != -1) {
        // no version provided - only remove mapper
        String staticRelPath = pathInfo.substring(NOVERSION.length() + 1, pathInfo.length());
        String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
        if (normalizedRelPath == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } else if (normalizedRelPath.endsWith("transparent.gif")) {
            deliverStatic(request, response, pathInfo, normalizedRelPath, true);
        } else {
            deliverStatic(request, response, pathInfo, normalizedRelPath, false);
        }
    } else if (pathInfo.startsWith(STATIC_DIR_NAME)) {
        String staticRelPath = pathInfo.substring(STATIC_DIR_NAME.length() + 1, pathInfo.length());
        // customizing
        CustomStaticFolderManager folderManager = CoreSpringFactory.getImpl(CustomStaticFolderManager.class);
        File file = new File(folderManager.getRootFile(), staticRelPath);
        if (file.exists()) {
            if (file.isDirectory()) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
            } else {
                MediaResource resource = new FileMediaResource(file);
                ServletUtil.serveResource(request, response, resource);
            }
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } else {
        // version provided - remove it
        int start = pathInfo.indexOf("/", 2);
        int end = pathInfo.length();
        if (start <= end) {
            String staticRelPath = pathInfo.substring(start, end);
            String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
            if (normalizedRelPath == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            } else {
                boolean expiration = !Settings.isDebuging();
                deliverStatic(request, response, pathInfo, normalizedRelPath, expiration);
            }
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
Also used : CustomStaticFolderManager(org.olat.admin.sysinfo.manager.CustomStaticFolderManager) FileMediaResource(org.olat.core.gui.media.FileMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) File(java.io.File)

Example 54 with MediaResource

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

the class ResourcesMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    String filename = null;
    MediaResource resource = null;
    try {
        File root = new File(assessmentObjectUri.getPath());
        String href = request.getParameter("href");
        if (StringHelper.containsNonWhitespace(href)) {
            filename = href;
        } else if (StringHelper.containsNonWhitespace(relPath)) {
            filename = relPath;
            if (filename.startsWith("/")) {
                filename = filename.substring(1, filename.length());
            }
        }
        File file = new File(root.getParentFile(), filename);
        if (file.exists()) {
            if (file.getName().endsWith(".xml")) {
                resource = new ForbiddenMediaResource();
            } else if (FileUtils.isInSubDirectory(root.getParentFile(), file)) {
                resource = new FileMediaResource(file, true);
            } else {
                resource = new ForbiddenMediaResource();
            }
        } else if (filename.endsWith("/raw/_noversion_/images/transparent.gif")) {
            String realPath = request.getServletContext().getRealPath("/static/images/transparent.gif");
            resource = new FileMediaResource(new File(realPath), true);
        } else {
            String submissionName = null;
            File storage = null;
            if (filename.startsWith("submissions/")) {
                String submission = filename.substring("submissions/".length());
                int candidateSessionIndex = submission.indexOf('/');
                if (candidateSessionIndex > 0) {
                    submissionName = submission.substring(candidateSessionIndex + 1);
                    if (submissionDirectory != null) {
                        storage = submissionDirectory;
                    } else if (submissionDirectoryMaps != null) {
                        String sessionKey = submission.substring(0, candidateSessionIndex);
                        if (StringHelper.isLong(sessionKey)) {
                            try {
                                storage = submissionDirectoryMaps.get(new Long(sessionKey));
                            } catch (Exception e) {
                                log.error("", e);
                            }
                        }
                    }
                }
            }
            if (storage != null && StringHelper.containsNonWhitespace(submissionName)) {
                File submissionFile = new File(storage, submissionName);
                if (submissionFile.exists()) {
                    resource = new FileMediaResource(submissionFile, true);
                } else {
                    resource = new NotFoundMediaResource();
                }
            } else {
                resource = new NotFoundMediaResource();
            }
        }
    } catch (Exception e) {
        log.error("", e);
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) FileMediaResource(org.olat.core.gui.media.FileMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) ForbiddenMediaResource(org.olat.core.gui.media.ForbiddenMediaResource) File(java.io.File)

Example 55 with MediaResource

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

the class RevisionListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == revisionListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                MediaResource resource;
                if (row < versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    resource = new VFSRevisionMediaResource(version, true);
                } else {
                    resource = new VFSMediaResource((VFSLeaf) versionedFile);
                    ((VFSMediaResource) resource).setDownloadable(true);
                }
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                if (row >= versionedFile.getVersions().getRevisions().size()) {
                    // restore current, do nothing
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
                    String comment = translate("version.restore.comment", new String[] { version.getRevisionNr() });
                    if (versionedFile.getVersions().restore(ureq.getIdentity(), version, comment)) {
                        status = FolderCommandStatus.STATUS_SUCCESS;
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    } else {
                        status = FolderCommandStatus.STATUS_FAILED;
                        showError("version.restore.failed");
                        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                    }
                }
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
            if (CMD_CANCEL.equals(tEvent.getAction())) {
                status = FolderCommandStatus.STATUS_CANCELED;
                fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
            } else {
                List<VFSRevision> selectedVersions = getSelectedRevisions(tEvent.getSelection());
                if (!selectedVersions.isEmpty()) {
                    if (CMD_DELETE.equals(tEvent.getAction())) {
                        String numOfVersionToDelete = Integer.toString(selectedVersions.size());
                        confirmDeleteBoxCtr = activateYesNoDialog(ureq, null, translate("version.confirmDelete", new String[] { numOfVersionToDelete }), confirmDeleteBoxCtr);
                        confirmDeleteBoxCtr.setUserObject(selectedVersions);
                    }
                }
            }
        }
    } else if (source == confirmDeleteBoxCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<VFSRevision> selectedVersions = (List<VFSRevision>) confirmDeleteBoxCtr.getUserObject();
            versionedFile.getVersions().delete(ureq.getIdentity(), selectedVersions);
            status = FolderCommandStatus.STATUS_SUCCESS;
        } else {
            status = FolderCommandStatus.STATUS_CANCELED;
        }
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) TableEvent(org.olat.core.gui.components.table.TableEvent) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

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