vgritsenko 02/02/10 20:36:38 Modified: src/java/org/apache/cocoon/components/language/markup/xsp JSGenerator.java XSPRequestHelper.java XSPResponseHelper.java src/java/org/apache/cocoon/components/language/markup/xsp/java request.xsl response.xsl xsp.xsl src/java/org/apache/cocoon/components/language/markup/xsp/javascript request.xsl response.xsl Log: Complete response logicsheet; request logicsheet bugfixes Revision Changes Path 1.3 +45 -7 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JSGenerator.java 10 Feb 2002 05:08:24 -0000 1.2 +++ JSGenerator.java 11 Feb 2002 04:36:38 -0000 1.3 @@ -64,6 +64,8 @@ import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.language.LanguageException; import org.apache.cocoon.environment.SourceResolver; +import org.apache.cocoon.environment.Response; +import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.generation.AbstractServerPage; import org.apache.cocoon.xml.XMLizable; @@ -84,6 +86,9 @@ import java.util.Date; import java.util.Locale; import java.util.Map; +import java.text.ParseException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; /** * Class representing interpreted XSP-generated @@ -91,7 +96,7 @@ * written in Javascript language * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> - * @version CVS $Id: JSGenerator.java,v 1.2 2002/02/10 05:08:24 vgritsenko Exp $ + * @version CVS $Id: JSGenerator.java,v 1.3 2002/02/11 04:36:38 vgritsenko Exp $ */ public class JSGenerator extends XSPGenerator implements Configurable, Initializable { @@ -365,15 +370,48 @@ // XSPResponseHelper - public void setHeader(String name, String value) { - XSPResponseHelper.setHeader(this.objectModel, name, value); + public void responseGetLocale() + throws SAXException { + XSPResponseHelper.getLocale(this.response, this.contentHandler); + } + + public void addDateHeader(String name, long date) { + XSPResponseHelper.addDateHeader(this.response, name, date); + } + + public void addDateHeader(String name, Date date) { + XSPResponseHelper.addDateHeader(this.response, name, date); + } + + public void addDateHeader(String name, String date) throws ParseException { + XSPResponseHelper.addDateHeader(this.response, name, date); + } + + public void addDateHeader(String name, String date, String format) throws ParseException { + XSPResponseHelper.addDateHeader(this.response, name, date, format); + } + + public void addDateHeader(String name, String date, DateFormat format) throws ParseException { + XSPResponseHelper.addDateHeader(this.response, name, date, format); + } + + public void setDateHeader(String name, long date) { + XSPResponseHelper.setDateHeader(this.response, name, date); + } + + public void setDateHeader(String name, Date date) { + XSPResponseHelper.setDateHeader(this.response, name, date); + } + + public void setDateHeader(String name, String date) throws ParseException { + XSPResponseHelper.setDateHeader(this.response, name, date); } - public void addHeader(String name, String value) { - XSPResponseHelper.addHeader(this.objectModel, name, value); + public void setDateHeader(String name, String date, String format) throws ParseException { + XSPResponseHelper.setDateHeader(this.response, name, date, format); } - public String encodeURL(String input) { - return XSPResponseHelper.encodeURL(this.objectModel, input); + public void setDateHeader(String name, String date, DateFormat format) throws ParseException { + XSPResponseHelper.setDateHeader(this.response, name, date, format); } } 1.9 +1 -2 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPRequestHelper.java Index: XSPRequestHelper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPRequestHelper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XSPRequestHelper.java 6 Feb 2002 17:10:16 -0000 1.8 +++ XSPRequestHelper.java 11 Feb 2002 04:36:38 -0000 1.9 @@ -75,7 +75,7 @@ * The <code>Request</code> object helper * * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> - * @version CVS $Id: XSPRequestHelper.java,v 1.8 2002/02/06 17:10:16 cziegeler Exp $ + * @version CVS $Id: XSPRequestHelper.java,v 1.9 2002/02/11 04:36:38 vgritsenko Exp $ */ public class XSPRequestHelper { /** @@ -102,7 +102,6 @@ public static void getLocale(Map objectModel, ContentHandler handler) throws SAXException { Request request = ObjectModelHelper.getRequest(objectModel); - request.getLocale(); getLocale(request.getLocale(), handler); } 1.6 +65 -40 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPResponseHelper.java Index: XSPResponseHelper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPResponseHelper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XSPResponseHelper.java 6 Feb 2002 17:10:16 -0000 1.5 +++ XSPResponseHelper.java 11 Feb 2002 04:36:38 -0000 1.6 @@ -59,13 +59,21 @@ import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Response; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + import java.util.Map; +import java.util.Locale; +import java.util.Date; +import java.text.ParseException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; /** * The XSP <code>Response</code> object helper * * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> - * @version CVS $Id: XSPResponseHelper.java,v 1.5 2002/02/06 17:10:16 cziegeler Exp $ + * @version CVS $Id: XSPResponseHelper.java,v 1.6 2002/02/11 04:36:38 vgritsenko Exp $ */ public class XSPResponseHelper { /** @@ -74,46 +82,63 @@ private static final String URI = Constants.XSP_RESPONSE_URI; private static final String PREFIX = Constants.XSP_RESPONSE_PREFIX; - /** - * Set the content header for a given response - * - * @param objectModel The Map objectModel - * @param name The header name - * @param value The header value - */ - public static void setHeader(Map objectModel, String name, String value) { - Response response = ObjectModelHelper.getResponse(objectModel); - response.setHeader(name, value); - } + private static void getLocale(Locale locale, ContentHandler handler) + throws SAXException + { + XSPObjectHelper.start(URI, PREFIX, handler, "locale"); - /** - * Set the content header for a given response - * - * @param objectModel The Map objectModel - * @param name The parameter name - * @param value The parameter value - */ - public static void addHeader( - Map objectModel, - String name, - String value - ) { - Response response = ObjectModelHelper.getResponse(objectModel); - response.addHeader(name, value); - } + XSPObjectHelper.elementData(URI, PREFIX, handler, "language", + locale.getLanguage()); + XSPObjectHelper.elementData(URI, PREFIX, handler, "country", + locale.getCountry()); + XSPObjectHelper.elementData(URI, PREFIX, handler, "variant", + locale.getVariant()); - /** - * Encode the URL - * - * @param objectModel The Map objectModel - * @param name The input url string - */ - public static String encodeURL( - Map objectModel, - String input - ) { - Response response = ObjectModelHelper.getResponse(objectModel); - return response.encodeURL(input); - } + XSPObjectHelper.end(URI, PREFIX, handler, "locale"); + } + + public static void getLocale(Response response, ContentHandler handler) + throws SAXException { + getLocale(response.getLocale(), handler); + } + + public static void addDateHeader(Response response, String name, long date) { + response.addDateHeader(name, date); + } + + public static void addDateHeader(Response response, String name, Date date) { + response.addDateHeader(name, date.getTime()); + } + + public static void addDateHeader(Response response, String name, String date) throws ParseException { + addDateHeader(response, name, date, DateFormat.getDateInstance()); + } + + public static void addDateHeader(Response response, String name, String date, String format) throws ParseException { + addDateHeader(response, name, date, new SimpleDateFormat(format)); + } + + public static void addDateHeader(Response response, String name, String date, DateFormat format) throws ParseException { + response.addDateHeader(name, format.parse(date).getTime()); + } + + public static void setDateHeader(Response response, String name, long date) { + response.setDateHeader(name, date); + } + + public static void setDateHeader(Response response, String name, Date date) { + response.setDateHeader(name, date.getTime()); + } + + public static void setDateHeader(Response response, String name, String date) throws ParseException { + setDateHeader(response, name, date, DateFormat.getDateInstance()); + } + + public static void setDateHeader(Response response, String name, String date, String format) throws ParseException { + setDateHeader(response, name, date, new SimpleDateFormat(format)); + } + public static void setDateHeader(Response response, String name, String date, DateFormat format) throws ParseException { + response.setDateHeader(name, format.parse(date).getTime()); + } } 1.4 +9 -11 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/request.xsl Index: request.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/request.xsl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- request.xsl 3 Feb 2002 01:15:16 -0000 1.3 +++ request.xsl 11 Feb 2002 04:36:38 -0000 1.4 @@ -12,7 +12,7 @@ <!-- * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]>Vadim Gritsenko</a> - * @version CVS $Revision: 1.3 $ $Date: 2002/02/03 01:15:16 $ + * @version CVS $Revision: 1.4 $ $Date: 2002/02/11 04:36:38 $ --> <!-- XSP Request logicsheet for the Java language --> @@ -428,7 +428,9 @@ </xsl:when> <xsl:when test="$as = 'xml'"> <xsp:element name="xsp-request:attribute"> - <xsp:attribute name="name" value="{$name}"/> + <xsp:attribute name="name"> + <xsp:expr><xsl:copy-of select="$name"/></xsp:expr> + </xsp:attribute> <xsp:expr>request.getAttribute(<xsl:copy-of select="$name"/>)</xsp:expr> </xsp:element> </xsl:when> @@ -441,7 +443,7 @@ </xsl:variable> <xsl:variable name="content"> <xsl:call-template name="get-nested-content"> - <xsl:with-param name="content" select="*|text()"/> + <xsl:with-param name="content" select="."/> </xsl:call-template> </xsl:variable> <xsp:logic> @@ -831,13 +833,11 @@ <xsl:variable name="name"> <xsl:call-template name="value-for-name"/> </xsl:variable> - <xsl:variable name="as"> <xsl:call-template name="value-for-as"> <xsl:with-param name="default" select="'string'"/> </xsl:call-template> </xsl:variable> - <xsl:variable name="default"> <xsl:choose> <xsl:when test="@default">"<xsl:value-of select="@default"/>"</xsl:when> @@ -849,19 +849,18 @@ <xsl:otherwise>null</xsl:otherwise> </xsl:choose> </xsl:variable> - <xsl:choose> <xsl:when test="$as = 'string'"> <xsp:expr> - (XSPRequestHelper.getSessionAttribute(objectModel, + (XSPRequestHelper.getSessionAttribute(objectModel, <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>)) </xsp:expr> </xsl:when> <xsl:when test="$as = 'xml'"> <!-- <xsp-request:session-attribute name="..."> --> <xsp:logic> - XSPRequestHelper.getSessionAttribute(objectModel, - this.contentHandler, + XSPRequestHelper.getSessionAttribute(objectModel, + this.contentHandler, <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>); </xsp:logic> </xsl:when> @@ -958,8 +957,7 @@ select="@container-encoding"/>"</xsl:when> <xsl:when test="xsp-request:container-encoding"> <xsl:call-template name="get-nested-content"> - <xsl:with-param name="content" - select="xsp-request:container-encoding"/> + <xsl:with-param name="content" select="xsp-request:container-encoding"/> </xsl:call-template> </xsl:when> <xsl:otherwise>null</xsl:otherwise> 1.2 +296 -13 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/response.xsl Index: response.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/response.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- response.xsl 3 Jan 2002 12:31:11 -0000 1.1 +++ response.xsl 11 Feb 2002 04:36:38 -0000 1.2 @@ -11,29 +11,142 @@ <!-- * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> - * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:11 $ + * @version CVS $Revision: 1.2 $ $Date: 2002/02/11 04:36:38 $ --> <!-- XSP Response logicsheet for the Java language --> -<xsl:stylesheet - version="1.0" - xmlns:xsp="http://apache.org/xsp" - xmlns:xsp-response="http://apache.org/xsp/response/2.0" +<xsl:stylesheet version="1.0" + xmlns:xsp="http://apache.org/xsp" + xmlns:xsp-response="http://apache.org/xsp/response/2.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - xmlns:xsl="http://www.w3.org/1999/XSL/Transform" -> - <xsl:template match="xsp-response:set-header"> + + <xsl:template match="xsp-response:get-character-encoding"> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'string'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>response.getCharacterEncoding()</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:character-encoding"> + <xsp:expr>response.getCharacterEncoding()</xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:get-locale"> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'object'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>String.valueOf(response.getLocale())</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'object'"> + <xsp:expr>response.getLocale()</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:logic> + XSPResponseHelper.getLocale(response, contentHandler); + </xsp:logic> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:set-locale"> + <xsp:logic> + response.setLocale( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template>); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-cookie"> + <xsp:logic> + response.addCookie( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template>); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-date-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="date"> + <xsl:choose> + <xsl:when test="@date">"<xsl:value-of select="@date"/>"</xsl:when> + <xsl:when test="xsp-response:date"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:date"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="format"> + <xsl:choose> + <xsl:when test="@format">"<xsl:value-of select="@format"/>"</xsl:when> + <xsl:when test="xsp-response:format"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:format"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + <xsl:choose> + <xsl:when test="$format != 'null'"> + XSPResponseHelper.addDateHeader(response, + String.valueOf(<xsl:copy-of select="$name"/>), + (<xsl:copy-of select="$date"/>), + (<xsl:copy-of select="$format"/>)); + </xsl:when> + <xsl:otherwise> + XSPResponseHelper.addDateHeader(response, + String.valueOf(<xsl:copy-of select="$name"/>), + (<xsl:copy-of select="$date"/>)); + </xsl:otherwise> + </xsl:choose> + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-header"> <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> <xsl:choose> - <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when> - <xsl:when test="xsp-response:name"> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:when test="xsp-response:value"> <xsl:call-template name="get-nested-content"> - <xsl:with-param name="content" select="xsp-response:name"/> + <xsl:with-param name="content" select="xsp-response:value"/> </xsl:call-template> </xsl:when> + <xsl:otherwise>null</xsl:otherwise> </xsl:choose> </xsl:variable> + <xsp:logic> + response.addHeader( + String.valueOf(<xsl:copy-of select="$name"/>), + String.valueOf(<xsl:copy-of select="$value"/>)); + </xsp:logic> + </xsl:template> + <xsl:template match="xsp-response:add-int-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> <xsl:variable name="value"> <xsl:choose> <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> @@ -42,15 +155,185 @@ <xsl:with-param name="content" select="xsp-response:value"/> </xsl:call-template> </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + response.addIntHeader( + String.valueOf(<xsl:copy-of select="$name"/>), + Integer.parseInt(String.valueOf(<xsl:copy-of select="$value"/>))); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:contains-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'boolean'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'boolean'"> + <xsp:expr>response.containsHeader(String.valueOf(<xsl:copy-of select="$name"/>))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'string'"> + <xsp:expr>String.valueOf(response.containsHeader( + String.valueOf(<xsl:copy-of select="$name"/>)))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:contains-header"> + <xsp:expr>response.containsHeader(String.valueOf(<xsl:copy-of select="$name"/>))</xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:encode-url"> + <xsl:variable name="url"> + <xsl:choose> + <xsl:when test="@url">"<xsl:value-of select="@url"/>"</xsl:when> + <xsl:when test="xsp-response:url"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:url"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'string'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>response.encodeURL(String.valueOf(<xsl:copy-of select="$url"/>))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:encode-url"> + <xsp:expr> + response.encodeURL(String.valueOf(<xsl:copy-of select="$url"/>)) + </xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:set-date-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="date"> + <xsl:choose> + <xsl:when test="@date">"<xsl:value-of select="@date"/>"</xsl:when> + <xsl:when test="xsp-response:date"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:date"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="format"> + <xsl:choose> + <xsl:when test="@format">"<xsl:value-of select="@format"/>"</xsl:when> + <xsl:when test="xsp-response:format"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:format"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + <xsl:choose> + <xsl:when test="$format"> + XSPResponseHelper.setDateHeader(response, + String.valueOf(<xsl:copy-of select="$name"/>), + String.valueOf( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="$date"/> + </xsl:call-template> + ), + String.valueOf(<xsl:copy-of select="$format"/>)); + </xsl:when> + <xsl:otherwise> + XSPResponseHelper.setDateHeader(response, + String.valueOf(<xsl:copy-of select="$name"/>), + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="$date"/> + </xsl:call-template>); + </xsl:otherwise> + </xsl:choose> + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:set-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> + <xsl:choose> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:when test="."> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template> + </xsl:when> <xsl:otherwise>""</xsl:otherwise> </xsl:choose> </xsl:variable> + <xsp:logic> + response.setHeader( + String.valueOf(<xsl:copy-of select="$name"/>), + String.valueOf(<xsl:copy-of select="$value"/>)); + </xsp:logic> + </xsl:template> + <xsl:template match="xsp-response:set-int-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> + <xsl:choose> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:otherwise> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> <xsp:logic> - XSPResponseHelper.setHeader(objectModel, <xsl:value-of select="$name"/>, <xsl:value-of select="$value"/>); + response.setIntHeader(String.valueOf(<xsl:copy-of select="$name"/>), + Integer.parseInt(String.valueOf(<xsl:copy-of select="$value"/>))); </xsp:logic> </xsl:template> + + + <xsl:template name="value-for-as"> + <xsl:param name="default"/> + <xsl:choose> + <xsl:when test="@as"><xsl:value-of select="@as"/></xsl:when> + <xsl:otherwise><xsl:value-of select="$default"/></xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template name="value-for-name"> + <xsl:choose> + <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when> + <xsl:when test="xsp-response:name"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:name"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="get-nested-content"> <xsl:param name="content"/> <xsl:choose> @@ -60,7 +343,7 @@ <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise> </xsl:choose> </xsl:template> - + <xsl:template match="@*|*|text()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|*|text()|processing-instruction()"/> 1.4 +3 -3 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl Index: xsp.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- xsp.xsl 6 Feb 2002 04:40:28 -0000 1.3 +++ xsp.xsl 11 Feb 2002 04:36:38 -0000 1.4 @@ -12,7 +12,7 @@ <!-- * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> * @author <a href="[EMAIL PROTECTED]">Sylvain Wallez</a> - * @version CVS $Revision: 1.3 $ $Date: 2002/02/06 04:40:28 $ + * @version CVS $Revision: 1.4 $ $Date: 2002/02/11 04:36:38 $ --> <!-- XSP Core logicsheet for the Java language --> @@ -100,8 +100,8 @@ /* Built-in parameters available for use */ // context - ServletContext - // request - HttpServletRequest - // response - HttpServletResponse + // request - org.apache.cocoon.environment.Request + // response - org.apache.cocoon.environment.Response // parameters - parameters defined in the sitemap /* User Class Declarations */ 1.2 +4 -2 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/javascript/request.xsl Index: request.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/javascript/request.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- request.xsl 9 Feb 2002 04:16:38 -0000 1.1 +++ request.xsl 11 Feb 2002 04:36:38 -0000 1.2 @@ -12,7 +12,7 @@ <!-- * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]>Vadim Gritsenko</a> - * @version CVS $Revision: 1.1 $ $Date: 2002/02/09 04:16:38 $ + * @version CVS $Revision: 1.2 $ $Date: 2002/02/11 04:36:38 $ --> <!-- XSP Request logicsheet for the Javascript language --> @@ -418,7 +418,9 @@ </xsl:when> <xsl:when test="$as = 'xml'"> <xsp:element name="xsp-request:attribute"> - <xsp:attribute name="name" value="{$name}"/> + <xsp:attribute name="name"> + <xsp:expr><xsl:copy-of select="$name"/></xsp:expr> + </xsp:attribute> <xsp:expr>request.getAttribute(<xsl:copy-of select="$name"/>)</xsp:expr> </xsp:element> </xsl:when> 1.2 +295 -14 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/javascript/response.xsl Index: response.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/javascript/response.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- response.xsl 9 Feb 2002 04:16:38 -0000 1.1 +++ response.xsl 11 Feb 2002 04:36:38 -0000 1.2 @@ -10,30 +10,141 @@ --> <!-- - * @author <a href="mailto:[EMAIL PROTECTED]>Vadim Gritsenko</a> - * @version CVS $Revision: 1.1 $ $Date: 2002/02/09 04:16:38 $ + * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> + * @version CVS $Revision: 1.2 $ $Date: 2002/02/11 04:36:38 $ --> -<!-- XSP Response logicsheet for the Javascript language --> -<xsl:stylesheet - version="1.0" - xmlns:xsp="http://apache.org/xsp" - xmlns:xsp-response="http://apache.org/xsp/response/2.0" +<!-- XSP Response logicsheet for the Java language --> +<xsl:stylesheet version="1.0" + xmlns:xsp="http://apache.org/xsp" + xmlns:xsp-response="http://apache.org/xsp/response/2.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - xmlns:xsl="http://www.w3.org/1999/XSL/Transform" -> - <xsl:template match="xsp-response:set-header"> + + <xsl:template match="xsp-response:get-character-encoding"> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'string'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>response.getCharacterEncoding()</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:character-encoding"> + <xsp:expr>response.getCharacterEncoding()</xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:get-locale"> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'object'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>String(response.getLocale())</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'object'"> + <xsp:expr>response.getLocale()</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:logic> + page.responseGetLocale(); + </xsp:logic> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:set-locale"> + <xsp:logic> + response.setLocale( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template>); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-cookie"> + <xsp:logic> + response.addCookie( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template>); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-date-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="date"> + <xsl:choose> + <xsl:when test="@date">"<xsl:value-of select="@date"/>"</xsl:when> + <xsl:when test="xsp-response:date"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:date"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="format"> + <xsl:choose> + <xsl:when test="@format">"<xsl:value-of select="@format"/>"</xsl:when> + <xsl:when test="xsp-response:format"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:format"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + <xsl:choose> + <xsl:when test="$format != 'null'"> + page.addDateHeader(String(<xsl:copy-of select="$name"/>), + (<xsl:copy-of select="$date"/>), + (<xsl:copy-of select="$format"/>)); + </xsl:when> + <xsl:otherwise> + page.addDateHeader(String(<xsl:copy-of select="$name"/>), + (<xsl:copy-of select="$date"/>)); + </xsl:otherwise> + </xsl:choose> + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:add-header"> <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> <xsl:choose> - <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when> - <xsl:when test="xsp-response:name"> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:when test="xsp-response:value"> <xsl:call-template name="get-nested-content"> - <xsl:with-param name="content" select="xsp-response:name"/> + <xsl:with-param name="content" select="xsp-response:value"/> </xsl:call-template> </xsl:when> + <xsl:otherwise>null</xsl:otherwise> </xsl:choose> </xsl:variable> + <xsp:logic> + response.addHeader( + String(<xsl:copy-of select="$name"/>), + String(<xsl:copy-of select="$value"/>)); + </xsp:logic> + </xsl:template> + <xsl:template match="xsp-response:add-int-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> <xsl:variable name="value"> <xsl:choose> <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> @@ -42,15 +153,185 @@ <xsl:with-param name="content" select="xsp-response:value"/> </xsl:call-template> </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + response.addIntHeader( + String(<xsl:copy-of select="$name"/>), + String(<xsl:copy-of select="$value"/>)); + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:contains-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'boolean'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'boolean'"> + <xsp:expr>response.containsHeader(String(<xsl:copy-of select="$name"/>))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'string'"> + <xsp:expr>String(response.containsHeader( + String(<xsl:copy-of select="$name"/>)))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:contains-header"> + <xsp:expr>response.containsHeader(String(<xsl:copy-of select="$name"/>))</xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:encode-url"> + <xsl:variable name="url"> + <xsl:choose> + <xsl:when test="@url">"<xsl:value-of select="@url"/>"</xsl:when> + <xsl:when test="xsp-response:url"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:url"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="as"> + <xsl:call-template name="value-for-as"> + <xsl:with-param name="default" select="'string'"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$as = 'string'"> + <xsp:expr>response.encodeURL(String(<xsl:copy-of select="$url"/>))</xsp:expr> + </xsl:when> + <xsl:when test="$as = 'xml'"> + <xsp:element name="xsp-response:encode-url"> + <xsp:expr> + response.encodeURL(String(<xsl:copy-of select="$url"/>)) + </xsp:expr> + </xsp:element> + </xsl:when> + </xsl:choose> + </xsl:template> + + <xsl:template match="xsp-response:set-date-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="date"> + <xsl:choose> + <xsl:when test="@date">"<xsl:value-of select="@date"/>"</xsl:when> + <xsl:when test="xsp-response:date"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:date"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="format"> + <xsl:choose> + <xsl:when test="@format">"<xsl:value-of select="@format"/>"</xsl:when> + <xsl:when test="xsp-response:format"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:format"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsp:logic> + <xsl:choose> + <xsl:when test="$format"> + page.setDateHeader( + String(<xsl:copy-of select="$name"/>), + String( + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="$date"/> + </xsl:call-template> + ), + String(<xsl:copy-of select="$format"/>)); + </xsl:when> + <xsl:otherwise> + page.setDateHeader( + String(<xsl:copy-of select="$name"/>), + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="$date"/> + </xsl:call-template>); + </xsl:otherwise> + </xsl:choose> + </xsp:logic> + </xsl:template> + + <xsl:template match="xsp-response:set-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> + <xsl:choose> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:when test="."> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template> + </xsl:when> <xsl:otherwise>""</xsl:otherwise> </xsl:choose> </xsl:variable> + <xsp:logic> + response.setHeader( + String(<xsl:copy-of select="$name"/>), + String(<xsl:copy-of select="$value"/>)); + </xsp:logic> + </xsl:template> + <xsl:template match="xsp-response:set-int-header"> + <xsl:variable name="name"> + <xsl:call-template name="value-for-name"/> + </xsl:variable> + <xsl:variable name="value"> + <xsl:choose> + <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when> + <xsl:otherwise> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="."/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> <xsp:logic> - page.setHeader(<xsl:value-of select="$name"/>, <xsl:value-of select="$value"/>); + response.setIntHeader(String(<xsl:copy-of select="$name"/>), + String(<xsl:copy-of select="$value"/>)); </xsp:logic> </xsl:template> + + + <xsl:template name="value-for-as"> + <xsl:param name="default"/> + <xsl:choose> + <xsl:when test="@as"><xsl:value-of select="@as"/></xsl:when> + <xsl:otherwise><xsl:value-of select="$default"/></xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template name="value-for-name"> + <xsl:choose> + <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when> + <xsl:when test="xsp-response:name"> + <xsl:call-template name="get-nested-content"> + <xsl:with-param name="content" select="xsp-response:name"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>null</xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="get-nested-content"> <xsl:param name="content"/> <xsl:choose> @@ -60,7 +341,7 @@ <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise> </xsl:choose> </xsl:template> - + <xsl:template match="@*|*|text()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]