public Decorator getNamedDecorator(HttpServletRequest req,
String name) {
if (pathNotAvailable || name == null) {
return super.getNamedDecorator(req, name);
}
URL resourcePath = null;
// try to locate the resource (might be an unexpanded WAR)
try {
resourcePath = config.getServletContext().getResource('/" + name);
}
catch (MalformedURLException e) {
e.printStackTrace();
return super.getNamedDecorator(req, name);
}
String filePath = config.getServletContext().getRealPath(name);
if (filePath == null && resourcePath == null) {
pathNotAvailable = true;
return super.getNamedDecorator(req, name);
}
else if (filePath != null) { // do we really need this disk file check?!
File file = new File(filePath);
if (file.exists() && file.canRead()) {
// if filename exists with name of supplied decorator, return Decorator
return new DefaultDecorator(name, name, null);
}
else {
// otherwise delegate to parent mapper.
return super.getNamedDecorator(req, name);
}
}
else {
// file path is null and resource path is not null - can't check file on disk
return new DefaultDecorator(name, name, null);
}
}
|