click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r806429 - /incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java
Date Fri, 21 Aug 2009 06:36:15 GMT
Author: sabob
Date: Fri Aug 21 06:36:15 2009
New Revision: 806429

URL: http://svn.apache.org/viewvc?rev=806429&view=rev
Log:
fixed file system resources not being cached

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java?rev=806429&r1=806428&r2=806429&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java
(original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java
Fri Aug 21 06:36:15 2009
@@ -24,9 +24,11 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarEntry;
@@ -79,8 +81,12 @@
         // Load all JAR resources
         loadAllJarResources();
 
-        // Load all file system resources
-        loadClickDirResources(servletContext);
+        // Load file system resources. File system resources override JAR
+        // resources
+        List<String> cacheables = getCacheableDirs();
+        for (String cacheable : cacheables) {
+            loadClickDirResources(servletContext, cacheable);
+        }
     }
 
     /**
@@ -130,6 +136,22 @@
         renderResource(response, resourceData);
     }
 
+    // ------------------------------------------------ Package Private Methods
+
+    /**
+     * Return the list of directories that contains cacheable resources.
+     * <p/>
+     * By default only resource under the "<tt>/click</tt>" directory will be
+     * cached.
+     *
+     * @return list of directories that should be cached
+     */
+    List<String> getCacheableDirs() {
+       List list = new ArrayList();
+       list.add("/click");
+       return list;
+    }
+
     // Private Methods --------------------------------------------------------
 
     private void loadAllJarResources() throws IOException {
@@ -279,7 +301,7 @@
             int pathIndex = fileName.indexOf(resourceDirectory);
             if (pathIndex != -1) {
                 if (logFeedback && logService.isTraceEnabled()) {
-                    logService.trace("load files from folder -> "
+                    logService.trace("loaded files from folder -> "
                         + dir.getAbsolutePath());
 
                     // Only provide feedback once per dir
@@ -311,24 +333,31 @@
     }
 
     @SuppressWarnings("unchecked")
-    private void loadClickDirResources(ServletContext servletContext)
+    private void loadClickDirResources(ServletContext servletContext, String dir)
         throws IOException {
 
-        Set resources = servletContext.getResourcePaths("/");
+        Set resources = servletContext.getResourcePaths(dir);
 
         if (resources != null) {
             // Add all resources withtin web application
             for (Iterator i = resources.iterator(); i.hasNext();) {
                 String resource = (String) i.next();
 
-                if (!configService.isTemplate(resource)
-                    && !resource.endsWith("/")) {
+                // If resource is a folder and a valid cacheable resource,
+                // recursively look for resources in that folder
+                if (resource.endsWith("/")) {
+
+                    loadClickDirResources(servletContext, resource);
+                } else {
+
+                    if (!configService.isTemplate(resource)) {
 
-                    byte[] resourceData =
-                        getServletResourceData(servletContext, resource);
+                        byte[] resourceData =
+                            getServletResourceData(servletContext, resource);
 
-                    if (resourceData != null) {
-                        resourceCache.put(resource, resourceData);
+                        if (resourceData != null) {
+                            resourceCache.put(resource, resourceData);
+                        }
                     }
                 }
             }



Mime
View raw message