You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Ulrich Stärk <ul...@spielviel.de> on 2012/11/19 11:13:38 UTC

[PATCH] First shot at reworking the Cookies interface.

From: Ulrich Staerk <ul...@apache.org>

---
 .../java/org/apache/tapestry5/CookieBuilder.java   | 87 ++++++++++++++++++++++
 .../tapestry5/internal/services/CookiesImpl.java   | 69 +++++++++--------
 .../org/apache/tapestry5/services/Cookies.java     | 35 ++++++++-
 3 files changed, 155 insertions(+), 36 deletions(-)
 create mode 100644 tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java b/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java
new file mode 100644
index 0000000..fb04c51
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java
@@ -0,0 +1,87 @@
+package org.apache.tapestry5;
+
+import org.apache.tapestry5.services.Request;
+
+/**
+ * A fluent API to create and write cookies. Used by the
+ * {@link org.apache.tapestry5.services.Cookies} service.
+ */
+public abstract class CookieBuilder
+{
+    
+    protected final String name;
+    protected final String value;
+    
+    protected String path;
+    protected String domain;
+    protected Integer maxAge;
+    protected Boolean secure;
+    
+    /**
+     * Initialize a new CookieBuilder
+     * 
+     * @param name  the name of the resulting cookie
+     * @param value the value of the resulting cookie
+     */
+    protected CookieBuilder(String name, String value)
+    {
+        this.name = name;
+        this.value = value;
+    }
+
+    /**
+     * Set the path for the cookie to be created. Defaults to {@link Request#getContextPath()}.
+     * @param  path the path for the cookie
+     * @return the modified {@link ICookieBuilder}
+     */
+    public CookieBuilder setPath(String path)
+    {
+        this.path = path;
+        return this;
+    }
+
+    /**
+     * Set the domain for the cookie to be created. Will not be set by default.
+     * @param  domain the domain for the cookie
+     * @return the modified {@link ICookieBuilder}
+     */
+    public CookieBuilder setDomain(String domain)
+    {
+        this.domain = domain;
+        return this;
+    }
+
+    /**
+     * Set how long the cookie should live. A value of <code>0</code> deletes a cookie, a value of
+     * <code>-1</code> deletes a cookie upon closing the browser. The default is defined by
+     * the symbol <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for
+     * this value is the equivalent of one week.
+     * 
+     * @param maxAge
+     *            the cookie's maximum age in seconds
+     * @return the modified {@link ICookieBuilder}
+     */
+    public CookieBuilder setMaxAge(int maxAge)
+    {
+        this.maxAge = maxAge;
+        return this;
+    }
+    
+    /**
+     * Set the cookie's secure mode. Defaults to {@link Request#isSecure()}.
+     * 
+     * @param secure whether to send the cookie over a secure channel only
+     * @return the modified {@link ICookieBuilder}
+     */
+    public CookieBuilder setSecure(boolean secure)
+    {
+        this.secure = secure;
+        return this;
+    }
+    
+    /**
+     * Sets defaults and writes the cookie to the client.
+     */
+    public abstract void write();
+    
+}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
index 3c88006..7fad97a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
@@ -14,14 +14,15 @@
 
 package org.apache.tapestry5.internal.services;
 
+import javax.servlet.http.Cookie;
+
+import org.apache.tapestry5.CookieBuilder;
 import org.apache.tapestry5.ioc.annotations.IntermediateType;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.util.TimeInterval;
 import org.apache.tapestry5.services.Cookies;
 import org.apache.tapestry5.services.Request;
 
-import javax.servlet.http.Cookie;
-
 /**
  * Implementation of the {@link org.apache.tapestry5.services.Cookies} service interface.
  */
