Package org.mortbay.http

Examples of org.mortbay.http.ResourceCache


        /*
         * 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;
                    }
                }
            }
View Full Code Here


    public Resource getResource(String pathInContext) throws IOException {
      if (log.isDebugEnabled())
        log.debug("Getting resource " + pathInContext + ", checking in plugins");
        // First try all the plugins with the path for an overidden resource
        for (Iterator i = resourceCaches.iterator(); i.hasNext();) {
            ResourceCache cache = (ResourceCache) i.next();
            Resource r = cache.getResource(pathInContext);
            if (r != null && r.exists() && !r.isDirectory()) {
              if (log.isDebugEnabled())
                log.debug("Found in " + cache.getBaseResource().toString());
                return r;
            }
        }
        if (log.isDebugEnabled())
          log.debug("Checking for alias");
View Full Code Here

     * @see com.adito.boot.Context#addResourceBase(java.net.URL)
     */
    public void addResourceBase(URL base) {
        if (log.isInfoEnabled())
            log.info("Adding new resource base " + base.toExternalForm());
        ResourceCache cache = new ResourceCache();
        cache.setMimeMap(webappContext.getMimeMap());
        cache.setEncodingMap(webappContext.getEncodingMap());
        cache.setResourceBase(base.toExternalForm());
        try {
            cache.start();
            webappContext.addResourceCache(cache);
            if (httpContext != null) {
                httpContext.addResourceCache(cache);
            }
            resourceCaches.put(base, cache);
View Full Code Here

     * @see com.adito.boot.Context#addResourceBase(java.net.URL)
     */
    public void removeResourceBase(URL base) {
        if (log.isInfoEnabled())
            log.info("Removing resource base " + base.toExternalForm());
        ResourceCache cache = (ResourceCache) resourceCaches.get(base);
        webappContext.removeResourceCache(cache);
        if (httpContext != null) {
            httpContext.removeResourceCache(cache);
        }
    }
View Full Code Here

TOP

Related Classes of org.mortbay.http.ResourceCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.