use of org.olat.core.gui.media.ForbiddenMediaResource 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;
}
use of org.olat.core.gui.media.ForbiddenMediaResource in project OpenOLAT by OpenOLAT.
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;
}
Aggregations