true
if a cookie by this name is present, false
if not.
+ */
+ public abstract boolean isCookiePresent(String name);
+ /**
+ * Returns the value of a particular request cookie.
+ *
+ * @param name Name of the cookie to retrieve the value of.
+ * @return The value of that cookie, or null
if the cookie is not present.
+ */
+ public abstract String getCookie(String name);
+
+ /**
+ * Returns a set containing all the cookie names associated with this request.
+ *
+ * @return See above.
+ */
+ public abstract Set getCookieNames();
+
+ /**
+ * Adds a new persistent cookie to the application. The cookie will be stored by the
+ * browser's persistent storage facility.
+ * Cookies should be used sparingly, to avoid possible privacy concerns.
+ *
+ * @param name Name of the cookie to be set.
+ * @param value Value of the cookie to be set.
+ * @param max_age The maximum lifespan of the persistent cookie, in seconds.
+ */
public abstract void savePersistentCookie(String name, String value, int max_age);
+ /**
+ * Adds a new temporary cookie to the application. The cookie will be stored in the
+ * browser's memory only, and will disappear when the browser is closed.
+ * Cookies should be used sparingly, to avoid possible privacy concerns.
+ *
+ * @param name Name of the cookie to be set.
+ * @param value Value of the cookie to be set.
+ */
public abstract void saveTemporaryCookie(String name, String value);
+ /**
+ * Deletes a cookie (either persistent or temporary) from the application. The cookie
+ * will be erased from the browser.
+ *
+ * @param name Name of the cookie to remove.
+ */
public abstract void deleteCookie(String name);
} // end interface CookieControl
diff --git a/src/com/silverwrist/venice/ui/script/ScriptLibrary.java b/src/com/silverwrist/venice/ui/script/ScriptLibrary.java
index 5637cac..5c7722c 100644
--- a/src/com/silverwrist/venice/ui/script/ScriptLibrary.java
+++ b/src/com/silverwrist/venice/ui/script/ScriptLibrary.java
@@ -22,6 +22,7 @@ import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
+import com.silverwrist.venice.ui.VeniceUISession;
import com.silverwrist.venice.ui.helpers.CookieControl;
import com.silverwrist.venice.ui.helpers.HTMLRendering;
import com.silverwrist.venice.ui.helpers.SessionControl;
@@ -128,6 +129,14 @@ public class ScriptLibrary
} // end castUserSideBoxDescriptor
+ public final VeniceUISession castVeniceUISession(Object o)
+ {
+ if (o instanceof VeniceUISession)
+ return (VeniceUISession)o;
+ throw new ClassCastException("ScriptLibrary.castVeniceUISession: invalid cast");
+
+ } // end castVeniceUISession
+
public final boolean[] createBooleanArray(int len)
{
return new boolean[len];
@@ -184,6 +193,8 @@ public class ScriptLibrary
public final String exceptionType(Object o) throws ScriptExit
{
+ if (o==null)
+ return null;
if (o instanceof ScriptExit)
throw (ScriptExit)o; // rethrow ScriptExit exceptions
if (o instanceof Throwable)
@@ -244,6 +255,15 @@ public class ScriptLibrary
} // end toInteger
+ public final String typeOf(Object o)
+ {
+ if (o==null)
+ return null;
+ else
+ return o.getClass().getName();
+
+ } // end typeOf
+
public final boolean validVeniceID(String s)
{
return IDUtils.isValidVeniceID(s);
diff --git a/src/com/silverwrist/venice/ui/servlet/HttpVeniceUISession.java b/src/com/silverwrist/venice/ui/servlet/HttpVeniceUISession.java
index 26444d8..c5fac1d 100644
--- a/src/com/silverwrist/venice/ui/servlet/HttpVeniceUISession.java
+++ b/src/com/silverwrist/venice/ui/servlet/HttpVeniceUISession.java
@@ -17,6 +17,7 @@
*/
package com.silverwrist.venice.ui.servlet;
+import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -24,7 +25,8 @@ import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
-import com.silverwrist.venice.ui.helpers.CookieControl;
+import com.silverwrist.venice.ui.helpers.*;
+import com.silverwrist.venice.ui.script.*;
class HttpVeniceUISession implements VeniceUISession
{
@@ -42,9 +44,9 @@ class HttpVeniceUISession implements VeniceUISession
*--------------------------------------------------------------------------------
*/
- private HttpSession session;
- private UserContext user;
- private Cookie venice_cookie = null;
+ private HttpSession session; // HTTP session value
+ private UserContext user; // user context associated with this session
+ private boolean new_session = true; // is this a new session?
/*--------------------------------------------------------------------------------
* Constructor
@@ -59,15 +61,6 @@ class HttpVeniceUISession implements VeniceUISession
{ // tell the engine to create us a user context
user = engine.createUserContext(request.getRemoteAddr());
- // Did the user send a Venice authentication cookie? If so, try to use it.
- Cookie[] cookies = request.getCookies();
- for (int i=0; (venice_cookie==null) && (i
+ * Cookies should be used sparingly, to avoid possible privacy concerns.
+ *
+ * @param name Name of the cookie to be set.
+ * @param value Value of the cookie to be set.
+ * @param max_age The maximum lifespan of the persistent cookie, in seconds.
+ */
public void savePersistentCookie(String name, String value, int max_age)
{
Cookie c = new Cookie(name,value);
c.setMaxAge(Math.max(max_age,1));
- c.setPath(req.getContextPath());
+ c.setPath(httpreq.getContextPath());
putCookie(c);
} // end savePersistentCookie
+ /**
+ * Adds a new temporary cookie to the application. The cookie will be stored in the
+ * browser's memory only, and will disappear when the browser is closed.
+ * Cookies should be used sparingly, to avoid possible privacy concerns.
+ *
+ * @param name Name of the cookie to be set.
+ * @param value Value of the cookie to be set.
+ */
public void saveTemporaryCookie(String name, String value)
{
Cookie c = new Cookie(name,value);
c.setMaxAge(-1);
- c.setPath(req.getContextPath());
+ c.setPath(httpreq.getContextPath());
putCookie(c);
} // end saveTemporaryCookie
+ /**
+ * Deletes a cookie (either persistent or temporary) from the application. The cookie
+ * will be erased from the browser.
+ *
+ * @param name Name of the cookie to remove.
+ */
public void deleteCookie(String name)
{
Cookie c = new Cookie(name,"");
c.setMaxAge(0);
- c.setPath(req.getContextPath());
+ c.setPath(httpreq.getContextPath());
putCookie(c);
} // end deleteCookie
@@ -1776,13 +1886,22 @@ class CookieControlImpl implements CookieControl
*--------------------------------------------------------------------------------
*/
+ /**
+ * Takes all cookies that have been set on the current request and writes them to the
+ * HTTP output.
+ *
+ * @param response HTTP response to receive all the cookies.
+ */
final void flushCookies(HttpServletResponse response)
{
if (new_cookies==null)
return; // no-op
+ if (logger.isDebugEnabled())
+ logger.debug("flushCookies(): " + new_cookies.size() + " cookie(s) to output");
+
// loop over the cookies and add them to the response
- Iterator it = new_cookies.iterator();
+ Iterator it = new_cookies.values().iterator();
while (it.hasNext())
{ // add cookies to the response
Cookie c = (Cookie)(it.next());
false
if not.
+ */
+ public boolean isCookiePresent(String name)
+ {
+ loadCookies();
+ return old_cookies.containsKey(name);
+
+ } // end isCookiePresent
+
+ /**
+ * Returns the value of a particular request cookie.
+ *
+ * @param name Name of the cookie to retrieve the value of.
+ * @return The value of that cookie, or null
if the cookie is not present.
+ */
+ public String getCookie(String name)
+ {
+ loadCookies();
+ Cookie tmp = (Cookie)(old_cookies.get(name));
+ return ((tmp==null) ? null : tmp.getValue());
+
+ } // end getCookie
+
+ /**
+ * Returns a set containing all the cookie names associated with this request.
+ *
+ * @return See above.
+ */
+ public Set getCookieNames()
+ {
+ loadCookies();
+ if (old_cookies.isEmpty())
+ return Collections.EMPTY_SET;
+ else
+ return Collections.unmodifiableSet(old_cookies.keySet());
+
+ } // end getCookieNames
+
+ /**
+ * Adds a new persistent cookie to the application. The cookie will be stored by the
+ * browser's persistent storage facility.