This patch offers the possibility to add session-infos (e.g. the session id,
if it's new, if the session is from url or cookie (see javadoc for the
infos)) to the xslt transformers (like those use-request-parameter or
se-browser-capabilities-db).
Default is of course off.
For me, I think it's quite useful although I do not know if this fits into
the discussion about session handling. As it's optional, the developer can
decide.
JOERN
Index: src/org/apache/cocoon/transformation/TraxTransformer.java
===================================================================
RCS file:
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java,v
retrieving revision 1.15.2.19
diff -u -b -r1.15.2.19 TraxTransformer.java
--- src/org/apache/cocoon/transformation/TraxTransformer.java 2001/11/06 10:47:44
1.15.2.19
+++ src/org/apache/cocoon/transformation/TraxTransformer.java 2001/11/11 10:40:26
@@ -25,6 +25,7 @@
import org.apache.cocoon.caching.TimeStampCacheValidity;
import org.apache.cocoon.components.browser.Browser;
import org.apache.cocoon.components.xslt.XSLTProcessor;
+import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.Cookie;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Source;
@@ -49,6 +50,7 @@
* <map:transformer name="xslt"
src="org.apache.cocoon.transformation.TraxTransformer"><br>
* <use-request-parameters>false</use-request-parameters>
* <use-browser-capabilities-db>false</use-browser-capabilities-db>
+ * <use-session-info>false</use-session-info>
*
<xslt-processor-role>org.apache.cocoon.components.xslt.XSLTProcessor</xslt-processor-role>
* </map:transformer>
* </pre>
@@ -69,7 +71,16 @@
* Note that this might have issues concerning cachability of the generated output of
this
* transformer.<br>
* This property is false by default.
+ * <p>
+ * The <use-session-info> configuration forces the transformer to make all
+ * of the session information available in the XSLT stylesheetas.<br>
+ * These infos are (boolean values are "true" or "false" strings: session-is-new,
+ * session-id-from-cookie, session-id-from-url, session-valid, session-id.<br>
+ * Note that this might have issues concerning cachability of the generated output of
+this
+ * transformer.<br>
+ * This property is false by default.
*
+ *
* The <xslt-processor> configuration allows to specify the XSLT processor that
will be
* used by its role name. This allows to have several XSLT processors in the
configuration
* (e.g. Xalan and Saxon) and choose one or the other depending on the needs of
stylesheet
@@ -114,6 +125,10 @@
private boolean useCookies = false;
private boolean _useCookies = false;
+ /** Should we info about the session availalbe in the stylesheet? (default is
+off) */
+ private boolean useSessionInfo = false;
+ private boolean _useSessionInfo = false;
+
private ComponentManager manager;
/** The trax TransformerHandler */
@@ -151,6 +166,12 @@
this._useBrowserCap = this.useBrowserCap;
getLogger().debug("Use browser capabilities is " + this.useBrowserCap + "
for " + this);
+ child = conf.getChild("use-session-info");
+ this.useSessionInfo = child.getValueAsBoolean(false);
+ this._useSessionInfo = this.useSessionInfo;
+ getLogger().debug("Use session info is " + this.useSessionInfo + " for " +
+this);
+
+
child = conf.getChild("xslt-processor-role");
String xsltRole = child.getValue(XSLTProcessor.ROLE);
getLogger().debug("Use XSLTProcessor of role " + xsltRole);
@@ -194,6 +215,7 @@
_useParameters = par.getParameterAsBoolean("use-request-parameters",
this.useParameters);
_useBrowserCap = par.getParameterAsBoolean("use-browser-capabilities-db",
this.useBrowserCap);
_useCookies = par.getParameterAsBoolean("use-cookies", this.useCookies);
+ _useSessionInfo = par.getParameterAsBoolean("use-session-info",
+this.useSessionInfo);
}
/**
@@ -317,6 +339,21 @@
}
}
+ if (this._useSessionInfo) {
+ /** The Request object */
+ Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
+ if (map == null) map = new HashMap(5);
+
+ if (request != null) {
+ Session session = request.getSession(true);
+ map.put("session-is-new",session.isNew()?"true":"false");
+
+map.put("session-id-from-cookie",request.isRequestedSessionIdFromCookie()?"true":"false");
+
+map.put("session-id-from-url",request.isRequestedSessionIdFromURL()?"true":"false");
+
+map.put("session-valid",request.isRequestedSessionIdValid()?"true":"false");
+ map.put("session-id",session.getId());
+ }
+ }
+
if (this._useCookies) {
Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
Cookie cookies[] = request.getCookies();
@@ -436,6 +473,7 @@
this._useParameters = this.useParameters;
this._useCookies = this.useCookies;
this._useBrowserCap = this.useBrowserCap;
+ this._useSessionInfo = this.useSessionInfo;
super.recycle();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]