[seam-commits] Seam SVN: r10900 - in modules/trunk: faces and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue May 12 07:55:44 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-05-12 07:55:44 -0400 (Tue, 12 May 2009)
New Revision: 10900

Added:
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManagedCookie.java
   modules/trunk/web/src/main/java/org/jboss/seam/web/ManagedCookie.java
Removed:
   modules/trunk/view/
Modified:
   modules/trunk/faces/pom.xml
Log:
merge view with web module

Modified: modules/trunk/faces/pom.xml
===================================================================
--- modules/trunk/faces/pom.xml	2009-05-12 07:11:16 UTC (rev 10899)
+++ modules/trunk/faces/pom.xml	2009-05-12 11:55:44 UTC (rev 10900)
@@ -59,6 +59,11 @@
          <groupId>${seam.groupId}</groupId>
          <artifactId>seam-international</artifactId>
       </dependency>
+      
+      <dependency>
+         <groupId>${seam.groupId}</groupId>
+         <artifactId>seam-web</artifactId>
+      </dependency>
 
       <dependency>
          <groupId>${webbeans.groupId}</groupId>

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManagedCookie.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManagedCookie.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManagedCookie.java	2009-05-12 11:55:44 UTC (rev 10900)
@@ -0,0 +1,61 @@
+package org.jboss.seam.faces;
+
+import javax.faces.context.FacesContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.view.Selector;
+
+/**
+ * Selector implementation for JSF environments
+ * 
+ * @author Shane Bryzak
+ */
+public class FacesManagedCookie extends ManagedCookie
+{
+   private static final long serialVersionUID = 7212365784926629129L;
+
+   @Override
+   protected void clearCookieValue()
+   {
+      Cookie cookie = getCookie();
+      if ( cookie!=null )
+      {
+         HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();         
+         cookie.setValue(null);
+         cookie.setPath(getCookiePath());
+         cookie.setMaxAge(0);
+         response.addCookie(cookie);
+      }      
+   }
+
+   @Override
+   protected Cookie getCookie()
+   {
+      FacesContext ctx = FacesContext.getCurrentInstance();
+      if (ctx != null)
+      {
+          return (Cookie) ctx.getExternalContext().getRequestCookieMap()
+            .get( getCookieName() );
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+   @Override
+   protected void setCookieValueIfEnabled(String value)
+   {
+      FacesContext ctx = FacesContext.getCurrentInstance();
+      
+      if ( isCookieEnabled() && ctx != null)
+      {
+         HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
+         Cookie cookie = new Cookie( getCookieName(), value );
+         cookie.setMaxAge( getCookieMaxAge() );
+         cookie.setPath(getCookiePath());
+         response.addCookie(cookie);
+      }
+   }
+}

Added: modules/trunk/web/src/main/java/org/jboss/seam/web/ManagedCookie.java
===================================================================
--- modules/trunk/web/src/main/java/org/jboss/seam/web/ManagedCookie.java	                        (rev 0)
+++ modules/trunk/web/src/main/java/org/jboss/seam/web/ManagedCookie.java	2009-05-12 11:55:44 UTC (rev 10900)
@@ -0,0 +1,158 @@
+package org.jboss.seam.web;
+
+import java.io.Serializable;
+
+import javax.servlet.http.Cookie;
+
+/**
+ * Support for selector objects which remember their selection as a cookie
+ * 
+ * @author Gavin King
+ * @author Shane Bryzak
+ */
+public abstract class ManagedCookie implements Serializable
+{
+   private static final long serialVersionUID = 8851522639722586279L;
+
+   /**
+    * 1 Year, in seconds
+    */
+   public static final int DEFAULT_MAX_AGE = 31536000;
+   
+   /**
+    * Is the cookie enabled
+    */
+   private boolean cookieEnabled;
+   
+   /**
+    * The maximum age of the cookie
+    */
+   private int cookieMaxAge = DEFAULT_MAX_AGE;
+   
+   /**
+    * The path of the cookie
+    */
+   private String cookiePath= "/";
+   
+   /**
+    * The name of the cookie
+    */
+   private String cookieName;
+   
+   /**
+    * Is the cookie enabled?
+    * 
+    * @return false by default
+    */
+   public boolean isCookieEnabled()
+   {
+      return cookieEnabled;
+   }
+   
+   /**
+    * Sets the enabled status of the cookie 
+    * 
+    * @param cookieEnabled
+    */
+   public void setCookieEnabled(boolean cookieEnabled)
+   {
+      this.cookieEnabled = cookieEnabled;
+   }
+   
+   /**
+    * The max age of the cookie
+    * @return 1 year by default
+    */
+   public int getCookieMaxAge()
+   {
+      return cookieMaxAge;
+   }
+   
+   /**
+    * Sets the maximum age of the cookie
+    * 
+    * @param cookieMaxAge The maximum age of the cookie, in seconds
+    */
+   public void setCookieMaxAge(int cookieMaxAge)
+   {
+      this.cookieMaxAge = cookieMaxAge;
+   }
+   
+   /**
+    * Returns the path of the cookie.
+    * 
+    * @return String The cookie path 
+    */
+   public String getCookiePath()
+   {
+      return cookiePath;
+   }
+   
+   /**
+    * Sets the path of the cookie.
+    * 
+    * @param cookiePath The cookie path
+    */
+   public void setCookiePath(String cookiePath)
+   {
+      this.cookiePath = cookiePath;
+   }
+   
+   /**
+    * Returns the name of the cookie.
+    * 
+    * @return String The name of the cookie
+    */
+   public String getCookieName()
+   {
+      return cookieName;
+   }
+   
+   /**
+    * Sets the cookie name.
+    * 
+    * @param cookieName String The name of the cookie 
+    */
+   public void setCookieName(String cookieName)
+   {
+      this.cookieName = cookieName;
+   }
+   
+   /**
+    * Get the value of the cookie, if this selector is enabled
+    * 
+    * @return String The value of the cookie if this selector is enabled, otherwise null.
+    */
+   public String getCookieValueIfEnabled()
+   {
+      return isCookieEnabled() ? getCookieValue() : null;
+   }
+   
+   /**
+    * Returns the Cookie instance.
+    * 
+    * @return Cookie The cookie instance.
+    */
+   public abstract Cookie getCookie();
+   
+   /**
+    * Returns the cookie value.
+    * 
+    * @return String The current value of the cookie.
+    */
+   public String getCookieValue()
+   {
+      Cookie cookie = getCookie();
+      return cookie == null ? null : cookie.getValue();
+   }
+   
+   /**
+    * Clears the cookie value.
+    */
+   public abstract void clearCookieValue();
+   
+   /**
+    * Sets the cookie value.
+    */
+   public abstract void setCookieValueIfEnabled(String value);
+}
\ No newline at end of file




More information about the seam-commits mailing list