use of io.undertow.server.handlers.resource.FileResource in project runwar by cfmlprojects.
the class MappedResourceManager method getResource.
public Resource getResource(String path) {
LOG.trace("* requested:" + path);
if (path == null) {
LOG.error("getResource got a null path!");
return null;
}
File reqFile = null;
try {
if (WEBINF != null && (path.startsWith("/WEB-INF") || path.startsWith("./WEB-INF"))) {
if (path.equals("/WEB-INF") || path.equals("./WEB-INF")) {
reqFile = WEBINF;
}
reqFile = new File(WEBINF, path.replaceAll(".+WEB-INF", ""));
} else if (path.startsWith(WEBINF.getPath())) {
reqFile = new File(WEBINF, path.replace(WEBINF.getPath(), ""));
} else if (path.startsWith("/CFIDE")) {
reqFile = new File(WEBINF.getParentFile(), path);
} else if (!path.startsWith("/WEB-INF")) {
reqFile = new File(getBase(), path);
if (!reqFile.exists()) {
reqFile = getAliasedFile(aliasMap, path);
}
if (reqFile == null) {
for (int x = 0; x < cfmlDirsFiles.length; x++) {
String absPath = cfmlDirsFiles[x].getCanonicalPath();
reqFile = new File(cfmlDirsFiles[x], path.replace(absPath, ""));
LOG.tracef("checking:%s = %s", absPath, reqFile.getAbsolutePath());
if (reqFile.exists()) {
break;
}
}
}
}
if (reqFile != null && reqFile.exists()) {
reqFile = reqFile.getAbsoluteFile().toPath().normalize().toFile();
LOG.tracef("path mapped to: %s", reqFile);
return new FileResource(reqFile, this, path);
} else {
LOG.tracef("No mapped resource for: %s", path);
return super.getResource(path);
}
} catch (MalformedURLException e) {
LOG.error(e.getMessage());
} catch (IOException e) {
LOG.error(e.getMessage());
}
return null;
}
Aggregations