@@ -72,63 +73,61 @@ public class CookiesImpl implements Cookies
 
     public void writeCookieValue(String name, String value)
     {
-        writeCookieValue(name, value, defaultMaxAge);
+        getBuilder(name, value).write();
     }
 
     public void writeCookieValue(String name, String value, int maxAge)
     {
-        Cookie cookie = new Cookie(name, value);
-        cookie.setPath(request.getContextPath() + "/");
-        cookie.setMaxAge(maxAge);
-        cookie.setSecure(request.isSecure());
-
-        cookieSink.addCookie(cookie);
+        getBuilder(name, value).setMaxAge(maxAge).write();
     }
 
     public void writeCookieValue(String name, String value, String path)
     {
-        Cookie cookie = new Cookie(name, value);
-        cookie.setPath(path);
-        cookie.setMaxAge(defaultMaxAge);
-        cookie.setSecure(request.isSecure());
-
-        cookieSink.addCookie(cookie);
+        getBuilder(name, value).setPath(path).write();
     }
 
     public void writeDomainCookieValue(String name, String value, String domain)
     {
-        writeDomainCookieValue(name, value, domain, defaultMaxAge);
+        getBuilder(name, value).setDomain(domain).write();
     }
 
     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);
-        cookie.setSecure(request.isSecure());
-
-        cookieSink.addCookie(cookie);
+        getBuilder(name, value).setDomain(domain).setMaxAge(maxAge).write();
     }
 
     public void writeCookieValue(String name, String value, String path, String domain)
     {
-        Cookie cookie = new Cookie(name, value);
-        cookie.setPath(path);
-        cookie.setDomain(domain);
-        cookie.setMaxAge(defaultMaxAge);
-        cookie.setSecure(request.isSecure());
-
-        cookieSink.addCookie(cookie);
+        getBuilder(name, value).setPath(path).setDomain(domain).write();
     }
 
     public void removeCookieValue(String name)
     {
-        Cookie cookie = new Cookie(name, null);
-        cookie.setPath(request.getContextPath() + "/");
-        cookie.setMaxAge(0);
-        cookie.setSecure(request.isSecure());
+        getBuilder(name, null).setMaxAge(0).write();
+    }
 
-        cookieSink.addCookie(cookie);
+    public CookieBuilder getBuilder(String name, String value)
+    {
+        CookieBuilder builder = new CookieBuilder(name, value)
+        {
+            @Override
+            public void write()
+            {
+                Cookie cookie = new Cookie(name, value);
+                
+                cookie.setPath(path == null ? request.getContextPath() + "/" : path);
+                
+                if(domain != null)
+                    cookie.setDomain(domain);
+                
+                cookie.setMaxAge(maxAge == null ? defaultMaxAge : maxAge);
+                
+                cookie.setSecure(secure == null ? request.isSecure() : secure);
+
+                cookieSink.addCookie(cookie);
+            }
+        };
+        
+        return builder;
     }
 }
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
index 4bcd653..875e63b 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2009 The Apache Software Foundation
+// Copyright 2007, 2009, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.services;
 
+import org.apache.tapestry5.CookieBuilder;
+
 /**
  * Used by other services to obtain cookie values for the current request, or to write cookie values as part of the
  * request.  Note that when writing cookies, the cookie's secure flag will match {@link
@@ -32,6 +34,8 @@ public interface Cookies
      * Creates or updates a cookie value. The value is stored using a max age (in seconds) defined by the symbol
      * <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for this value is the equivalent of
      * one week.
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
 
     void writeCookieValue(String name, String value);
@@ -42,27 +46,37 @@ public interface Cookies
      * @param name   the name of the cookie
      * @param value  the value to be stored in the cookie
      * @param maxAge the maximum age, in seconds, to store the cookie
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
 
     void writeCookieValue(String name, String value, int maxAge);
 
     /**
      * As with {@link #writeCookieValue(String, String)} but an explicit path may be set.
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
     void writeCookieValue(String name, String value, String path);
 
     /**
      * As with {@link #writeCookieValue(String, String)} but an explicit domain may be set.
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
     void writeDomainCookieValue(String name, String value, String domain);
 
     /**
      * As with {@link #writeCookieValue(String, String)} but an explicit domain and maximum age may be set.
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
     void writeDomainCookieValue(String name, String value, String domain, int maxAge);
 
     /**
      * As with {@link #writeCookieValue(String, String, String)} but an explicit domain and path may be set.
+     * 
+     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
      */
     void writeCookieValue(String name, String value, String path, String domain);
 
