if (pathInfo == null) {
// huh? What's this, send not found, don't know what to do here
if (isLogDebugEnabled()) {
logDebug("PathInfo is null for static request URI::" + request.getRequestURI(), null);
}
ServletUtil.serveResource(request, response, new NotFoundMediaResource("error"));
return;
}
// remove uri prefix and version from request if available
String staticRelPath = null;
if (pathInfo.indexOf(NOVERSION) != -1) {
// no version provided - only remove mapper
staticRelPath = pathInfo.substring(mapperPath.length() + 1 + NOVERSION.length(), pathInfo.length());
}
else {
// version provided - remove it
String version = Settings.getVersionId();
staticRelPath = pathInfo.substring(mapperPath.length() + 1 + version.length(), pathInfo.length());
}
// remove any .. in the path
String normalizedRelPath = normalizePath(staticRelPath);
if (normalizedRelPath == null) {
if (isLogDebugEnabled()) {
logDebug("Path is null after noralizing for static request URI::" + request.getRequestURI(), null);
}
ServletUtil.serveResource(request, response, new NotFoundMediaResource("error"));
return;
}
// create the file from the path
String staticAbsPath = WebappHelper.getContextRoot() + STATIC_DIR_NAME + normalizedRelPath;
File staticFile = new File(staticAbsPath);
// only serve if file exists
if (!staticFile.exists()) {
if (isLogDebugEnabled()) {
logDebug("File does not exist for URI::" + request.getRequestURI(), null);
}
// try fallback without version ID
staticRelPath = pathInfo.substring(mapperPath.length() , pathInfo.length());
normalizedRelPath = normalizePath(staticRelPath);
staticAbsPath = WebappHelper.getContextRoot() + STATIC_DIR_NAME + normalizedRelPath;
staticFile = new File(staticAbsPath);
if (!staticFile.exists()) {
ServletUtil.serveResource(request, response, new NotFoundMediaResource("error"));
return;
}
// log as error, file exists but wrongly mapped
logWarn("File exists but not mapped using version - use StaticMediaDispatch methods to create URL of static files! invalid URI::" + request.getRequestURI(), null);
}