You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Saraswati Sivasankar (sasivasa)" <sa...@cisco.com> on 2004/05/19 12:04:59 UTC

Context object - decode

Hi,
 
I am working on a requirement that needs to decode the value in the
'context' that is put after encoding the same using the java URLEncoder
class.

/*********** Start of code **********/
String bookmarkName =
URLEncoder.encode(request.getParameter("txtName"),"UTF-8");
String bookmarkUrl =
URLEncoder.encode(request.getParameter("txtUrl"),"UTF-8");

context.put("bookmarkname",bookmarkName);
context.put("bookmarkurl",bookmarkUrl);
/*********** end of code **********/

How do I decode this using VTL?
 
Thanks and Regards,
Saraswati


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re[2]: Capture directive

Posted by Stan Devyatovsky <st...@devyatovsky.com>.
Hello Nathan,

 Thanks for the info, Nathan! I will try searching the archive.
 Still, I think this directive would be worth including it in official
 package. I think it should be not difficult to implement.
>> Velocity has "set" directive:
>> #set($a = "text text text")
>>
>> Now is there something like #capture directive in Velocity?
>>
>> #capture($a)
>> text text
>> multiline text
>> <html tags here... />
>> #end
>>
>> So that $a variable would be assigned the content between "capture"
>> and "end"?


NB> there's nothing official, but there have been a few custom directives that do
NB> this posted over the years.  it seems to me there was one posted about a year
NB> ago or so that was called #define and works like yours below.  try searching
NB> the archives for it.  if you can't find it, i think i still have a copy saved
NB> somewhere and i can repost it.

NB> oh, and i'm pretty sure that the current CVS HEAD of velocity supports line
NB> breaks in #set() statements, so you could do:

NB> #set( $a = "
NB> text text
NB> multiline text
NB> <html tags here... />
NB> " )

NB> but that's a slightly different thing functionally.

NB> Nathan Bubna
NB> nathan@esha.com


NB> ---------------------------------------------------------------------
NB> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
NB> For additional commands, e-mail: velocity-user-help@jakarta.apache.org




-- 
Best regards,
 Stan                            mailto:stan@devyatovsky.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Capture directive

Posted by Nathan Bubna <na...@esha.com>.
Stan Devyatovsky said:
> Velocity has "set" directive:
> #set($a = "text text text")
>
> Now is there something like #capture directive in Velocity?
>
> #capture($a)
> text text
> multiline text
> <html tags here... />
> #end
>
> So that $a variable would be assigned the content between "capture"
> and "end"?


there's nothing official, but there have been a few custom directives that do
this posted over the years.  it seems to me there was one posted about a year
ago or so that was called #define and works like yours below.  try searching
the archives for it.  if you can't find it, i think i still have a copy saved
somewhere and i can repost it.

oh, and i'm pretty sure that the current CVS HEAD of velocity supports line
breaks in #set() statements, so you could do:

#set( $a = "
text text
multiline text
<html tags here... />
" )

but that's a slightly different thing functionally.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Capture directive

Posted by Stan Devyatovsky <st...@devyatovsky.com>.
Hello,

Velocity has "set" directive:
#set($a = "text text text")

Now is there something like #capture directive in Velocity?

#capture($a)
text text
multiline text
<html tags here... />
#end

So that $a variable would be assigned the content between "capture"
and "end"?

-- 
Best regards,
 Stan                            mailto:stan@devyatovsky.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Display timestamp in VM - Urgent

Posted by Mike Kienenberger <mk...@alaska.net>.
The Velocity-Tools DateTool can also provide all of this without code 
support.

http://www.jajakarta.org/velocity/tools/velocity-tools-
1.1/docs/generic/DateTool.html

-Mike


Will Glass-Husain <wg...@forio.com> wrote:
> Put a date object in the context
> 
> context.put("today",new Date());
> 
> Then in VTL say:
> 
> $today
> 
> ----- Original Message ----- 
> From: "Saraswati Sivasankar (sasivasa)" <sa...@cisco.com>
> To: "'Velocity Users List'" <ve...@jakarta.apache.org>
> Sent: Monday, July 19, 2004 9:51 PM
> Subject: Display timestamp in VM - Urgent
> 
> > What is the best way to display timestamp in VTL ?
> > Is there any way other than using the java methods from context?
> > 
> > Any info would help.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Display timestamp in VM - Urgent

Posted by Will Glass-Husain <wg...@forio.com>.
Put a date object in the context

context.put("today",new Date());

Then in VTL say:

$today

WILL

----- Original Message ----- 
From: "Saraswati Sivasankar (sasivasa)" <sa...@cisco.com>
To: "'Velocity Users List'" <ve...@jakarta.apache.org>
Sent: Monday, July 19, 2004 9:51 PM
Subject: Display timestamp in VM - Urgent


> 
> Hi,
> What is the best way to display timestamp in VTL ?
> Is there any way other than using the java methods from context?
> 
> Any info would help.
> 
> Regards!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Display timestamp in VM - Urgent

Posted by "Saraswati Sivasankar (sasivasa)" <sa...@cisco.com>.
Hi,
What is the best way to display timestamp in VTL ?
Is there any way other than using the java methods from context?

Any info would help.

Regards!


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: How to handle data in request object with space?

