use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class CatalogEntryImageMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
if (relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
}
VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
VFSItem image = categoryResources.resolve(relPath);
MediaResource resource = null;
if (image instanceof VFSLeaf) {
if (image instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) image).getMetaInfo();
if (info != null) {
VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
if (thumbnail != null) {
resource = new VFSMediaResource(thumbnail);
}
}
}
if (resource == null) {
resource = new VFSMediaResource((VFSLeaf) image);
}
} else {
resource = new NotFoundMediaResource();
}
return resource;
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class CustomDBController method exportDb.
private void exportDb(UserRequest ureq, final String category) {
final ICourse course = CourseFactory.loadCourse(courseKey);
String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
MediaResource export = new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
// create the headers
Row headerRow = exportSheet.newRow();
headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
for (CourseDBEntry entry : content) {
User user = entry.getIdentity().getUser();
String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
Row dataRow = exportSheet.newRow();
dataRow.addCell(0, entry.getCategory(), null);
dataRow.addCell(1, name, null);
if (StringHelper.containsNonWhitespace(entry.getName())) {
dataRow.addCell(2, entry.getName(), null);
}
if (entry.getValue() != null) {
dataRow.addCell(3, entry.getValue().toString(), null);
}
}
} catch (IOException e) {
logError("", e);
}
}
};
ureq.getDispatchResult().setResultingMediaResource(export);
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.core.gui.media.MediaResource in project openolat by klemens.
the class VFSContainerMapper method handle.
public MediaResource handle(String relPath, HttpServletRequest request) {
VFSItem vfsItem = container.resolve(relPath);
MediaResource mr;
if (vfsItem == null || !(vfsItem instanceof VFSLeaf)) {
mr = new NotFoundMediaResource();
} else {
mr = new VFSMediaResource((VFSLeaf) vfsItem);
}
return mr;
}
use of org.olat.core.gui.media.MediaResource in project openolat by klemens.
the class CustomDBController method exportDb.
private void exportDb(UserRequest ureq, final String category) {
final ICourse course = CourseFactory.loadCourse(courseKey);
String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
MediaResource export = new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
// create the headers
Row headerRow = exportSheet.newRow();
headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
for (CourseDBEntry entry : content) {
User user = entry.getIdentity().getUser();
String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
Row dataRow = exportSheet.newRow();
dataRow.addCell(0, entry.getCategory(), null);
dataRow.addCell(1, name, null);
if (StringHelper.containsNonWhitespace(entry.getName())) {
dataRow.addCell(2, entry.getName(), null);
}
if (entry.getValue() != null) {
dataRow.addCell(3, entry.getValue().toString(), null);
}
}
} catch (IOException e) {
logError("", e);
}
}
};
ureq.getDispatchResult().setResultingMediaResource(export);
}
Aggregations