use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.
the class DialogElementController method doDownload.
private void doDownload(UserRequest ureq) {
VFSLeaf file = dialogElmsMgr.getDialogLeaf(element);
if (file != null) {
ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(file));
ThreadLocalUserActivityLogger.log(CourseLoggingAction.DIALOG_ELEMENT_FILE_DOWNLOADED, getClass(), LoggingResourceable.wrapBCFile(element.getFilename()));
} else {
ureq.getDispatchResult().setResultingMediaResource(new NotFoundMediaResource());
logError("No file to discuss: " + element, null);
}
}
use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentRunController method doDownloadSignature.
private void doDownloadSignature(UserRequest ureq) {
MediaResource resource = null;
if (courseNode instanceof IQTESTCourseNode) {
IQTESTCourseNode testCourseNode = (IQTESTCourseNode) courseNode;
AssessmentEntry assessmentEntry = testCourseNode.getUserAssessmentEntry(userCourseEnv);
AssessmentTestSession session = qtiService.getAssessmentTestSession(assessmentEntry.getAssessmentId());
File signature = qtiService.getAssessmentResultSignature(session);
if (signature.exists()) {
resource = new DownloadeableMediaResource(signature);
}
}
if (resource == null) {
resource = new NotFoundMediaResource();
}
ureq.getDispatchResult().setResultingMediaResource(resource);
}
use of org.olat.core.gui.media.NotFoundMediaResource in project OpenOLAT by OpenOLAT.
the class MessageListController method doDeliverAttachment.
private void doDeliverAttachment(UserRequest ureq, String cmd) {
MediaResource res = null;
try {
int index = cmd.lastIndexOf("_");
String attachmentPosition = cmd.substring(cmd.indexOf("_") + 1, index);
String messageKey = cmd.substring(index + 1);
int position = Integer.parseInt(attachmentPosition);
Long key = new Long(messageKey);
for (MessageView view : backupViews) {
if (view.getKey().equals(key)) {
List<VFSItem> attachments = view.getAttachments();
// velocity counter start with 1
VFSLeaf attachment = (VFSLeaf) attachments.get(position - 1);
VFSMediaResource fileResource = new VFSMediaResource(attachment);
// prevent XSS attack
fileResource.setDownloadable(true);
res = fileResource;
}
}
} catch (Exception e) {
logError("Cannot deliver message attachment", e);
}
if (res == null) {
res = new NotFoundMediaResource();
}
ureq.getDispatchResult().setResultingMediaResource(res);
}
use of org.olat.core.gui.media.NotFoundMediaResource 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.NotFoundMediaResource in project OpenOLAT by OpenOLAT.
the class TunnelMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest hreq) {
String method = hreq.getMethod();
String uri = relPath;
HttpUriRequest meth = null;
try {
URIBuilder builder = new URIBuilder();
builder.setScheme(proto).setHost(host).setPort(port.intValue());
if (uri == null) {
uri = (startUri == null) ? "" : startUri;
}
if (uri.length() > 0 && uri.charAt(0) != '/') {
uri = "/" + uri;
}
if (StringHelper.containsNonWhitespace(uri)) {
builder.setPath(uri);
}
if (method.equals("GET")) {
String queryString = hreq.getQueryString();
if (StringHelper.containsNonWhitespace(queryString)) {
builder.setCustomQuery(queryString);
}
meth = new HttpGet(builder.build());
} else if (method.equals("POST")) {
Map<String, String[]> params = hreq.getParameterMap();
HttpPost pmeth = new HttpPost(builder.build());
List<BasicNameValuePair> pairs = new ArrayList<>();
for (String key : params.keySet()) {
String[] vals = params.get(key);
for (String val : vals) {
pairs.add(new BasicNameValuePair(key, val));
}
}
HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
pmeth.setEntity(entity);
meth = pmeth;
}
// test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py
if ("enabled".equals(CoreSpringFactory.getImpl(BaseSecurityModule.class).getUserInfosTunnelCourseBuildingBlock())) {
User u = ident.getUser();
meth.addHeader("X-OLAT-USERNAME", ident.getName());
meth.addHeader("X-OLAT-LASTNAME", u.getProperty(UserConstants.LASTNAME, null));
meth.addHeader("X-OLAT-FIRSTNAME", u.getProperty(UserConstants.FIRSTNAME, null));
meth.addHeader("X-OLAT-EMAIL", u.getProperty(UserConstants.EMAIL, null));
meth.addHeader("X-OLAT-USERIP", ipAddress);
}
HttpResponse response = httpClient.execute(meth);
if (response == null) {
// error
return new NotFoundMediaResource();
}
// get or post successfully
Header responseHeader = response.getFirstHeader("Content-Type");
if (responseHeader == null) {
// error
EntityUtils.consumeQuietly(response.getEntity());
return new NotFoundMediaResource();
}
return new HttpRequestMediaResource(response);
} catch (ClientProtocolException | URISyntaxException e) {
log.error("", e);
return null;
} catch (IOException e) {
log.error("Error loading URI: " + (meth == null ? "???" : meth.getURI()), e);
return null;
}
}
Aggregations