You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by st...@outerthought.org on 2003/02/03 02:01:04 UTC
[WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate HowTos Mon Feb 3 02:01:04 2003
Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSP+TransformCustomDate, version: 1 on Mon Feb 3 00:03:10 2003 by Scherler
New page created:
+ If you are using <esql/> you may need to transform a custom date string to a valid Java Date object.
+
+ Here is an example:
+ {{{
+ <esql:query>
+ select * from reports where date = #<xsp-request:get-parameter name="date"/>#
+ </esql:query>
+ }}}
+
+ The actual date of the <esql:query/> has to be in the format e.g. 01/29/2003, but if you are a in e.g. Germany you are used to this date format: 29.01.2003.
+
+ __Step 1__
+ Create a HTML-Form save it as date.html in your cocoon-webapp dir.
+ {{{
+ <html>
+ <head>
+ <meta name="author"content="ThorstenScherler">
+ <title>TransformCustomDate</title>
+ </head>
+ <body>
+ <p>Please press Submit.</p>
+ <form action="date.xml" method="GET">
+ <input type="text" name="date" value="29.01.2003"/>
+ <input type="submit" value="Submit"/>
+ </form>
+ </body>
+ </html>
+ }}}
+ On submit this will result in attaching __/date.xml?date=29.01.2003__ to the uri where the html form was called from.
+
+ __Step 2__
+ Create a file date.xsp and put this in your cocoon-webapp dir.
+ {{{
+ <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
+ <xsp:structure>
+ <xsp:include>java.util.*</xsp:include>
+ <xsp:include>java.text.*</xsp:include>
+ </xsp:structure>
+ <document>
+ <xsp:logic>
+ String datePattern = "dd.MM.yyyy";
+ SimpleDateFormat dateFormat = new SimpleDateFormat( datePattern );
+ String sDate_one ="";
+ try
+ {
+ sDate_one=request.getParameter("date");
+ }
+ catch( ParseException e )
+ {
+ getLogger().error("XSP param error: ", e);
+ }
+ Date date_one = null;
+ try
+ {
+ date_one = dateFormat.parse( sDate_one );
+ }
+ catch( ParseException e )
+ {
+ getLogger().error("XSP date error: ", e);
+ }
+ </xsp:logic>
+ <request>date.xml?date=<xsp:expr>sDate_one</xsp:expr>
+ </request>
+ <transformed>
+ <xsp:expr>date_one</xsp:expr>
+ </transformed>
+ </document>
+ </xsp:page>
+ }}}
+
+ __Step 3__ put this in your cocoon-webapp sitemap.xmap
+ {{{
+ <map:pipeline>
+ <map:match pattern="date">
+ <map:read src="date.html"/>
+ </map:match>
+ <map:match pattern="date.xml">
+ <map:generate type="xsp" src="date.xsp"/>
+ <map:serialize type="xml"/>
+ </map:match>
+ </map:pipeline>
+ }}}
+
+ __Testing__
+ Now request {{{http://localhost:8080/cocoon-webapp/date}}} and press the Submit-Button.
+
+ If everything works fine you will see a XML-page with a valid date.
+ If not - please check the logs.
+
+ __Modifying the date-Format__
+ {{{
+ String datePattern = "dd.MM.yyyy";
+ }}}
+ If you wish to modify the date-format please see [SimpleDateFormat Class Reference|http://oss.software.ibm.com/icu/apiref/classSimpleDateFormat.html].
+
+ Giving you an idea of how to do it:
+ {{{
+ String datePattern = "MM/dd/yyyy";
+ }}}
+ expect 01/31/2003 as the string-format.
+
+ Please let me know if you had problems with it? [Thorsten Scherler|Scherler]
+
Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSPTransformCustomDate, version: 2 on Mon Feb 3 00:06:07 2003 by Scherler
- Please let me know if you had problems with it? [Thorsten Scherler|Scherler]
? ^
+ Please let me know if you had problems with it. [Thorsten Scherler|Scherler]
? ^
Page: http://wiki.cocoondev.org/Wiki.jsp?page=HowTos, version: 56 on Mon Feb 3 00:08:52 2003 by Scherler
- * __[XSP TransformCustomDate]__ -- How to create a java date object from a date string from a request-- [Scherler]
? --------------
+ * __[XSP TransformCustomDate]__ -- How to create a java date object from a date string -- [Scherler]
Re: [WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate
HowTos Mon Feb 3 02:01:04 2003
Posted by Steven Noels <st...@outerthought.org>.
Nicola Ken Barozzi wrote:
> Why not use something like this instead?
>
> Anonymous Doc-er <co...@xml.apache.org>
>
> Actually, it was a big laugh for me, I honestly did think it was you all
> these days changing stuff :,-))
Gee. :-)
Dunnow if cocoon-docs@xml.apache.org is subscribed to self() - otherwise
seems OK to me. Having a 'real' sender address might be good if people
want to contact the owner of the script in case of errors.
</Steven>
--
Steven Noels http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org stevenn at apache.org
Re: [WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate
HowTos Mon Feb 3 02:01:04 2003
Posted by Nicola Ken Barozzi <ni...@apache.org>.
Steven Noels wrote:
> Nicola Ken Barozzi wrote:
>
>> stevenn@outerthought.org wrote:
>>
>>> Page:
>>> http://wiki.cocoondev.org/Wiki.jsp?page=XSP+TransformCustomDate,
>>> version: 1 on Mon Feb 3 00:03:10 2003 by Scherler
>>
>> Gee Steven, you sure edit *a lot* of stuff! ;-P
>>
>> The fact is that I understood it's not you... just now %-)
>
>
> I thought of using the Wiki UserName in the header, but not everybody
> 'logs in' properly. Do you want me to use your email address? ;)
I'd propose Stefano's ;-P
Why not use something like this instead?
Anonymous Doc-er <co...@xml.apache.org>
Actually, it was a big laugh for me, I honestly did think it was you all
these days changing stuff :,-))
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
Re: [WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate
HowTos Mon Feb 3 02:01:04 2003
Posted by Steven Noels <st...@outerthought.org>.
Nicola Ken Barozzi wrote:
> stevenn@outerthought.org wrote:
>
>> Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSP+TransformCustomDate,
>> version: 1 on Mon Feb 3 00:03:10 2003 by Scherler
>
>
> Gee Steven, you sure edit *a lot* of stuff! ;-P
>
> The fact is that I understood it's not you... just now %-)
I thought of using the Wiki UserName in the header, but not everybody
'logs in' properly. Do you want me to use your email address? ;)
</Steven>
--
Steven Noels http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org stevenn at apache.org
Re: [WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate
HowTos Mon Feb 3 02:01:04 2003
Posted by Nicola Ken Barozzi <ni...@apache.org>.
stevenn@outerthought.org wrote:
> Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSP+TransformCustomDate, version: 1 on Mon Feb 3 00:03:10 2003 by Scherler
Gee Steven, you sure edit *a lot* of stuff! ;-P
The fact is that I understood it's not you... just now %-)
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------