You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Bruce Altner <ba...@hq.nasa.gov> on 2001/11/17 15:08:55 UTC

stringSubstitution()

Sorry, I sent this under an incorrect subject heading. Let me try again...


I apparently need help understaning how to use the stringSubstitution() 
method in the StringUtils class.  For a test I just wanted to
replace "!" with "?".

Here is a code snippet from the calling class:


         Hashtable rt = new Hashtable();
         rt.put("!","?");
         context.put ("utils", new StringUtils());   //so that I can use 
StringUtils methods
         context.put("rt",rt); 
//stringSubstitution requires a Hashtable of substitution values


The template I merge with this has the following:

#set ($teststring = "Are you going to Scarboro Fair!")
$rt
After substituion "$teststring" becomes 
"$utils.stringSubstitution($teststring,$rt)"

which comes out this way...

{!=?}
After substituion "Are you going to Scarboro Fair!" becomes "Are you going 
to Scarboro Fair!"

 From the first line of output I see that the replacement table (rt) is 
available but the string is not being replaced.
I must be missing the point of this method entirely. Can anyone explain it?

Thanks,
Bruce 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Error reporting in Error.vm

Posted by Dan Bachelder <ch...@chowda.net>.
It is a turbine question...

you need to do something like data.setStackTrace() and data.setTemplate()...
try turbine-user@jakarta.apache.org

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Saturday, November 17, 2001 12:10 PM
Subject: Re: Error reporting in Error.vm


> On 11/17/01 12:09 PM, "Bruce Altner" <ba...@hq.nasa.gov> wrote:
>
> > Greetings:
> >
> > I have combed the docs but can't find the answer to this one:
> >
> > I am encountering ParseErrorExceptions which are dutifully reported in
> > velocity.log. My question is how to get the message or stacktrace to
appear
> > in Error.vm...or is Error.vm specifically for graceful exits only. Are
the
> > exceptions stuffed into the context, and, if so, how do I pull them out?
>
> What is Error.vm?
>
> --
> Geir Magnusson Jr.                       geirm@optonline.net
> System and Software Consulting
> You're going to end up getting pissed at your software
> anyway, so you might as well not pay for it. Try Open Source.
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Error reporting in Error.vm

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/17/01 12:09 PM, "Bruce Altner" <ba...@hq.nasa.gov> wrote:

> Greetings:
> 
> I have combed the docs but can't find the answer to this one:
> 
> I am encountering ParseErrorExceptions which are dutifully reported in
> velocity.log. My question is how to get the message or stacktrace to appear
> in Error.vm...or is Error.vm specifically for graceful exits only. Are the
> exceptions stuffed into the context, and, if so, how do I pull them out?

What is Error.vm?

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Error reporting in Error.vm

Posted by Bruce Altner <ba...@hq.nasa.gov>.
Greetings:

I have combed the docs but can't find the answer to this one:

I am encountering ParseErrorExceptions which are dutifully reported in 
velocity.log. My question is how to get the message or stacktrace to appear 
in Error.vm...or is Error.vm specifically for graceful exits only. Are the 
exceptions stuffed into the context, and, if so, how do I pull them out?

Thanks,
Bruce
_________________________________________________________________
"It's a magical world, Hobbes, ol' buddy...let's go exploring!" ---Calvin

Phone: 202-651-8553
Pager Email:8273479@skytel.com




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: stringSubstitution()...never mind!

Posted by Bruce Altner <ba...@hq.nasa.gov>.
I apologize for answering my own question, but never mind. I took a look at 
the source code and all is clear now. Next time I will do that first.

Thanks,
Bruce



>I apparently need help understaning how to use the stringSubstitution() 
>method in the StringUtils class.  For a test I just wanted to
>replace "!" with "?".
>
>Here is a code snippet from the calling class:
>
>
>         Hashtable rt = new Hashtable();
>         rt.put("!","?");
>         context.put ("utils", new StringUtils());   //so that I can use 
> StringUtils methods
>         context.put("rt",rt); //stringSubstitution requires a Hashtable 
> of substitution values
>
>
>The template I merge with this has the following:
>
>#set ($teststring = "Are you going to Scarboro Fair!")
>$rt
>After substituion "$teststring" becomes 
>"$utils.stringSubstitution($teststring,$rt)"
>
>which comes out this way...
>
>{!=?}
>After substituion "Are you going to Scarboro Fair!" becomes "Are you going 
>to Scarboro Fair!"
>
> From the first line of output I see that the replacement table (rt) is 
> available but the string is not being replaced.
>I must be missing the point of this method entirely. Can anyone explain it?
>
>Thanks,
>Bruce
>
>--
>To unsubscribe, 
>e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: 
><ma...@jakarta.apache.org>
>

_________________________________________________________________
"It's a magical world, Hobbes, ol' buddy...let's go exploring!" ---Calvin

Phone: 202-651-8553
Pager Email:8273479@skytel.com




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: stringSubstitution()

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/17/01 9:08 AM, "Bruce Altner" <ba...@hq.nasa.gov> wrote:

> Sorry, I sent this under an incorrect subject heading. Let me try again...
> 
> 
> I apparently need help understaning how to use the stringSubstitution()
> method in the StringUtils class.  For a test I just wanted to
> replace "!" with "?".
> 
> Here is a code snippet from the calling class:
> 
> 
>        Hashtable rt = new Hashtable();
>        rt.put("!","?");
>        context.put ("utils", new StringUtils());   //so that I can use
> StringUtils methods
>        context.put("rt",rt);
> //stringSubstitution requires a Hashtable of substitution values
> 
> 
> The template I merge with this has the following:
> 
> #set ($teststring = "Are you going to Scarboro Fair!")
> $rt
> After substituion "$teststring" becomes
> "$utils.stringSubstitution($teststring,$rt)"
> 
> which comes out this way...
> 
> {!=?}
> After substituion "Are you going to Scarboro Fair!" becomes "Are you going
> to Scarboro Fair!"
> 
> From the first line of output I see that the replacement table (rt) is
> available but the string is not being replaced.
> I must be missing the point of this method entirely. Can anyone explain it?


Yep - if you look at the code for that method, it looks for things like
$<token> in the input string.  So you have to do something like

  rt.put( "foo", "?");

and then in your template

  #set($teststring = 'Are you going $foo ' )


Note that you should use '' rather that "" to prevent velocity from trying
to render the string if you don't want variable interpolation from the
context.

Also note you could do this entierly w/in velocity proper :

#set( $foo = "?")
#set( $string = "Are you going... $foo")

$string

Would produce

Are you going.... ?

geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Be a giant.  Take giant steps.  Do giant things...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>