/*
* 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;
}
}
}