click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r778179 - in /incubator/click/trunk/click: documentation/docs/roadmap-changes.html framework/src/org/apache/click/service/XmlConfigService.java
Date Sun, 24 May 2009 15:50:04 GMT
Author: sabob
Date: Sun May 24 15:50:04 2009
New Revision: 778179

URL: http://svn.apache.org/viewvc?rev=778179&view=rev
Log:
improved XmlConfigService to deploy resources from folders on classpath. CLK-552

Modified:
    incubator/click/trunk/click/documentation/docs/roadmap-changes.html
    incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java

Modified: incubator/click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/roadmap-changes.html?rev=778179&r1=778178&r2=778179&view=diff
==============================================================================
--- incubator/click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ incubator/click/trunk/click/documentation/docs/roadmap-changes.html Sun May 24 15:50:04
2009
@@ -141,9 +141,9 @@
     </div>
     <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
       <li class="change">
-          Added new Calendar popup to DateField. This Calendar popup is based on
+          Added new Calendar popup to DateField. This Calendar popup uses
           <a target="_blank" class="external" href="http://code.google.com/p/calendardateselect/">Calendar
Date Select</a>
-          which is built on top of the Prototype JavaScript library.
+          which is based on the Prototype JavaScript library.
           <p/>
           Please note if you don't want a dependency on the Prototype library
           you can use the third-party
@@ -245,6 +245,11 @@
           [<a target='_blank' href="https://issues.apache.org/click/browse/CLK-498">498</a>].
       </li>
       <li class="change">
+          Improved XmlConfigService to scan for deployable resources inside folders
+          on the classpath
+          [<a target='_blank' href="https://issues.apache.org/click/browse/CLK-552">552</a>].
+      </li>
+      <li class="change">
           <a class="external" target="_blank" href="http://code.google.com/p/click-calendar/">Click
Calendar</a>
           version 1.0.1 has been released which fixes a memory leak in the calendar popup
           [<a target='_blank' href="https://issues.apache.org/jira/browse/CLK-499">499</a>].

