[ You are here:
XTF ->
Tag Reference -> Session State ]
Session State
XTF is capable of tracking variables associated with a particular browsing session. This section details the functions available to any crossQuery or dynaXML stylesheet for storing and retrieving session data.
Store Session Data Function
This function can be called within a stylesheet to set a name/value pair in the session data, like this:
<xsl:value-of select="session:setData(Name, Value)"/>
where
session: |
is a namespace prefix to differentiate this function from any other. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.Session. |
Name |
specifies the name under which to store the value in the session data. |
Value |
specifies the particular value to store. It may be either a string, or a structured piece of XML with a single outer-level element (and any number of inner elements.) |
This function searches the session data for a value with a matching name. If found, the old value is replaced with the specified one. If not found, a new name/value pair is added to the session data.
Note that session tracking must be enabled in the servlet configuration file before calling session:setData; if it not, a runtime error will be generated and processing will stop. By default session tracking is enabled; see the
XTF Deployment Guide for more information on enabling or disabling session tracking.
Although this function is typically called within an
<xsl:value-of> element, it does not return a value. The purpose of using the
<xsl:value-of> element is to force the XSLT processor to execute the function instead of possibly optimizing out the call.
Retrieve Session Data Function
This function can be called within a stylesheet to retrieve a value from the session data, like this:
<xsl:variable name="Variable" select="session:getData(Name)"/>
where
Variable |
specifies the name of an XSLT variable to create. |
session: |
is a namespace prefix to differentiate this function from any other. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.Session. |
Name |
specifies the name to look up in the session data. |
This function searches the session data for a value with a matching name and returns the value (in this case, assigning it to the given XSLT variable.) If not found,
null is returned (i.e. empty string/empty sequence.)
Note that if session tracking isn't enabled,
null is always returned. By default session tracking is enabled; see the
XTF Deployment Guide for more information on enabling or disabling session tracking.
Get Session Identifier
This function can be called within a stylesheet to obtain the current session identifier string, like this:
<xsl:variable name="sessionID" select="session:getID()"/>
where
session: |
is a namespace prefix to differentiate this function from any other. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.Session. |
This function returns the unique identifier assigned by the servlet container (e.g. Resin or Tomcat) to the current user session.
Check Enabled Status Function
This function can be called within a stylesheet to check whether session tracking is enabled, like this:
<xsl:if test="session:isEnabled()"/>
where
session: |
is a namespace prefix to differentiate this function from any other. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.Session. |
This function returns
true if session tracking is enabled in the configuration file for the current servlet. It returns
false if session tracking is not enabled. By default session tracking is enabled; see the
XTF Deployment Guide for more information on enabling or disabling session tracking.
Encode URL Function
This function can be called within a stylesheet to add the session ID to any URL created by the stylesheet, like this:
<xsl:variable name="Variable" select="session:encodeURL(RawURL)"/>
where
Variable |
specifies the name of an XSLT variable to create. This variable will contain the new, encoded, URL. |
session: |
is a namespace prefix to differentiate this function from any other. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.Session. |
RawURL |
specifies an expression or other variable containing the URL to be encoded. |
This function adds a session ID to the specified raw URL, if necessary. Generally session IDs are stored in cookies, but if the user has disabled cookies, URLs will have session IDs added to them. Note that if session tracking is disabled, the URL will be returned unchanged.