Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 32041 invoked from network); 31 May 2009 12:20:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 May 2009 12:20:43 -0000 Received: (qmail 10059 invoked by uid 500); 31 May 2009 12:20:55 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 10046 invoked by uid 500); 31 May 2009 12:20:55 -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 10036 invoked by uid 99); 31 May 2009 12:20:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 May 2009 12:20:55 +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, 31 May 2009 12:20:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7535C238886C; Sun, 31 May 2009 12:20:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r780417 - in /incubator/click/trunk/click: build/ documentation/docs/ examples/webapp/WEB-INF/ framework/src/org/apache/click/ framework/src/org/apache/click/service/ framework/src/org/apache/click/util/ Date: Sun, 31 May 2009 12:20:26 -0000 To: click-commits@incubator.apache.org From: medgar@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090531122026.7535C238886C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: medgar Date: Sun May 31 12:20:25 2009 New Revision: 780417 URL: http://svn.apache.org/viewvc?rev=780417&view=rev Log: CLK-556 Added: incubator/click/trunk/click/framework/src/org/apache/click/util/Bindable.java Modified: incubator/click/trunk/click/build/build.xml incubator/click/trunk/click/documentation/docs/click-dtd.html incubator/click/trunk/click/documentation/docs/roadmap-changes.html incubator/click/trunk/click/examples/webapp/WEB-INF/click.xml incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java incubator/click/trunk/click/framework/src/org/apache/click/click.dtd incubator/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java Modified: incubator/click/trunk/click/build/build.xml URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/build/build.xml?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/build/build.xml (original) +++ incubator/click/trunk/click/build/build.xml Sun May 31 12:20:25 2009 @@ -46,7 +46,7 @@ - + Modified: incubator/click/trunk/click/documentation/docs/click-dtd.html URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/click-dtd.html?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/documentation/docs/click-dtd.html (original) +++ incubator/click/trunk/click/documentation/docs/click-dtd.html Sun May 31 12:20:25 2009 @@ -44,7 +44,7 @@ <!ELEMENT pages (page*, excludes*)> <!ATTLIST pages package CDATA #IMPLIED> <!ATTLIST pages automapping (true|false) "true"> - <!ATTLIST pages autobinding (true|false) "true"> + <!ATTLIST pages autobinding (annotation|public|none) "public"> <!-- Page definition. --> <!ELEMENT page (header*)> 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=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/documentation/docs/roadmap-changes.html (original) +++ incubator/click/trunk/click/documentation/docs/roadmap-changes.html Sun May 31 12:20:25 2009 @@ -210,6 +210,11 @@ [555].
  • + Added Bindable + annotation support for field autobinding. + [556]. +
  • +
  • Improved Page redirect to support parameters. See the new Page methods setRedirect(String, Map) and setRedirect(Class, Map) Modified: incubator/click/trunk/click/examples/webapp/WEB-INF/click.xml URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/WEB-INF/click.xml?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/examples/webapp/WEB-INF/click.xml (original) +++ incubator/click/trunk/click/examples/webapp/WEB-INF/click.xml Sun May 31 12:20:25 2009 @@ -20,7 +20,7 @@ - + Modified: incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java (original) +++ incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java Sun May 31 12:20:25 2009 @@ -44,6 +44,7 @@ import org.apache.click.service.ConfigService; import org.apache.click.service.LogService; import org.apache.click.service.XmlConfigService; +import org.apache.click.service.ConfigService.AutoBinding; import org.apache.click.util.ClickUtils; import org.apache.click.util.ErrorPage; import org.apache.click.util.HtmlStringBuffer; @@ -1068,8 +1069,8 @@ // Bind to final variable to enable callback processing final Page page = newPage; - if (configService.isPagesAutoBinding()) { - // Automatically add public controls to the page + if (configService.getAutoBindingMode() != AutoBinding.NONE) { + processPageFields(newPage, new FieldCallback() { public void processField(String fieldName, Object fieldValue) { if (fieldValue instanceof Control) { @@ -1239,7 +1240,8 @@ */ protected Map createTemplateModel(final Page page) { - if (configService.isPagesAutoBinding()) { + if (configService.getAutoBindingMode() != AutoBinding.NONE) { + processPageFields(page, new FieldCallback() { public void processField(String fieldName, Object fieldValue) { if (fieldValue instanceof Control == false) { Modified: incubator/click/trunk/click/framework/src/org/apache/click/click.dtd URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/click.dtd?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/click.dtd (original) +++ incubator/click/trunk/click/framework/src/org/apache/click/click.dtd Sun May 31 12:20:25 2009 @@ -28,7 +28,7 @@ - + Modified: incubator/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java?rev=780417&r1=780416&r2=780417&view=diff ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java (original) +++ incubator/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java Sun May 31 12:20:25 2009 @@ -116,6 +116,9 @@ /** The page not found file path:   "/click/not-found.htm". */ public static final String NOT_FOUND_PATH = "/click/not-found.htm"; + /** The page auto binding mode. */ + public enum AutoBinding { PUBLIC, ANNOTATION, NONE }; + /** * The servlet context attribute name. The ClickServlet stores the * application ConfigService instance in the ServletContext using this @@ -193,14 +196,14 @@ public boolean isJspPage(String path); /** - * Return true if auto binding is enabled. Autobinding will automatically - * bind any request parameters to public fields, add any public controls to - * the page and add public fields to the page model. + * Return the page auto binding mode. If the mode is "PUBLIC" any public + * Page fields will be auto bound, if the mode is "ANNOTATION" any Page field + * with the "Bindable" annotation will be auto bound and if the mode is + * "NONE" no Page fields will be auto bound. * - * @return true if request parameters should be automatically bound to public - * page fields + * @return the Page field auto binding mode { PUBLIC, ANNOTATION, NONE } */ - public boolean isPagesAutoBinding(); + public AutoBinding getAutoBindingMode(); /** * Return true if the application is in "production" mode. @@ -258,20 +261,20 @@ public List getPageClassList(); /** - * Return Map of public fields for the given page class. + * Return Map of bindable fields for the given page class. * * @param pageClass the page class - * @return a Map of public fields for the given page class + * @return a Map of bindable fields for the given page class */ public Map getPageFields(Class pageClass); /** - * Return the public field of the given name for the pageClass, + * Return the bindable field of the given name for the pageClass, * or null if not defined. * * @param pageClass the page class * @param fieldName the name of the field - * @return the public field of the pageClass with the given name or null + * @return the bindable field of the pageClass with the given name or null */ public Field getPageField(Class pageClass, String fieldName); @@ -284,10 +287,10 @@ public Map getPageHeaders(String path); /** - * Return an array public fields for the given page class. + * Return an array bindable for the given page class. * * @param pageClass the page class - * @return an array public fields for the given page class + * @return an array bindable fields for the given page class */ public Field[] getPageFieldArray(Class pageClass); 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=780417&r1=780416&r2=780417&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 31 12:20:25 2009 @@ -37,18 +37,19 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; - import java.util.jar.JarEntry; import java.util.jar.JarInputStream; + import javax.servlet.ServletContext; +import ognl.Ognl; + import org.apache.click.Control; import org.apache.click.Page; +import org.apache.click.util.Bindable; import org.apache.click.util.ClickUtils; import org.apache.click.util.Format; 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; @@ -165,7 +166,7 @@ // -------------------------------------------------------- Private Members /** The automatically bind controls, request parameters and models flag. */ - private Boolean autobinding; + private AutoBinding autobinding; /** The Commons FileUpload service class. */ private FileUploadService fileUploadService; @@ -343,17 +344,12 @@ } /** - * @see ConfigService#isPagesAutoBinding() + * @see ConfigService#getAutoBindingMode() * - * @return true if request parameters should be automatically bound to public - * page fields + * @return the Page field auto binding mode { PUBLIC, ANNOTATION, NONE } */ - public boolean isPagesAutoBinding() { - if (autobinding != null) { - return autobinding.booleanValue(); - } else { - return true; - } + public AutoBinding getAutoBindingMode() { + return autobinding; } /** @@ -432,7 +428,10 @@ pageClass = getPageClass(path, pagesPackage); if (pageClass != null) { - page = new PageElm(path, pageClass, commonHeaders); + page = new PageElm(path, + pageClass, + commonHeaders, + autobinding); pageByPathMap.put(page.getPath(), page); addToClassMap(page); @@ -694,10 +693,19 @@ autobindingStr = "true"; } - if ("true".equalsIgnoreCase(autobindingStr)) { - autobinding = Boolean.TRUE; + if ("annotation".equalsIgnoreCase(autobindingStr)) { + autobinding = AutoBinding.ANNOTATION; + + // Provided for backward compability + } else if ("true".equalsIgnoreCase(autobindingStr)) { + autobinding = AutoBinding.PUBLIC; + + } else if ("public".equalsIgnoreCase(autobindingStr)) { + autobinding = AutoBinding.PUBLIC; + } else if ("false".equalsIgnoreCase(autobindingStr)) { - autobinding = Boolean.FALSE; + autobinding = AutoBinding.NONE; + } else { String msg = "Invalid pages autobinding attribute: " + autobindingStr; throw new RuntimeException(msg); @@ -753,7 +761,10 @@ Element pageElm = (Element) pageList.get(i); XmlConfigService.PageElm page = - new XmlConfigService.PageElm(pageElm, pagesPackage, commonHeaders); + new XmlConfigService.PageElm(pageElm, + pagesPackage, + commonHeaders, + autobinding); pageByPathMap.put(page.getPath(), page); @@ -798,9 +809,11 @@ Class pageClass = getPageClass(pagePath, pagesPackage); if (pageClass != null) { - XmlConfigService.PageElm page = new XmlConfigService.PageElm(pagePath, - pageClass, - commonHeaders); + XmlConfigService.PageElm page = + new XmlConfigService.PageElm(pagePath, + pageClass, + commonHeaders, + autobinding); pageByPathMap.put(page.getPath(), page); @@ -1613,6 +1626,34 @@ return null; } + private static Field[] getBindablePageFields(Class pageClass, AutoBinding mode) { + if (mode == AutoBinding.PUBLIC) { + return pageClass.getFields(); + + } else if (mode == AutoBinding.ANNOTATION) { + + List fieldList = new ArrayList(); + + // Only include bindable fields + for (Field field : pageClass.getFields()) { + if (field.getAnnotation(Bindable.class) != null) { + fieldList.add(field); + } + } + + Field[] fieldArray = new Field[fieldList.size()]; + + for (int i = 0; i < fieldList.size(); i++) { + fieldArray[i] = fieldList.get(i); + } + + return fieldArray; + + } else { + return new Field[0]; + } + } + // ---------------------------------------------------------- Inner Classes static class PageElm { @@ -1627,7 +1668,10 @@ final String path; - public PageElm(Element element, String pagesPackage, Map commonHeaders) + public PageElm(Element element, + String pagesPackage, + Map commonHeaders, + AutoBinding autobinding) throws ClassNotFoundException { // Set headers @@ -1664,7 +1708,7 @@ } - fieldArray = pageClass.getFields(); + fieldArray = getBindablePageFields(pageClass, autobinding); fields = new HashMap(); for (int i = 0; i < fieldArray.length; i++) { @@ -1673,13 +1717,16 @@ } } - private PageElm(String path, Class pageClass, Map commonHeaders) { + private PageElm(String path, + Class pageClass, + Map commonHeaders, + AutoBinding mode) { headers = Collections.unmodifiableMap(commonHeaders); this.pageClass = pageClass; this.path = path; - fieldArray = pageClass.getFields(); + fieldArray = getBindablePageFields(pageClass, mode); fields = new HashMap(); for (int i = 0; i < fieldArray.length; i++) { @@ -1691,7 +1738,7 @@ public PageElm(String classname, String path) throws ClassNotFoundException { - this.fieldArray = null; + this.fieldArray = new Field[0]; this.fields = Collections.EMPTY_MAP; this.headers = Collections.EMPTY_MAP; pageClass = ClickUtils.classForName(classname); Added: incubator/click/trunk/click/framework/src/org/apache/click/util/Bindable.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/util/Bindable.java?rev=780417&view=auto ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/util/Bindable.java (added) +++ incubator/click/trunk/click/framework/src/org/apache/click/util/Bindable.java Sun May 31 12:20:25 2009 @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.click.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Provides a Page field auto binding annotation. + * + * @author Malcolm Edgar + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Bindable { +}