You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/02/28 15:41:07 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java session.xsl xscript-lib.xsl
vgritsenko 02/02/28 06:41:07
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
JSGenerator.java XSPSessionHelper.java
src/java/org/apache/cocoon/components/language/markup/xsp/java
session.xsl xscript-lib.xsl
Log:
Session logicsheet bugfixes/cleanup
Revision Changes Path
1.6 +18 -1 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/JSGenerator.java
Index: JSGenerator.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/JSGenerator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JSGenerator.java 22 Feb 2002 07:00:08 -0000 1.5
+++ JSGenerator.java 28 Feb 2002 14:41:07 -0000 1.6
@@ -91,7 +91,7 @@
* written in Javascript language
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
- * @version CVS $Id: JSGenerator.java,v 1.5 2002/02/22 07:00:08 cziegeler Exp $
+ * @version CVS $Id: JSGenerator.java,v 1.6 2002/02/28 14:41:07 vgritsenko Exp $
*/
public class JSGenerator extends XSPGenerator
implements Configurable, Initializable {
@@ -105,6 +105,7 @@
// FIXME: Use Store to cache compiled scripts
private Script script;
+ private Exception compileError;
public void configure(Configuration configuration) throws ConfigurationException {
@@ -151,6 +152,8 @@
getLogger().debug("Compiling script " + file);
}
script = context.compileReader(global, new FileReader(file), file.toString(), 1, null);
+ } catch (Exception e) {
+ compileError = e;
} finally {
Context.exit();
}
@@ -160,6 +163,10 @@
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, par);
+ if (compileError != null) {
+ throw new ProcessingException("Failed to compile script", compileError);
+ }
+
global.put("objectModel", global, Context.toObject(this.objectModel, global));
global.put("request", global, Context.toObject(this.request, global));
global.put("response", global, Context.toObject(this.response, global));
@@ -413,5 +420,15 @@
public void setDateHeader(String name, String date, DateFormat format) throws ParseException {
XSPResponseHelper.setDateHeader(this.response, name, date, format);
+ }
+
+ // XSPSessionHelper
+ public Object getSessionAttribute(String name, Object defaultValue) {
+ return XSPSessionHelper.getSessionAttribute(this.objectModel, name, defaultValue);
+ }
+
+ public String[] getSessionAttributeNames() {
+ Collection c = XSPSessionHelper.getSessionAttributeNames(this.objectModel);
+ return (String[])c.toArray(new String[c.size()]);
}
}
1.8 +1 -135 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPSessionHelper.java
Index: XSPSessionHelper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPSessionHelper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XSPSessionHelper.java 22 Feb 2002 07:00:08 -0000 1.7
+++ XSPSessionHelper.java 28 Feb 2002 14:41:07 -0000 1.8
@@ -69,43 +69,11 @@
*
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
- * @version CVS $Id: XSPSessionHelper.java,v 1.7 2002/02/22 07:00:08 cziegeler Exp $
+ * @version CVS $Id: XSPSessionHelper.java,v 1.8 2002/02/28 14:41:07 vgritsenko Exp $
*/
public class XSPSessionHelper {
/**
- * FIXME (VG): Remove
- */
- private static final String URI = "http://apache.org/xsp/session/2.0";
- private static final String PREFIX = "xsp-session";
-
- /**
- * Sets the given session attribute value
- *
- * @param objectModel The Map objectModel
- * @param name The parameter name
- * @param content The parameter value
- */
- public static void setSessionAttribute(Map objectModel, String name, Object content) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- Session session = request.getSession(false);
- session.setAttribute(name, content);
- }
-
- /**
- * Return the given session attribute value or a user-provided default if
- * none was specified.
- *
- * @param objectModel The Map objectModel
- * @param name The parameter name
- */
- public static Object getSessionAttribute(Map objectModel, String name) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- Session session = request.getSession(false);
- return session.getAttribute(name);
- }
-
- /**
* Return the given session attribute value or a user-provided default if
* none was specified.
*
@@ -139,111 +107,9 @@
Request request = ObjectModelHelper.getRequest(objectModel);
ArrayList v = new ArrayList();
Enumeration e = request.getSession().getAttributeNames();
-
while (e.hasMoreElements()) {
v.add(e.nextElement());
}
return v;
- }
-
- /**
- * Output the given session attribute value or a user-provided default if
- * none was specified.
- *
- * @param objectModel The Map objectModel
- * @param contentHandler The SAX content handler
- * @param name The parameter name
- * @param defaultValue Value to substitute in absence of a parameter value
- * @exception SAXException If a SAX error occurs
- */
- public static void getSessionAttribute(Map objectModel, ContentHandler contentHandler,
- String name, Object defaultValue)
- throws SAXException {
- AttributesImpl attr = new AttributesImpl();
- XSPObjectHelper.addAttribute(attr, "name", name);
-
- XSPObjectHelper.elementData(
- URI, PREFIX, contentHandler, "attribute",
- (String) getSessionAttribute(objectModel, name, defaultValue),
- attr
- );
- }
-
- /**
- * Get the session creation time
- *
- * @param objectModel The Map objectModel
- */
- public static long getSessionCreationTime(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- return request.getSession().getCreationTime();
- }
-
- /**
- * Get the session id
- *
- * @param objectModel The Map objectModel
- */
- public static String getSessionId(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- return request.getSession().getId();
- }
-
- /**
- * Get the session last accessed time
- *
- * @param objectModel The Map objectModel
- */
- public static long getSessionLastAccessedTime(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- return request.getSession().getLastAccessedTime();
- }
-
- /**
- * Get the session max inactive interval
- *
- * @param objectModel The Map objectModel
- */
- public static long getSessionMaxInactiveInterval(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- return request.getSession().getMaxInactiveInterval();
- }
-
- /**
- * Set the session max inactive interval
- * @param objectModel The Map objectModel
- * @param interval max inactive interval
- */
- public static void setSessionMaxInactiveInterval(Map objectModel, int interval) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- request.getSession().setMaxInactiveInterval(interval);
- }
-
- /**
- * Invalidate the session
- * @param objectModel The Map objectModel
- */
- public static void invalidateSession(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- request.getSession().invalidate();
- }
-
- /**
- * Checks the isNew flag
- * @param objectModel The Map objectModel
- */
- public static boolean isSessionNew(Map objectModel) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- return request.getSession().isNew();
- }
-
- /**
- * Remove the specified attribute
- * @param objectModel The Map objectModel
- * @param name The parameter name
- */
- public static void removeSessionAttribute(Map objectModel, String name) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- request.getSession().removeAttribute(name);
}
}
1.11 +28 -47 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/session.xsl
Index: session.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/session.xsl,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- session.xsl 21 Feb 2002 02:51:49 -0000 1.10
+++ session.xsl 28 Feb 2002 14:41:07 -0000 1.11
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<!-- $Id: session.xsl,v 1.10 2002/02/21 02:51:49 vgritsenko Exp $-->
+<!-- $Id: session.xsl,v 1.11 2002/02/28 14:41:07 vgritsenko Exp $-->
<!--
============================================================================
@@ -56,7 +56,7 @@
*
* @author <a href="mailto:ricardo@apache.org>Ricardo Rocha</a>
* @author ported by <a href="mailto:bloritsch@apache.org>Berin Loritsch</a>
- * @version CVS $Revision: 1.10 $ $Date: 2002/02/21 02:51:49 $
+ * @version CVS $Revision: 1.11 $ $Date: 2002/02/28 14:41:07 $
-->
<xsl:stylesheet version="1.0"
@@ -72,19 +72,16 @@
<xsl:with-param name="default" select="'string'"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:choose>
<xsl:when test="$as = 'string'">
<xsp:expr>
- (XSPSessionHelper.getSessionId(objectModel))
+ (request.getSession().getId())
</xsp:expr>
</xsl:when>
<xsl:when test="$as = 'xml'">
<!-- <xsp-session:session-id> -->
<xsp:element name="xsp-session:session-id">
- <xsp:logic>
- (XSPSessionHelper.getSessionId(objectModel))
- </xsp:logic>
+ <xsp:expr>request.getSession().getId()</xsp:expr>
</xsp:element>
</xsl:when>
</xsl:choose>
@@ -129,13 +126,11 @@
<xsl:with-param name="default" select="'array'"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:choose>
<xsl:when test="$as = 'xml'">
<xsp:logic>
List v = XSPSessionHelper.getSessionAttributeNames(objectModel);
</xsp:logic>
-
<xsp:element name="xsp-session:attribute-names">
<xsp:logic>
for (int i = 0; i < v.size(); i++) {
@@ -146,7 +141,6 @@
</xsp:logic>
</xsp:element>
</xsl:when>
-
<xsl:when test="$as = 'array'">
<xsp:expr>
XSPSessionHelper.getSessionAttributeNames(objectModel)
@@ -161,23 +155,22 @@
<xsl:with-param name="default" select="'long'"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:choose>
<xsl:when test="$as = 'xml'">
<xsp:element name="xsp-session:creation-time">
<xsp:expr>
- new Date(XSPSessionHelper.getSessionCreationTime(objectModel))
+ new Date(request.getSession().getCreationTime())
</xsp:expr>
</xsp:element>
</xsl:when>
<xsl:when test="$as = 'string'">
<xsp:expr>
- new Date(XSPSessionHelper.getSessionCreationTime(objectModel))
+ new Date(request.getSession().getCreationTime())
</xsp:expr>
</xsl:when>
<xsl:when test="$as = 'long'">
<xsp:expr>
- XSPSessionHelper.getSessionCreationTime(objectModel)
+ request.getSession().getCreationTime()
</xsp:expr>
</xsl:when>
</xsl:choose>
@@ -189,15 +182,14 @@
<xsl:with-param name="default" select="'string'"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:choose>
<xsl:when test="$as = 'xml'">
<xsp:element name="xsp-session:id">
- <xsp:expr>XSPSessionHelper.getSessionId(objectModel)</xsp:expr>
+ <xsp:expr>request.getSession().getId()</xsp:expr>
</xsp:element>
</xsl:when>
<xsl:when test="$as = 'string'">
- <xsp:expr>XSPSessionHelper.getSessionId(objectModel)</xsp:expr>
+ <xsp:expr>request.getSession().getId()</xsp:expr>
</xsl:when>
</xsl:choose>
</xsl:template>
@@ -208,23 +200,22 @@
<xsl:with-param name="default" select="'long'"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:choose>
<xsl:when test="$as = 'xml'">
<xsp:element name="xsp-session:last-accessed-time">
<xsp:expr>
- new Date(XSPSessionHelper.getSessionLastAccessedTime(objectModel))
+ new Date(request.getSession().getLastAccessedTime())
</xsp:expr>
</xsp:element>
</xsl:when>
<xsl:when test="$as = 'string'">
<xsp:expr>
- new Date(XSPSessionHelper.getSessionLastAccessedTime(objectModel))
+ new Date(request.getSession().getLastAccessedTime())
</xsp:expr>
</xsl:when>
<xsl:when test="$as = 'long'">
<xsp:expr>
- XSPSessionHelper.getSessionLastAccessedTime(objectModel)
+ request.getSession().getLastAccessedTime()
</xsp:expr>
</xsl:when>
</xsl:choose>
@@ -241,19 +232,18 @@
<xsl:when test="$as = 'xml'">
<xsp:element name="xsp-session:max-inactive-interval">
<xsp:expr>
- XSPSessionHelper.getSessionMaxInactiveInterval(objectModel)
+ request.getSession().getMaxInactiveInterval()
</xsp:expr>
</xsp:element>
</xsl:when>
<xsl:when test="$as = 'string'">
<xsp:expr>
- String.valueOf(XSPSessionHelper.getSessionMaxInactiveInterval(
- objectModel))
+ String.valueOf(request.getSession().getMaxInactiveInterval())
</xsp:expr>
</xsl:when>
<xsl:when test="$as = 'int'">
<xsp:expr>
- XSPSessionHelper.getSessionMaxInactiveInterval(objectModel)
+ request.getSession().getMaxInactiveInterval()
</xsp:expr>
</xsl:when>
</xsl:choose>
@@ -261,7 +251,7 @@
<xsl:template match="xsp-session:invalidate">
<xsp:logic>
- XSPSessionHelper.invalidateSession(objectModel);
+ request.getSession().invalidate();
</xsp:logic>
</xsl:template>
@@ -271,21 +261,18 @@
<xsl:with-param name="default" select="'boolean'"/>
</xsl:call-template>
</xsl:variable>
-
<xsp:expr>
<xsl:choose>
<xsl:when test="$as = 'xml'">
<xsp:element name="xsp-session:is-new">
- <xsp:expr>XSPSessionHelper.isSessionNew(objectModel)</xsp:expr>
+ <xsp:expr>request.getSession().isNew()</xsp:expr>
</xsp:element>
</xsl:when>
<xsl:when test="$as = 'string'">
- <xsp:expr>
- String.valueOf(XSPSessionHelper.isSessionNew(objectModel))
- </xsp:expr>
+ <xsp:expr>String.valueOf(request.getSession().isNew())</xsp:expr>
</xsl:when>
<xsl:when test="$as = 'boolean'">
- <xsp:expr>XSPSessionHelper.isSessionNew(objectModel)</xsp:expr>
+ <xsp:expr>request.getSession().isNew()</xsp:expr>
</xsl:when>
</xsl:choose>
</xsp:expr>
@@ -295,11 +282,8 @@
<xsl:variable name="name">
<xsl:call-template name="value-for-name"/>
</xsl:variable>
-
<xsp:logic>
- XSPSessionHelper.removeSessionAttribute(objectModel,
- String.valueOf(<xsl:copy-of select="$name"/>)
- );
+ request.getSession().removeAttribute(String.valueOf(<xsl:copy-of select="$name"/>));
</xsp:logic>
</xsl:template>
@@ -307,17 +291,15 @@
<xsl:variable name="name">
<xsl:call-template name="value-for-name"/>
</xsl:variable>
-
<xsl:variable name="content">
<xsl:call-template name="get-nested-content">
<xsl:with-param name="content" select="."/>
</xsl:call-template>
</xsl:variable>
-
<xsp:logic>
- XSPSessionHelper.setSessionAttribute(objectModel,
- String.valueOf(<xsl:copy-of select="$name"/>),
- <xsl:copy-of select="$content"/>);
+ request.getSession().setAttribute(
+ String.valueOf(<xsl:copy-of select="$name"/>),
+ <xsl:copy-of select="$content"/>);
</xsp:logic>
</xsl:template>
@@ -333,18 +315,16 @@
</xsl:when>
</xsl:choose>
</xsl:variable>
-
<xsp:logic>
- XSPSessionHelper.setSessionMaxInactiveInterval(objectModel,
- Integer.parseInt(String.valueOf(<xsl:copy-of select="$interval"/>)));
+ request.getSession().setMaxInactiveInterval(
+ Integer.parseInt(String.valueOf(<xsl:copy-of select="$interval"/>))
+ );
</xsp:logic>
</xsl:template>
<!-- encode an URL with the session ID -->
<xsl:template match="xsp-session:encode-url">
- <xsl:variable name="href">"<xsl:value-of
- select="@href"/>"</xsl:variable>
-
+ <xsl:variable name="href">"<xsl:value-of select="@href"/>"</xsl:variable>
<xsp:element name="a">
<xsp:attribute name="href">
<xsp:expr>
@@ -379,6 +359,7 @@
<xsl:apply-templates/>
</xsp:element>
</xsl:template>
+
<xsl:template name="value-for-name">
1.4 +5 -5 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl
Index: xscript-lib.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xscript-lib.xsl 13 Feb 2002 01:09:08 -0000 1.3
+++ xscript-lib.xsl 28 Feb 2002 14:41:07 -0000 1.4
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- $Id: xscript-lib.xsl,v 1.3 2002/02/13 01:09:08 vgritsenko Exp $-->
+<!-- $Id: xscript-lib.xsl,v 1.4 2002/02/28 14:41:07 vgritsenko Exp $-->
<!--
============================================================================
@@ -57,7 +57,7 @@
* Date: September 19, 2001
*
* @author <a href="mailto:ovidiu@cup.hp.com>Ovidiu Predescu</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/02/13 01:09:08 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/02/28 14:41:07 $
-->
<xsl:stylesheet
@@ -300,8 +300,8 @@
<xsl:when test="$scope = 'global'">""</xsl:when>
<!-- for the page scope use the context-path as context -->
<xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when>
- <xsl:when test="$scope = 'session'">(XSPSessionHelper.getSessionId(objectModel))</xsl:when>
- <xsl:otherwise>(XSPSessionHelper.getSessionId(objectModel)), (request.getContextPath())</xsl:otherwise>
+ <xsl:when test="$scope = 'session'">(request.getSession().getId())</xsl:when>
+ <xsl:otherwise>(request.getSession().getId()), (request.getContextPath())</xsl:otherwise>
</xsl:choose>
</xsl:template>
@@ -315,7 +315,7 @@
<xsl:when test="$scope = 'global'">""</xsl:when>
<!-- for the page scope use the context-path as context -->
<xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when>
- <xsl:otherwise>(XSPSessionHelper.getSessionId(objectModel))</xsl:otherwise>
+ <xsl:otherwise>(request.getSession().getId())</xsl:otherwise>
</xsl:choose>
</xsl:template>
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org