* @see org.mortbay.http.ResourceCache#getResource(java.lang.String)
*/
public Resource getResource(String pathInContext) throws IOException {
boolean fullResourceCache = SystemProperties.get("adito.fullResourceCache",
String.valueOf(!(SystemProperties.get("adito.useDevConfig", "false").equals("true")))).equals("true");
Resource r;
if (log.isDebugEnabled())
log.debug("Request for " + pathInContext);
// This is a work around to prevent WEB-INF getting listed by using the
// path //WEB-INF
if (pathInContext.indexOf("//WEB-INF") != -1) {
return null;
}
/*
* When in 'Full resource cache' mode, check if we already have cached
* the resource
*/
if (fullResourceCache && cacheState.containsKey(pathInContext)) {
r = cacheState.get(pathInContext).getResource();
if (log.isDebugEnabled())
if (r == null)
log.debug("Resource " + pathInContext + " is permanently as missing.");
else
log.debug("Resource " + pathInContext + " found in permanent cache");
return r;
}
/*
* Determine if the resource has already been found in a resource cache
* (be it an extensions resource cache or the cores)
*/
ResourceCache o = fullResourceCache ? null : (ResourceCache) resourceCacheMap.get(pathInContext);
if (o == null) {
/*
* The existence of the resource has not yet been determined. Search
* all resource caches in reverse until the extension is found. When
* found, store which cache it was found in for quick look up in the
* future.
*/
if (log.isDebugEnabled())
log.debug("Resource " + pathInContext + " not found in any resource cache, checking in plugins");
for (Iterator i = reverseCaches.iterator(); i.hasNext();) {
ResourceCache cache = (ResourceCache) i.next();
r = cache.getResource(pathInContext);
if (r != null && r.exists() && !r.isDirectory()) {
if (fullResourceCache) {
if (log.isDebugEnabled())
log.debug(" Found in " + cache.getBaseResource().toString());
cacheState.put(pathInContext, new CacheState(CacheState.FOUND, pathInContext, r));
} else {
if (log.isDebugEnabled())
log.debug(" Found in " + cache.getBaseResource().toString());
resourceCacheMap.put(pathInContext, cache);
}
return r;
}
}
/*
* The resource cannot be found in this caches base directory
*/
if (log.isDebugEnabled())
log.debug(" Not found");
} else {
/*
* We know what cache the resource came from so check it still
* exists and return. This will only happen when not in full cache
* mode
*/
r = o.getResource(pathInContext);
if (r != null && r.exists() && !r.isDirectory()) {
if (log.isDebugEnabled())
log.debug(" Found in " + o.getBaseResource().toString());
return r;
}
}
if (log.isDebugEnabled())
log.debug("Checking for alias in plugins");
String resourceAlias = getResourceAlias(pathInContext);
if (resourceAlias != null) {
/*
* The resource was not found with its real name in any caches base
* directory, so repeat the operation but look for the alias
*/
if (log.isDebugEnabled())
log.debug(" Found alias of " + resourceAlias + ", checking in plugins");
for (Iterator i = reverseCaches.iterator(); i.hasNext();) {
ResourceCache cache = (ResourceCache) i.next();
r = cache.getResource(resourceAlias);
/*
* When checking for resource modification, check for existence
* of file. This allows file to be removed at runtime without
* adding overhead when used on deployed server
*/
if (r != null && r.exists() && !r.isDirectory()) {
if (fullResourceCache) {
if (log.isDebugEnabled())
log.debug(" Found in " + cache.getBaseResource().toString());
cacheState.put(pathInContext, new CacheState(CacheState.FOUND, pathInContext, r));
return r;
} else {
if (log.isDebugEnabled())
log.debug(" Found in " + cache.getBaseResource().toString());
resourceCacheMap.put(pathInContext, cache);
return r;
}
}
}
if (log.isDebugEnabled())
log.debug(" Not found");
}
/*
* The resource could not be found in any caches base directory, so pass
* to the main webapp
*/
if (log.isDebugEnabled())
log.debug("Passing to main webapp");
r = super.getResource(pathInContext);
if (r != null && r.exists() && !r.isDirectory()) {
/*
* The resource has been found in the main webapps base directory,
* store where it was found for quick lookup in future requests
*/