click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
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 GMT
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 @@
    <property name="jar.spring" value="spring-${spring.version}.jar"/>
    <property name="jar.upload" value="commons-fileupload-${commons-fileupload.version}.jar"/>
    <property name="jar.velocity" value="velocity-${velocity.version}.jar"/>
-   <property name="javac.source" value="1.4"/>
+   <property name="javac.source" value="1.5"/>
    <property name="repository" value="http://repo1.maven.org"/>
    <property name="maven-bundle" value="../maven-upload"/>
 

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 @@
   &lt;!ELEMENT <span class="red">pages</span> (<span class="blue">page</span>*,
<span class="blue">excludes</span>*)&gt;
     &lt;!ATTLIST <span class="red">pages</span> <span class="blue">package</span>
CDATA #IMPLIED&gt;
     &lt;!ATTLIST <span class="red">pages</span> <span class="blue">automapping</span>
(true|false) "<span class="green">true</span>"&gt;
-    &lt;!ATTLIST <span class="red">pages</span> <span class="blue">autobinding</span>
(true|false) "<span class="green">true</span>"&gt;
+    &lt;!ATTLIST <span class="red">pages</span> <span class="blue">autobinding</span>
(annotation|public|none) "<span class="green">public</span>"&gt;
 
     &lt;!-- Page definition. --&gt;
     &lt;!ELEMENT <span class="red">page</span> (<span class="blue">header</span>*)&gt;

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 @@
           [<a target='_blank' href="https://issues.apache.org/jira/browse/CLK-555">555</a>].
       </li>
       <li class="change">
+          Added <a href="click-api/org/apache/click/util/Bindable.html">Bindable</a>

+          annotation support for field autobinding.
+          [<a target='_blank' href="https://issues.apache.org/jira/browse/CLK-556">556</a>].
+      </li>
+      <li class="change">
           Improved Page redirect to support parameters. See the new Page methods
           <a href="click-api/org/apache/click/Page.html#setRedirect(java.lang.String,
java.util.Map)">setRedirect(String, Map)</a>
           and <a href="click-api/org/apache/click/Page.html#setRedirect(java.lang.Class,
java.util.Map)">setRedirect(Class, Map)</a>

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 @@
 
 <click-app charset="UTF-8">
 
-  <pages package="org.apache.click.examples.page">
+  <pages package="org.apache.click.examples.page" autobinding="public">
   </pages>
 
   <mode value="profile"/>

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 @@
   <!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) "annotation">
 
     <!-- Page definition. -->
     <!ELEMENT page (header*)>

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: &nbsp; "<tt>/click/not-found.htm</tt>".
*/
     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<Field> fieldList = new ArrayList<Field>();
+
+            // 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 {
+}



Mime
View raw message