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;
}
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);
}
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);
}
}
}
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);
}
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();
}
Aggregations