Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 7797 invoked from network); 24 May 2009 15:50:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 May 2009 15:50:17 -0000 Received: (qmail 77989 invoked by uid 500); 24 May 2009 15:50:30 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 77976 invoked by uid 500); 24 May 2009 15:50:30 -0000 Mailing-List: contact click-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@incubator.apache.org Delivered-To: mailing list click-commits@incubator.apache.org Received: (qmail 77966 invoked by uid 99); 24 May 2009 15:50:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 24 May 2009 15:50:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 24 May 2009 15:50:26 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D9C8D238888E; Sun, 24 May 2009 15:50:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: click-commits@incubator.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090524155004.D9C8D238888E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@
  • - Added new Calendar popup to DateField. This Calendar popup is based on + Added new Calendar popup to DateField. This Calendar popup uses Calendar Date Select - which is built on top of the Prototype JavaScript library. + which is based on the Prototype JavaScript library.

    Please note if you don't want a dependency on the Prototype library you can use the third-party @@ -245,6 +245,11 @@ [498].

  • + Improved XmlConfigService to scan for deployable resources inside folders + on the classpath + [552]. +
  • +
  • Click Calendar version 1.0.1 has been released which fixes a memory leak in the calendar popup [499]. 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'. *

    - * 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. + *

    + * 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. *

    @@ -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");