Posted by Ma...@prg.co.nz.
Hmm,

$bookmarkdtl should be an array in IMO. In order to access the single 
elements you could do a
#foreach loop.

Context data:

        VelocityContext context = new VelocityContext();
        Map map = new Hashtable();
        map.put("arr", new Object[] {"Abc", "die Katze","liegt im Schnee"
});
        context.put("map", map);
        ...

Template:

        #set( $fooBar = $map.get('arr') )
        #foreach( $name in $fooBar )
         $name
        #end

mano





"Saraswati Sivasankar \(sasivasa\)" <sa...@cisco.com> 
21/06/2004 17:15
Please respond to
"Velocity Users List" <ve...@jakarta.apache.org>


To
"'Velocity Users List'" <ve...@jakarta.apache.org>
cc

Subject
How to handle data in request object with space?






Hi,

I am trying to get data from 'request' object in my VM file through code
below. 
#set($bookmarkdtl = $data.Request.getAttribute('bkmrkdtl'))

However, I notice that the data after any space character is not 
retrieved.
Eg. If data in the request object is an arraylist of values as below, 
request.setAttribute("bkmrkdtl",alDetails);

The data retrieved through #set($bookmarkdtl =
$data.Request.getAttribute('bkmrkdtl')) does not retrieve complete data. 
If
anyone has any solution, pls do share with me.

Regards,
Saraswati


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org



How to handle data in request object with space?

Posted by "Saraswati Sivasankar (sasivasa)" <sa...@cisco.com>.
Hi,

I am trying to get data from 'request' object in my VM file through code
below. 
#set($bookmarkdtl = $data.Request.getAttribute('bkmrkdtl'))

However, I notice that the data after any space character is not retrieved.
Eg. If data in the request object is an arraylist of values as below, 
request.setAttribute("bkmrkdtl",alDetails);

The data retrieved through #set($bookmarkdtl =
$data.Request.getAttribute('bkmrkdtl')) does not retrieve complete data. If
anyone has any solution, pls do share with me.

Regards,
Saraswati


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Context object - decode

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On May 19, 2004, at 11:23 AM, Mike Kienenberger wrote:

> Geir Magnusson Jr <ge...@4quarters.com> wrote:
>>
>> On May 19, 2004, at 6:04 AM, Saraswati Sivasankar (sasivasa) wrote:
>>> I am working on a requirement that needs to decode the value in the
>>> 'context' that is put after encoding the same using the java 
>>> URLEncoder
>>> class.
>>>
>>> How do I decode this using VTL?
>>
>> If the tools project doesn't already have one (they probably do), make
>> a little tool.  You need to make a tool and put it in the context, and
>> then use in vtl :
>>
>> $myTool.decode($bookmarkname)
>
>
> Based on an answer from Nathan Bubna for a similar question I once 
> asked,
>
> In the toolbox.xml file:
>
> <tool>
>     <key>URLDecoder</key>
>     <class>java.net.URLDecoder</class>
> </tool>
>
> In your template:
>
> $URLDecoder.decode($bookmarkname,"UTF-8")
>
>

Sure, that could work.  But I tend to make a tool because some genius 
at Sun decided that having a class that did encoding *and* decoding was 
too much to do at once, so you need one tool for each.

geir

-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Context object - decode

Posted by Mike Kienenberger <mk...@alaska.net>.
Geir Magnusson Jr <ge...@4quarters.com> wrote:
> 
> On May 19, 2004, at 6:04 AM, Saraswati Sivasankar (sasivasa) wrote:
> > I am working on a requirement that needs to decode the value in the
> > 'context' that is put after encoding the same using the java URLEncoder
> > class.
> >
> > How do I decode this using VTL?
> 
> If the tools project doesn't already have one (they probably do), make 
> a little tool.  You need to make a tool and put it in the context, and 
> then use in vtl :
> 
> $myTool.decode($bookmarkname)


Based on an answer from Nathan Bubna for a similar question I once asked,

In the toolbox.xml file:

<tool>
    <key>URLDecoder</key>
    <class>java.net.URLDecoder</class>
</tool>

In your template:

$URLDecoder.decode($bookmarkname,"UTF-8")



Nathan Bubna <na...@esha.com> wrote:
> 
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringEscapeUtils.html
> 
> <tool>
>     <key>escape</key>
>     <class>org.apache.commons.lang.StringEscapeUtils</class>
> </tool>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Context object - decode

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On May 19, 2004, at 6:04 AM, Saraswati Sivasankar (sasivasa) wrote:

> Hi,
>
> I am working on a requirement that needs to decode the value in the
> 'context' that is put after encoding the same using the java URLEncoder
> class.
>
> /*********** Start of code **********/
> String bookmarkName =
> URLEncoder.encode(request.getParameter("txtName"),"UTF-8");
> String bookmarkUrl =
> URLEncoder.encode(request.getParameter("txtUrl"),"UTF-8");
>
> context.put("bookmarkname",bookmarkName);
> context.put("bookmarkurl",bookmarkUrl);
> /*********** end of code **********/
>
> How do I decode this using VTL?

If the tools project doesn't already have one (they probably do), make 
a little tool.  You need to make a tool and put it in the context, and 
then use in vtl :

$myTool.decode($bookmarkname)


>
> Thanks and Regards,
> Saraswati
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org