Search in sources :

Example 76 with MediaResource

use of org.olat.core.gui.media.MediaResource 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 77 with MediaResource

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

the class MapperDispatcher method execute.

/**
 * @param hreq
 * @param hres
 */
@Override
public void execute(HttpServletRequest hreq, HttpServletResponse hres) throws IOException {
    String pathInfo = DispatcherModule.subtractContextPath(hreq);
    // e.g. non-cacheable: 	23423/bla/blu.html
    // e.g. cacheable: 		my.mapper.path/bla/blu.html
    String subInfo = pathInfo.substring(DispatcherModule.PATH_MAPPED.length());
    int slashPos = subInfo.indexOf('/');
    String smappath;
    if (slashPos == -1) {
        smappath = subInfo;
    } else {
        smappath = subInfo.substring(0, slashPos);
    }
    // legacy???
    DBFactory.getInstance().commitAndCloseSession();
    // e.g. non-cacheable: 	23423
    // e.g. cacheable: 		my.mapper.path
    UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(hreq);
    Mapper m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(usess, smappath);
    if (m == null) {
        // an anonymous mapper?
        m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(null, smappath);
        if (m == null) {
            logWarn("Call to mapped resource, but mapper does not exist for path::" + smappath, null);
            DispatcherModule.sendNotFound(pathInfo, hres);
            return;
        }
    }
    String mod = slashPos > 0 ? subInfo.substring(slashPos) : "";
    if (mod.indexOf("..") != -1) {
        logWarn("Illegal mapper path::" + mod + " contains '..'", null);
        DispatcherModule.sendForbidden(pathInfo, hres);
        return;
    }
    // /bla/blu.html
    MediaResource mr = m.handle(mod, hreq);
    ServletUtil.serveResource(hreq, hres, mr);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) MediaResource(org.olat.core.gui.media.MediaResource)

Example 78 with MediaResource

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

the class DeletedFileListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deletedFilesListTableCtr) {
        if (event instanceof TableEvent) {
            TableEvent tEvent = (TableEvent) event;
            int row = tEvent.getRowId();
            if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                MediaResource resource = new VFSRevisionMediaResource(version, true);
                ureq.getDispatchResult().setResultingMediaResource(resource);
            } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
                VFSRevision version = getLastRevision(deletedFiles.get(row));
                if (VersionsManager.getInstance().restore(container, version)) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                // ERROR
                }
            }
        } 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 if (CMD_RESTORE.equals(tEvent.getAction())) {
                List<VFSRevision> selectedRevisions = getSelectedRevisions(tEvent.getSelection());
                boolean allOk = true;
                for (VFSRevision revision : selectedRevisions) {
                    allOk &= VersionsManager.getInstance().restore(container, revision);
                }
                if (allOk) {
                    status = FolderCommandStatus.STATUS_SUCCESS;
                    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
                } else {
                    status = FolderCommandStatus.STATUS_FAILED;
                }
            } else if (CMD_DELETE.equals(tEvent.getAction())) {
                List<Versions> versionsToDelete = getSelectedVersions(tEvent.getSelection());
                if (!versionsToDelete.isEmpty()) {
                    String msg = translate("version.del.confirm") + "<p>" + renderVersionsAsHtml(versionsToDelete) + "</p>";
                    // create dialog controller
                    dialogCtr = activateYesNoDialog(ureq, translate("version.del.header"), msg, dialogCtr);
                    dialogCtr.setUserObject(versionsToDelete);
                }
            }
        }
    } else if (source == dialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            @SuppressWarnings("unchecked") List<Versions> versionsToDelete = (List<Versions>) dialogCtr.getUserObject();
            VersionsManager.getInstance().deleteVersions(versionsToDelete);
            status = FolderCommandStatus.STATUS_SUCCESS;
            fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
        }
    }
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) 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) VFSRevisionMediaResource(org.olat.core.util.vfs.VFSRevisionMediaResource) ArrayList(java.util.ArrayList) List(java.util.List)

Example 79 with MediaResource

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

the class FlexiTableElementImpl method doExport.

private void doExport(UserRequest ureq) {
    // ensure the all rows are loaded to export
    if (dataSource != null) {
        if (dataModel instanceof FlexiTableDataSource) {
            ((FlexiTableDataSource<?>) dataModel).load(getSearchText(), getSelectedFilters(), getConditionalQueries(), 0, -1, orderBy);
        } else {
            dataSource.load(getSearchText(), getSelectedFilters(), getConditionalQueries(), 0, -1, orderBy);
        }
    }
    MediaResource resource;
    if (dataModel instanceof ExportableFlexiTableDataModel) {
        resource = ((ExportableFlexiTableDataModel) dataModel).export(component);
    } else {
        ExportableFlexiTableDataModelDelegate exporter = new ExportableFlexiTableDataModelDelegate();
        resource = exporter.export(component, getTranslator());
    }
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : MediaResource(org.olat.core.gui.media.MediaResource)

Example 80 with MediaResource

use of org.olat.core.gui.media.MediaResource 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)

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