@@ -70,4 +84,23 @@ public interface Cookies
      * Removes a previously written cookie, by writing a new cookie with a maxAge of 0.
      */
     void removeCookieValue(String name);
+    
+    /**
+     * Returns a {@link CookieBuilder} to build and write a {@link javax.servlet.http.Cookie}. The default
+     * implementation creates a cookie who's value is stored using a max age (in seconds) defined by
+     * the symbol <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for
+     * this value is the equivalent of one week. The default path is the context path (see
+     * {@link Request#getContextPath()}) of the current Request, the default secure setting is to
+     * send the cookie over secure channels only, if the original request was secure (see
+     * {@link Request#isSecure()}
+     * 
+     * @param name
+     *            the name of the cookie
+     * @param value
+     *            the value of the cookie
+     * @return a {@link CookieBuilder} for setting additional cookie attributes and writing it out
+     * 
+     * @since 5.4
+     */
+    CookieBuilder getBuilder(String name, String value);
 }
-- 
1.8.0.msysgit.0


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: [PATCH] First shot at reworking the Cookies interface.

Posted by Denis Stepanov <de...@gmail.com>.
Current API is looks kinda limited, you can only read a value of the cookie, there is not way how to edit existing cookie values.

It doesn't require backward-incompatible changes at all, just adding few new methods and an interface, previous methods doesn't need to be changed.

If you already working on it just make it right.

Denis

Nov 19, 2012 v 1:12 PM, Ulrich Stärk <ul...@spielviel.de>:

> My proposed changes assume that the only thing needed was a more convenient way to set cookie
> parameters.
> 
> What you are proposing is a completely new API for cookie handling that would require more
> backwards-incompatible changes than simply adding one more method to an existing interface. In
> addition, all of what you are proposing, except for iterating over all cookies, can be done already.
> 
> What you are proposing can be done but I don't know whether the gain in functionality outweighs the
> effort. Thoughts?
> 
> Cheers,
> 
> Uli
> 
> On 19.11.2012 12:38, Denis Stepanov wrote:
>> It looks more like a cookie writer than a builder.
>> 
>> It would be better to create an interface a.p.t.s.Cookie alternative to the javax.servlet.http.Cookie so it would be possible to modify current cookie value without using the servlet api, all setters could return Cookie instance to support method chaining, than there is no need for a builder at all.
>> 
>> Suggested API:
>> 
>> cookies.create("abc", "xyz").setPath("fff").setMaxAge("fdfdf") ...
>> 
>> cookies.has("abc") // checks if cookie with a name "abc" exists
>> 
>> cookies.get("abc").setValue("fffff"); // throws an exception if a cookie with a name "abc" doesn't exist
>> 
>> cookies.remove("abc")
>> 
>> cookies.getAll() : Collection<Cookie>
>> 
>> for ... each ... when ...
>>    cookie.remove()
>> 
>> I would deprecate all current methods from the a.p.t.s.Cookies service and remove them in the next version. Should be CookieSource and CookieSink refactored to use a.p.t.s.Cookie or removed?
>> 
>> Denis
>> 
>> 
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: [PATCH] First shot at reworking the Cookies interface.

Posted by Ulrich Stärk <ul...@spielviel.de>.
My proposed changes assume that the only thing needed was a more convenient way to set cookie
parameters.

What you are proposing is a completely new API for cookie handling that would require more
backwards-incompatible changes than simply adding one more method to an existing interface. In
addition, all of what you are proposing, except for iterating over all cookies, can be done already.

What you are proposing can be done but I don't know whether the gain in functionality outweighs the
effort. Thoughts?

Cheers,

Uli

On 19.11.2012 12:38, Denis Stepanov wrote:
> It looks more like a cookie writer than a builder.
> 
> It would be better to create an interface a.p.t.s.Cookie alternative to the javax.servlet.http.Cookie so it would be possible to modify current cookie value without using the servlet api, all setters could return Cookie instance to support method chaining, than there is no need for a builder at all.
> 
> Suggested API:
> 
> cookies.create("abc", "xyz").setPath("fff").setMaxAge("fdfdf") ...
> 
> cookies.has("abc") // checks if cookie with a name "abc" exists
> 
> cookies.get("abc").setValue("fffff"); // throws an exception if a cookie with a name "abc" doesn't exist
> 
> cookies.remove("abc")
> 
> cookies.getAll() : Collection<Cookie>
> 
> for ... each ... when ...
>     cookie.remove()
> 
> I would deprecate all current methods from the a.p.t.s.Cookies service and remove them in the next version. Should be CookieSource and CookieSink refactored to use a.p.t.s.Cookie or removed?
> 
> Denis
> 
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: [PATCH] First shot at reworking the Cookies interface.

