You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/11/03 11:15:13 UTC
svn commit: r832372 -
/incubator/click/trunk/click/framework/src/org/apache/click/service/ClickResourceService.java
Author: sabob
Date: Tue Nov 3 10:15:12 2009
New Revision: 832372
URL: http://svn.apache.org/viewvc?rev=832372&view=rev
Log:
only load resources from jars specified by getDeployableDirs
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=832372&r1=832371&r2=832372&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 Tue Nov 3 10:15:12 2009
@@ -79,13 +79,15 @@
templateService = configService.getTemplateService();
// Load all JAR resources
- loadAllJarResources();
+ List<String> cacheables = getCacheableDirs();
+ for (String cacheable : cacheables) {
+ loadJarResources(cacheable);
+ }
// Load file system resources. File system resources override JAR
// resources
- List<String> cacheables = getCacheableDirs();
for (String cacheable : cacheables) {
- loadClickDirResources(servletContext, cacheable);
+ loadDirResources(servletContext, cacheable);
}
}
@@ -136,17 +138,66 @@
renderResource(response, resourceData);
}
- // ------------------------------------------------ Package Private Methods
+ // ------------------------------------------------------ Protected Methods
/**
* Return the list of directories that contains cacheable resources.
* <p/>
- * By default only resource under the "<tt>/click</tt>" directory will be
- * cached.
+ * By default only resource packaged under the "<tt>/click</tt>" directory
+ * will be processed. To serve resources from other directories you need to
+ * override this method and return a list of directories to process.
+ * <p/>
+ * For example:
+ *
+ * <pre class="prettyprint">
+ * public class MyResourceService extends ClickResourceService {
+ *
+ * protected List<String> getCacheableDirs() {
+ * // Get default dirs which includes /click
+ * List list = super.getCacheableDirs();
+ *
+ * // Add resources packaged under the folder /clickclick
+ * list.add("/clickclick");
+ * // Add resources packaged under the folder /mycorp
+ * list.add("/mycorp");
+ * }
+ * } </pre>
+ *
+ * You also need to add a mapping in your <tt>web.xml</tt> to forward
+ * requests for these resources on to Click:
+ *
+ * <pre class="prettyprint">
+ * <-- The default Click *.htm mapping -->
+ * <servlet-mapping>
+ * <servlet-name>ClickServlet</servlet-name>
+ * <url-pattern>*.htm</url-pattern>
+ * </servlet-mapping>
+ *
+ * <-- Add a mapping to serve all resources under /click directly from
+ * the JARs. -->
+ * <servlet-mapping>
+ * <servlet-name>ClickServlet</servlet-name>
+ * <url-pattern>/click/*</url-pattern>
+ * </servlet-mapping>
+ *
+ * <-- Add another mapping to serve all resources under /clickclick
+ * from the JARs. -->
+ * <servlet-mapping>
+ * <servlet-name>ClickServlet</servlet-name>
+ * <url-pattern>/clickclick/*</url-pattern>
+ * </servlet-mapping>
+ *
+ * <-- Add a mapping to serve all resources under /mycorp
+ * from the JARs. -->
+ * <servlet-mapping>
+ * <servlet-name>ClickServlet</servlet-name>
+ * <url-pattern>/mycorp/*</url-pattern>
+ * </servlet-mapping>
+ * </pre>
*
* @return list of directories that should be cached
*/
- List<String> getCacheableDirs() {
+ protected List<String> getCacheableDirs() {
List list = new ArrayList();
list.add("/click");
return list;
@@ -154,7 +205,10 @@
// Private Methods --------------------------------------------------------
- private void loadAllJarResources() throws IOException {
+ private void loadJarResources(String resourceDir) throws IOException {
+ if (resourceDir == null) {
+ throw new IllegalArgumentException("resource directory cannot be null");
+ }
long startTime = System.currentTimeMillis();
@@ -162,7 +216,10 @@
// Find all jars and directories on the classpath that contains the
// directory "META-INF/resources/", and deploy those resources
- String resourceDirectory = "META-INF/resources/";
+ if (!resourceDir.startsWith("/")) {
+ resourceDir = '/' + resourceDir;
+ }
+ String resourceDirectory = "META-INF/resources" + resourceDir;
Enumeration<URL> en = classLoader.getResources(resourceDirectory);
while (en.hasMoreElements()) {
URL url = en.nextElement();
@@ -333,21 +390,25 @@
}
@SuppressWarnings("unchecked")
- private void loadClickDirResources(ServletContext servletContext, String dir)
+ private void loadDirResources(ServletContext servletContext, String resourceDir)
throws IOException {
- Set resources = servletContext.getResourcePaths(dir);
+ if (resourceDir == null) {
+ throw new IllegalArgumentException("resource directory cannot be null");
+ }
+
+ Set resources = servletContext.getResourcePaths(resourceDir);
if (resources != null) {
// Add all resources withtin web application
for (Iterator i = resources.iterator(); i.hasNext();) {
String resource = (String) i.next();
- // If resource is a folder and a valid cacheable resource,
- // recursively look for resources in that folder
+ // If resource is a folder, recursively look for resources in
+ // that folder
if (resource.endsWith("/")) {
- loadClickDirResources(servletContext, resource);
+ loadDirResources(servletContext, resource);
} else {
if (!configService.isTemplate(resource)) {