Modified: incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java?rev=778179&r1=778178&r2=778179&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
(original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
Sun May 24 15:50:04 2009
@@ -49,6 +49,8 @@
 import org.apache.click.util.HtmlStringBuffer;
 import ognl.Ognl;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.Validate;
 import org.w3c.dom.Document;
@@ -814,7 +816,7 @@
 
     /**
      * Build the {@link #pageByClassMap} from the {@link #pageByPathMap} and
-     * delegate to {@link #buildClassMap(PageElm)}.
+     * delegate to {@link #addToClassMap(PageElm)}.
      */
     void buildClassMap() {
         // Build pages by class map
@@ -1114,7 +1116,7 @@
             deployControls(rootElm);
             deployControlSets(rootElm);
 
-            deployFilesInJars();
+            deployAutoFiles();
         } else {
             String msg = "Could not auto deploy files to 'click' web folder."
                 + " You may need to manually include click resources in your"
@@ -1124,13 +1126,14 @@
     }
 
     /**
-     * Deploy from jars, files that are specified in the folder 'META-INF/web'.
+     * Deploy from jars and directories all files that are specified in the
+     * folder 'META-INF/web'.
      * <p/>
-     * Only jars available on the classpath are scanned.
+     * Only jars and folders available on the classpath are scanned.
      *
      * @throws java.lang.Exception if the files cannot be deployed
      */
-    private void deployFilesInJars() throws Exception {
+    private void deployAutoFiles() throws Exception {
 
         // Find all jars under WEB-INF/lib and deploy all resources from these jars
         long startTime = System.currentTimeMillis();
@@ -1154,33 +1157,78 @@
 
             String jarPath = null;
 
-            // Extract the jar name from the entry
+            // Check if path represents a jar
             if (path.indexOf('!') > 0) {
                 jarPath = path.substring(0, path.indexOf('!'));
-            } else {
-                // If jar name cannot be extracted, skip the resource
-                logService.trace("Path does not represent a Jar -> '" + path + "'");
-                continue;
-            }
 
-            File jar = new File(jarPath);
+                File jar = new File(jarPath);
 
-            if (jar.exists()) {
-                deployFilesInJar(jar);
+                if (jar.exists()) {
+                    deployFilesInJar(jar);
 
+                } else {
+                    logService.error("Could not deploy the jar '" + jarPath +
+                        "'. Please ensure this file exists in the specified" +
+                        " location.");
+                }
             } else {
-                logService.error("Could not deploy the jar '" + jarPath
-                    + "'. Please ensure this file exists in the specified"
-                    + " location.");
+                File dir = new File(path);
+                deployFilesInDir(dir);
             }
         }
 
         if (logService.isTraceEnabled()) {
-            logService.trace("deployed files from jars - "
+            logService.trace("deployed files from jars and folders - "
                 + (System.currentTimeMillis() - startTime) + " ms");
         }
     }
 
+
+    /**
+     * Deploy files from the specified directory.
+     * <p/>
+     * Only files specified in the folder 'META-INF/web' will be deployed.
+     *
+     * @param dir the directory which resources will be deployed
+     * @throws java.lang.Exception if for some reason the files cannot be
+     * deployed
+     */
+    private void deployFilesInDir(File dir) throws Exception {
+        if (dir == null) {
+            throw new IllegalArgumentException("Dir cannot be null");
+        }
+
+        if (!dir.exists()) {
+            logService.trace("There are no files in the folder '"
+                + dir.getAbsolutePath() + "'");
+            return;
+        }
+
+        Iterator files = FileUtils.iterateFiles(dir, TrueFileFilter.INSTANCE,
+            TrueFileFilter.INSTANCE);
+
+        boolean logFeedback = true;
+        while (files.hasNext()) {
+            // file example -> META-INF/web/click/table.css
+            File file = (File) files.next();
+            String fileName = file.getCanonicalPath().replace('\\', '/');
+
+            // Only deploy resources from "META-INF/web/"
+            int pathIndex = fileName.indexOf("META-INF/web/");
+            if (pathIndex != -1) {
+                if (logFeedback && logService.isTraceEnabled()) {
+                    logService.trace("deploy files from folder -> " +
+                        dir.getAbsolutePath());
+
+                    // Only provide feedback once per dir
+                    logFeedback = false;
+                }
+                fileName = fileName.substring(pathIndex);
+                deployFile(fileName, "META-INF/web/");
+            }
+        }
+    }
+
     /**
      * Deploy files from the specified jar.
      * <p/>
@@ -1211,7 +1259,7 @@
                 // jarEntryName example -> META-INF/web/click/table.css
                 String jarEntryName = jarEntry.getName();
 
-                // Deploy all resources under "META-INF/web/"
+                // Only deploy resources from "META-INF/web/"
                 int pathIndex = jarEntryName.indexOf("META-INF/web/");
                 if (pathIndex == 0) {
                     if (logFeedback && logService.isTraceEnabled()) {
@@ -1221,24 +1269,7 @@
                         // Only provide feedback once per jar
                         logFeedback = false;
                     }
-                    pathIndex += "META-INF/web/".length();
-
-                    // By default deploy to the web root dir
-                    String targetDir = "";
-
-                    // resourceName example -> click/table.css
-                    String resourceName = jarEntryName.substring(pathIndex);
-                    int index = resourceName.lastIndexOf('/');
-
-                    if (index != -1) {
-                        // targetDir example -> click
-                        targetDir = resourceName.substring(0, index);
-                    }
-
-                    // Copy resources to web folder
-                    ClickUtils.deployFile(servletContext,
-                        jarEntryName,
-                        targetDir);
+                    deployFile(jarEntryName, "META-INF/web/");
                 }
             }
         } finally {
@@ -1247,6 +1278,38 @@
         }
     }
 
+    /**
+     * Deploy the specified file.
+     *
+     * @param file the file to deploy
+     * @param prefix the file prefix that must be removed when the file is
+     * deployed
+     */
+    private void deployFile(String file, String prefix) {
+        // Only deploy resources containing the prefix
+        int pathIndex = file.indexOf(prefix);
+        if (pathIndex == 0) {
+            pathIndex += prefix.length();
+
+            // By default deploy to the web root dir
+            String targetDir = "";
+
+            // resourceName example -> click/table.css
+            String resourceName = file.substring(pathIndex);
+            int index = resourceName.lastIndexOf('/');
+
+            if (index != -1) {
+                // targetDir example -> click
+                targetDir = resourceName.substring(0, index);
+            }
+
+            // Copy resources to web folder
+            ClickUtils.deployFile(servletContext,
+                                  file,
+                                  targetDir);
+        }
+    }
+
     private void loadMode(Element rootElm) {
         Element modeElm = ClickUtils.getChild(rootElm, "mode");
 



Mime
View raw message