You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/12/16 19:53:59 UTC

svn commit: r487857 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/form/ java/org/apache/tapestry/services/ java/org/apache/tapestry/services/impl/ test/org/apache/tapestry/services/impl/

Author: jkuhnert
Date: Sat Dec 16 10:53:58 2006
New Revision: 487857

URL: http://svn.apache.org/viewvc?view=rev&rev=487857
Log:
Fixes TAPESTRY-751. 

Added ability to set domain / path values on cookies.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Checkbox.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/CookieSource.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Checkbox.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Checkbox.java?view=diff&rev=487857&r1=487856&r2=487857
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Checkbox.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Checkbox.java Sat Dec 16 10:53:58 2006
@@ -71,8 +71,9 @@
         try
         {
             // This is atypical validation - since this component does not explicitly bind to an object
+            
             getValidatableFieldSupport().validate(this, writer, cycle, value);
-
+            
             setValue(value != null);
         }
         catch (ValidatorException e)

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/CookieSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/CookieSource.java?view=diff&rev=487857&r1=487856&r2=487857
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/CookieSource.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/CookieSource.java Sat Dec 16 10:53:58 2006
@@ -50,7 +50,31 @@
      */
 
     void writeCookieValue(String name, String value, int maxAge);
-
+    
+    /**
+     * As with {@link #writeCookieValue(String, String)} but an explicit path
+     * may be set.
+     */
+    void writeCookieValue(String name, String value, String path);
+    
+    /**
+     * As with {@link #writeCookieValue(String, String)} but an explicit path
+     * may be set.
+     */
+    void writeDomainCookieValue(String name, String value, String domain);
+    
+    /**
+     * As with {@link #writeCookieValue(String, String)} but an explicit path
+     * may be set.
+     */
+    void writeDomainCookieValue(String name, String value, String domain, int maxAge);
+    
+    /**
+     * As with {@link #writeCookieValue(String, String, String)} but an explicit
+     * domain may be set.
+     */
+    void writeCookieValue(String name, String value, String path, String domain);
+    
     /**
      * Removes a previously written cookie, by writing a new cookie with a maxAge of 0.
      */

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java?view=diff&rev=487857&r1=487856&r2=487857
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java Sat Dec 16 10:53:58 2006
@@ -63,7 +63,40 @@
 
         _response.addCookie(cookie);
     }
-
+    
+    public void writeCookieValue(String name, String value, String path) 
+    {
+        Cookie cookie = new Cookie(name, value);
+        cookie.setPath(path);
+        _response.addCookie(cookie);
+    }
+    
+    public void writeDomainCookieValue(String name, String value, String domain) 
+    {
+        Cookie cookie = new Cookie(name, value);
+        cookie.setPath(_request.getContextPath() + "/");
+        cookie.setDomain(domain);
+        _response.addCookie(cookie);
+    }
+    
+    public void writeDomainCookieValue(String name, String value, String domain, int maxAge) 
+    {
+        Cookie cookie = new Cookie(name, value);
+        cookie.setPath(_request.getContextPath() + "/");
+        cookie.setDomain(domain);
+        cookie.setMaxAge(maxAge);
+        
+        _response.addCookie(cookie);
+    }
+    
+    public void writeCookieValue(String name, String value, String path, String domain) 
+    {
+        Cookie cookie = new Cookie(name, value);
+        cookie.setPath(path);
+        cookie.setDomain(domain);
+        _response.addCookie(cookie);
+    }
+    
     public void removeCookieValue(String name)
     {
         Cookie cookie = new Cookie(name, null);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java?view=diff&rev=487857&r1=487856&r2=487857
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java Sat Dec 16 10:53:58 2006
@@ -107,29 +107,28 @@
 
         String actual = cs.readCookieValue(name);
 
-        assertEquals(expected, actual);
+        assertEquals(actual, expected);
 
         verify();
     }
 
-    public void testNoCookies()
+    public void test_No_Cookies()
     {
         attempt("foo", null, null);
     }
 
-    public void testMatch()
+    public void test_Match()
     {
-        attempt("fred", "flintstone", new String[]
-        { "barney", "rubble", "fred", "flintstone" });
+        attempt("fred", "flintstone", 
+                new String[] { "barney", "rubble", "fred", "flintstone" });
     }
 
-    public void testNoMatch()
+    public void test_No_Match()
     {
-        attempt("foo", null, new String[]
-        { "bar", "baz" });
+        attempt("foo", null, new String[] { "bar", "baz" });
     }
 
-    public void testWriteCookie()
+    public void test_Write_Cookie_Domain()
     {
         HttpServletRequest request = newHttpRequest();
         HttpServletResponse response = newResponse();
@@ -137,25 +136,26 @@
         // Training
 
         trainGetContextPath(request, "/context");
-
+        
         Cookie cookie = new ComparableCookie("foo", "bar", ONE_WEEK);
         cookie.setPath("/context/");
-
+        cookie.setDomain("fobar.com");
+        
         response.addCookie(cookie);
-
+        
         replay();
-
+        
         CookieSourceImpl cs = new CookieSourceImpl();
         cs.setRequest(request);
         cs.setResponse(response);
         cs.setDefaultMaxAge(ONE_WEEK);
-
-        cs.writeCookieValue("foo", "bar");
+        
+        cs.writeDomainCookieValue("foo", "bar", "fobar.com", ONE_WEEK);
 
         verify();
     }
 
-    public void testWriteCookieWithMaxAge()
+    public void test_Write_Cookie_With_Max_Age()
     {
         HttpServletRequest request = newHttpRequest();
         HttpServletResponse response = newResponse();
@@ -181,6 +181,32 @@
         verify();
     }
 
+    public void test_Write_Cookie()
+    {
+        HttpServletRequest request = newHttpRequest();
+        HttpServletResponse response = newResponse();
+
+        // Training
+        
+        trainGetContextPath(request, "/context");
+        
+        Cookie cookie = new ComparableCookie("foo", "bar", ONE_WEEK);
+        cookie.setPath("/context/");
+
+        response.addCookie(cookie);
+
+        replay();
+
+        CookieSourceImpl cs = new CookieSourceImpl();
+        cs.setRequest(request);
+        cs.setResponse(response);
+        cs.setDefaultMaxAge(ONE_WEEK);
+
+        cs.writeCookieValue("foo", "bar");
+
+        verify();
+    }
+    
     private void trainGetContextPath(HttpServletRequest request, String contextPath)
     {
         expect(request.getContextPath()).andReturn(contextPath);
@@ -191,7 +217,7 @@
         return newMock(HttpServletResponse.class);
     }
 
-    public void testRemoveCookie()
+    public void test_Remove_Cookie()
     {
         HttpServletRequest request = newHttpRequest();
         HttpServletResponse response = newResponse();