use of org.olat.admin.sysinfo.manager.CustomStaticFolderManager in project openolat by klemens.
the class StaticServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String pathInfo = request.getPathInfo();
if (pathInfo == null) {
// huh? What's this, send not found, don't know what to do here
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (pathInfo.indexOf(NOVERSION) != -1) {
// no version provided - only remove mapper
String staticRelPath = pathInfo.substring(NOVERSION.length() + 1, pathInfo.length());
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (normalizedRelPath.endsWith("transparent.gif")) {
deliverStatic(request, response, pathInfo, normalizedRelPath, true);
} else {
deliverStatic(request, response, pathInfo, normalizedRelPath, false);
}
} else if (pathInfo.startsWith(STATIC_DIR_NAME)) {
String staticRelPath = pathInfo.substring(STATIC_DIR_NAME.length() + 1, pathInfo.length());
// customizing
CustomStaticFolderManager folderManager = CoreSpringFactory.getImpl(CustomStaticFolderManager.class);
File file = new File(folderManager.getRootFile(), staticRelPath);
if (file.exists()) {
if (file.isDirectory()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
} else {
MediaResource resource = new FileMediaResource(file);
ServletUtil.serveResource(request, response, resource);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// version provided - remove it
int start = pathInfo.indexOf("/", 2);
int end = pathInfo.length();
if (start <= end) {
String staticRelPath = pathInfo.substring(start, end);
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
boolean expiration = !Settings.isDebuging();
deliverStatic(request, response, pathInfo, normalizedRelPath, expiration);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
}
use of org.olat.admin.sysinfo.manager.CustomStaticFolderManager in project OpenOLAT by OpenOLAT.
the class StaticServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String pathInfo = request.getPathInfo();
if (pathInfo == null) {
// huh? What's this, send not found, don't know what to do here
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (pathInfo.indexOf(NOVERSION) != -1) {
// no version provided - only remove mapper
String staticRelPath = pathInfo.substring(NOVERSION.length() + 1, pathInfo.length());
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (normalizedRelPath.endsWith("transparent.gif")) {
deliverStatic(request, response, pathInfo, normalizedRelPath, true);
} else {
deliverStatic(request, response, pathInfo, normalizedRelPath, false);
}
} else if (pathInfo.startsWith(STATIC_DIR_NAME)) {
String staticRelPath = pathInfo.substring(STATIC_DIR_NAME.length() + 1, pathInfo.length());
// customizing
CustomStaticFolderManager folderManager = CoreSpringFactory.getImpl(CustomStaticFolderManager.class);
File file = new File(folderManager.getRootFile(), staticRelPath);
if (file.exists()) {
if (file.isDirectory()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
} else {
MediaResource resource = new FileMediaResource(file);
ServletUtil.serveResource(request, response, resource);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// version provided - remove it
int start = pathInfo.indexOf("/", 2);
int end = pathInfo.length();
if (start <= end) {
String staticRelPath = pathInfo.substring(start, end);
String normalizedRelPath = ServletUtil.normalizePath(staticRelPath);
if (normalizedRelPath == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
boolean expiration = !Settings.isDebuging();
deliverStatic(request, response, pathInfo, normalizedRelPath, expiration);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
}
Aggregations