javawebparts.taglib.jstags
Class CookieFunctionsTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javawebparts.taglib.jstags.CookieFunctionsTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class CookieFunctionsTag
extends javax.servlet.jsp.tagext.TagSupport

This class is a custom tag that renders the getCookie() and setCookie() Javascript functions which can be called to get or set a cookie.

This tag uses the following attributes:

renderScriptTags - true/false - When set to true, the Javascript will be rendered inside a <script> </script> tag pair. When set to false, this will not be done and it is expected that the <jstags:fullTrim/> tag appears inside a <script> </script> tag pair. If this attribute is not present, the script tags WILL be rendered.

It renders the following Javascript:

function setCookie(inName, inValue, inExpiry) {
document.cookie = inName + \"=\" + " +
escape(inValue) +
\"; expires=\" + inExpiry.toGMTString();
docCookies = document.cookie;
}
function getCookie(name) {
docCookies = document.cookie;
index = docCookies.indexOf(name + \"=\");
if (index == -1) {
return null;
}
index = docCookies.indexOf(\"=\", index) + 1;
endstr = docCookies.indexOf(\";\", index);
if (endstr == -1) {
endstr = docCookies.length;
}
return unescape(docCookies.substring(index, " +
endstr));
}

Usage example:

setCookie("myCookie", "Hello!", new Date("25 Dec 2006 06:00:00 EST"));
This will set a cookie named "myCookie" with the value "Hello!" which expires on December 25, 2006 at 6pm EST.

getCookie("myCookie");
This retrieves the value of the cookie named "myCookie".

Author:
Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String renderScriptTags
          Whether to render the opening and closing script tags around the emitted Javascript.
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
CookieFunctionsTag()
           
 
Method Summary
 int doStartTag()
          Render the results of the tag.
 void setRenderScriptTags(java.lang.String inRenderScriptTags)
          renderScriptTags mutator.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


renderScriptTags

private java.lang.String renderScriptTags
Whether to render the opening and closing script tags around the emitted Javascript.

Constructor Detail

CookieFunctionsTag

public CookieFunctionsTag()
Method Detail

setRenderScriptTags

public void setRenderScriptTags(java.lang.String inRenderScriptTags)
renderScriptTags mutator.

Parameters:
inRenderScriptTags - renderScriptTags.

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the results of the tag.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Return code.
Throws:
javax.servlet.jsp.JspException - If anything goes wrong


Copyright © 2005 Frank W. Zammetti