Posted by Denis Stepanov <de...@gmail.com>.
It looks more like a cookie writer than a builder.

It would be better to create an interface a.p.t.s.Cookie alternative to the javax.servlet.http.Cookie so it would be possible to modify current cookie value without using the servlet api, all setters could return Cookie instance to support method chaining, than there is no need for a builder at all.

Suggested API:

cookies.create("abc", "xyz").setPath("fff").setMaxAge("fdfdf") ...

cookies.has("abc") // checks if cookie with a name "abc" exists

cookies.get("abc").setValue("fffff"); // throws an exception if a cookie with a name "abc" doesn't exist

cookies.remove("abc")

cookies.getAll() : Collection<Cookie>

for ... each ... when ...
    cookie.remove()

I would deprecate all current methods from the a.p.t.s.Cookies service and remove them in the next version. Should be CookieSource and CookieSink refactored to use a.p.t.s.Cookie or removed?

Denis




Re: [PATCH] First shot at reworking the Cookies interface.

Posted by Ulrich Stärk <ul...@apache.org>.
After struggling for days with my Git infrastructure (it sucks on Windows), I was finally able to
produce and mail the following patch for reworking the Cookies interface. Please review and comment.
Tests will follow.

Cheers,

Uli

On 19.11.2012 11:13, Ulrich Stärk wrote:
> From: Ulrich Staerk <ul...@apache.org>
> 
> ---
>  .../java/org/apache/tapestry5/CookieBuilder.java   | 87 ++++++++++++++++++++++
>  .../tapestry5/internal/services/CookiesImpl.java   | 69 +++++++++--------
>  .../org/apache/tapestry5/services/Cookies.java     | 35 ++++++++-
>  3 files changed, 155 insertions(+), 36 deletions(-)
>  create mode 100644 tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java
> 
> diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java b/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java
> new file mode 100644
> index 0000000..fb04c51
> --- /dev/null
> +++ b/tapestry-core/src/main/java/org/apache/tapestry5/CookieBuilder.java
> @@ -0,0 +1,87 @@
> +package org.apache.tapestry5;
> +
> +import org.apache.tapestry5.services.Request;
> +
> +/**
> + * A fluent API to create and write cookies. Used by the
> + * {@link org.apache.tapestry5.services.Cookies} service.
> + */
> +public abstract class CookieBuilder
> +{
> +    
> +    protected final String name;
> +    protected final String value;
> +    
> +    protected String path;
> +    protected String domain;
> +    protected Integer maxAge;
> +    protected Boolean secure;
> +    
> +    /**
> +     * Initialize a new CookieBuilder
> +     * 
> +     * @param name  the name of the resulting cookie
> +     * @param value the value of the resulting cookie
> +     */
> +    protected CookieBuilder(String name, String value)
> +    {
> +        this.name = name;
> +        this.value = value;
> +    }
> +
> +    /**
> +     * Set the path for the cookie to be created. Defaults to {@link Request#getContextPath()}.
> +     * @param  path the path for the cookie
> +     * @return the modified {@link ICookieBuilder}
> +     */
> +    public CookieBuilder setPath(String path)
> +    {
> +        this.path = path;
> +        return this;
> +    }
> +
> +    /**
> +     * Set the domain for the cookie to be created. Will not be set by default.
> +     * @param  domain the domain for the cookie
> +     * @return the modified {@link ICookieBuilder}
> +     */
> +    public CookieBuilder setDomain(String domain)
> +    {
> +        this.domain = domain;
> +        return this;
> +    }
> +
> +    /**
> +     * Set how long the cookie should live. A value of <code>0</code> deletes a cookie, a value of
> +     * <code>-1</code> deletes a cookie upon closing the browser. The default is defined by
> +     * the symbol <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for
> +     * this value is the equivalent of one week.
> +     * 
> +     * @param maxAge
> +     *            the cookie's maximum age in seconds
> +     * @return the modified {@link ICookieBuilder}
> +     */
> +    public CookieBuilder setMaxAge(int maxAge)
> +    {
> +        this.maxAge = maxAge;
> +        return this;
> +    }
> +    
> +    /**
> +     * Set the cookie's secure mode. Defaults to {@link Request#isSecure()}.
> +     * 
> +     * @param secure whether to send the cookie over a secure channel only
> +     * @return the modified {@link ICookieBuilder}
> +     */
> +    public CookieBuilder setSecure(boolean secure)
> +    {
> +        this.secure = secure;
> +        return this;
> +    }
> +    
> +    /**
> +     * Sets defaults and writes the cookie to the client.
> +     */
> +    public abstract void write();
> +    
> +}
> diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
> index 3c88006..7fad97a 100644
> --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
> +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CookiesImpl.java
> @@ -14,14 +14,15 @@
>  
>  package org.apache.tapestry5.internal.services;
>  
> +import javax.servlet.http.Cookie;
> +
> +import org.apache.tapestry5.CookieBuilder;
>  import org.apache.tapestry5.ioc.annotations.IntermediateType;
>  import org.apache.tapestry5.ioc.annotations.Symbol;
>  import org.apache.tapestry5.ioc.util.TimeInterval;
>  import org.apache.tapestry5.services.Cookies;
>  import org.apache.tapestry5.services.Request;
>  
> -import javax.servlet.http.Cookie;
> -
>  /**
>   * Implementation of the {@link org.apache.tapestry5.services.Cookies} service interface.
>   */
> @@ -72,63 +73,61 @@ public class CookiesImpl implements Cookies
>  
>      public void writeCookieValue(String name, String value)
>      {
> -        writeCookieValue(name, value, defaultMaxAge);
> +        getBuilder(name, value).write();
>      }
>  
>      public void writeCookieValue(String name, String value, int maxAge)
>      {
> -        Cookie cookie = new Cookie(name, value);
> -        cookie.setPath(request.getContextPath() + "/");
> -        cookie.setMaxAge(maxAge);
> -        cookie.setSecure(request.isSecure());
> -
> -        cookieSink.addCookie(cookie);
> +        getBuilder(name, value).setMaxAge(maxAge).write();
>      }
>  
>      public void writeCookieValue(String name, String value, String path)
>      {
> -        Cookie cookie = new Cookie(name, value);
> -        cookie.setPath(path);
> -        cookie.setMaxAge(defaultMaxAge);
> -        cookie.setSecure(request.isSecure());
> -
> -        cookieSink.addCookie(cookie);
> +        getBuilder(name, value).setPath(path).write();
>      }
>  
>      public void writeDomainCookieValue(String name, String value, String domain)
>      {
> -        writeDomainCookieValue(name, value, domain, defaultMaxAge);
> +        getBuilder(name, value).setDomain(domain).write();
>      }
>  
>      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);
> -        cookie.setSecure(request.isSecure());
> -
> -        cookieSink.addCookie(cookie);
> +        getBuilder(name, value).setDomain(domain).setMaxAge(maxAge).write();
>      }
>  
>      public void writeCookieValue(String name, String value, String path, String domain)
>      {
> -        Cookie cookie = new Cookie(name, value);
> -        cookie.setPath(path);
> -        cookie.setDomain(domain);
> -        cookie.setMaxAge(defaultMaxAge);
> -        cookie.setSecure(request.isSecure());
> -
> -        cookieSink.addCookie(cookie);
> +        getBuilder(name, value).setPath(path).setDomain(domain).write();
>      }
>  
>      public void removeCookieValue(String name)
>      {
> -        Cookie cookie = new Cookie(name, null);
> -        cookie.setPath(request.getContextPath() + "/");
> -        cookie.setMaxAge(0);
> -        cookie.setSecure(request.isSecure());
> +        getBuilder(name, null).setMaxAge(0).write();
> +    }
>  
> -        cookieSink.addCookie(cookie);
> +    public CookieBuilder getBuilder(String name, String value)
> +    {
> +        CookieBuilder builder = new CookieBuilder(name, value)
> +        {
> +            @Override
> +            public void write()
> +            {
> +                Cookie cookie = new Cookie(name, value);
> +                
> +                cookie.setPath(path == null ? request.getContextPath() + "/" : path);
> +                
> +                if(domain != null)
> +                    cookie.setDomain(domain);
> +                
> +                cookie.setMaxAge(maxAge == null ? defaultMaxAge : maxAge);
> +                
> +                cookie.setSecure(secure == null ? request.isSecure() : secure);
> +
> +                cookieSink.addCookie(cookie);
> +            }
> +        };
> +        
> +        return builder;
>      }
>  }
> diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
> index 4bcd653..875e63b 100644
> --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
> +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/Cookies.java
> @@ -1,4 +1,4 @@
> -// Copyright 2007, 2009 The Apache Software Foundation
> +// Copyright 2007, 2009, 2012 The Apache Software Foundation
>  //
>  // Licensed under the Apache License, Version 2.0 (the "License");
>  // you may not use this file except in compliance with the License.
> @@ -14,6 +14,8 @@
>  
>  package org.apache.tapestry5.services;
>  
> +import org.apache.tapestry5.CookieBuilder;
> +
>  /**
>   * Used by other services to obtain cookie values for the current request, or to write cookie values as part of the
>   * request.  Note that when writing cookies, the cookie's secure flag will match {@link
> @@ -32,6 +34,8 @@ public interface Cookies
>       * Creates or updates a cookie value. The value is stored using a max age (in seconds) defined by the symbol
>       * <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for this value is the equivalent of
>       * one week.
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>  
>      void writeCookieValue(String name, String value);
> @@ -42,27 +46,37 @@ public interface Cookies
>       * @param name   the name of the cookie
>       * @param value  the value to be stored in the cookie
>       * @param maxAge the maximum age, in seconds, to store the cookie
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>  
>      void writeCookieValue(String name, String value, int maxAge);
>  
>      /**
>       * As with {@link #writeCookieValue(String, String)} but an explicit path may be set.
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>      void writeCookieValue(String name, String value, String path);
>  
>      /**
>       * As with {@link #writeCookieValue(String, String)} but an explicit domain may be set.
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>      void writeDomainCookieValue(String name, String value, String domain);
>  
>      /**
>       * As with {@link #writeCookieValue(String, String)} but an explicit domain and maximum age may be set.
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>      void writeDomainCookieValue(String name, String value, String domain, int maxAge);
>  
>      /**
>       * As with {@link #writeCookieValue(String, String, String)} but an explicit domain and path may be set.
> +     * 
> +     * @deprecated Use the {@link CookieBuilder} API, obtained with {@link #getBuilder(String, String)}, instead.
>       */
>      void writeCookieValue(String name, String value, String path, String domain);
>  
> @@ -70,4 +84,23 @@ public interface Cookies
>       * Removes a previously written cookie, by writing a new cookie with a maxAge of 0.
>       */
>      void removeCookieValue(String name);
> +    
> +    /**
> +     * Returns a {@link CookieBuilder} to build and write a {@link javax.servlet.http.Cookie}. The default
> +     * implementation creates a cookie who's value is stored using a max age (in seconds) defined by
> +     * the symbol <code>org.apache.tapestry5.default-cookie-max-age</code>. The factory default for
> +     * this value is the equivalent of one week. The default path is the context path (see
> +     * {@link Request#getContextPath()}) of the current Request, the default secure setting is to
> +     * send the cookie over secure channels only, if the original request was secure (see
> +     * {@link Request#isSecure()}
> +     * 
> +     * @param name
> +     *            the name of the cookie
> +     * @param value
> +     *            the value of the cookie
> +     * @return a {@link CookieBuilder} for setting additional cookie attributes and writing it out
> +     * 
> +     * @since 5.4
> +     */
> +    CookieBuilder getBuilder(String name, String value);
>  }
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org