You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by mailmur <ma...@yahoo.com> on 2007/08/01 08:36:28 UTC
Re: Unicode in Velocity
http://koti.mbnet.fi/akini/java/unicodereader/
http://koti.mbnet.fi/akini/java/java_utf8_xml/
Velocity 1.5+ has UnicodeFileResourceLoader loader
implementation. You can save .vm files as UTF-8 (with
or without BOM) text files. It saves you all the
troubles.
Only issue then is to make sure you send HttpResponse
headers accordingly.
Content-Type: text/html; charset=UTF-8
--- "Gary M. Catlin" <gc...@gmail.com> wrote:
> How do I assign and output a unicode character in
> velocity? I need to
> output the value of "f00b" prior to a block of
> calculated output.
>
> TIA
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Unicode in Velocity
Posted by "Gary M. Catlin" <gc...@gmail.com>.
Thank you, Nathan. I'll let you know how it works.
gmc
Nathan Bubna wrote:
> On 8/8/07, Gary M. Catlin <gc...@gmail.com> wrote:
>
>> Thank you for the reply, but not sure if that will help. My solution
>> needs to be at a higher level. I need to "set" a variable with a unicode
>> value, and to output this value before and after a block of output:
>>
>> #set ($v = "\uf00b")
>>
>
> Unfortunately, this was broken. It has been fixed in Velocity 1.6 though.
> https://issues.apache.org/jira/browse/VELOCITY-520
>
> If you aren't interested in building 1.6 from source yourself (it has
> no releases yet), then you could create a "tool" that creates
> arbitrary unicode characters for you. Since i was curious of how to
> do this myself, i wrote one for you:
>
> public class UnicodeTool
> {
> public static String get(String code)
> {
> if (code != null && code.startsWith("\\u"))
> {
> code = code.substring(2, code.length());
> }
> return get(Integer.valueOf(code,16));
> }
>
> public static String get(int codePoint)
> {
> return String.valueOf(Character.toChars(codePoint));
> }
> }
>
> Just put an instance in the context as "unicode" and use it in the
> template like this:
>
> #set( $v = $unicode.get('f00b') )
>
>
>> $v
>> $myBlockOutput
>> $v
>>
>> The problem has been assigning the unicode value. The standard 'escape'
>> does not seem to be working. We are using Velocity 1.5.
>>
>> Thank you.
>>
>>
>> mailmur wrote:
>>
>>> http://koti.mbnet.fi/akini/java/unicodereader/
>>> http://koti.mbnet.fi/akini/java/java_utf8_xml/
>>>
>>> Velocity 1.5+ has UnicodeFileResourceLoader loader
>>> implementation. You can save .vm files as UTF-8 (with
>>> or without BOM) text files. It saves you all the
>>> troubles.
>>>
>>> Only issue then is to make sure you send HttpResponse
>>> headers accordingly.
>>> Content-Type: text/html; charset=UTF-8
>>>
>>> --- "Gary M. Catlin" <gc...@gmail.com> wrote:
>>>
>>>
>>>
>>>> How do I assign and output a unicode character in
>>>> velocity? I need to
>>>> output the value of "f00b" prior to a block of
>>>> calculated output.
>>>>
>>>> TIA
>>>>
>>>>
>>>
>>>
>>> ____________________________________________________________________________________
>>> Pinpoint customers who are looking for what you sell.
>>> http://searchmarketing.yahoo.com/
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Unicode in Velocity
Posted by Nathan Bubna <nb...@gmail.com>.
On 8/8/07, Gary M. Catlin <gc...@gmail.com> wrote:
> Thank you for the reply, but not sure if that will help. My solution
> needs to be at a higher level. I need to "set" a variable with a unicode
> value, and to output this value before and after a block of output:
>
> #set ($v = "\uf00b")
Unfortunately, this was broken. It has been fixed in Velocity 1.6 though.
https://issues.apache.org/jira/browse/VELOCITY-520
If you aren't interested in building 1.6 from source yourself (it has
no releases yet), then you could create a "tool" that creates
arbitrary unicode characters for you. Since i was curious of how to
do this myself, i wrote one for you:
public class UnicodeTool
{
public static String get(String code)
{
if (code != null && code.startsWith("\\u"))
{
code = code.substring(2, code.length());
}
return get(Integer.valueOf(code,16));
}
public static String get(int codePoint)
{
return String.valueOf(Character.toChars(codePoint));
}
}
Just put an instance in the context as "unicode" and use it in the
template like this:
#set( $v = $unicode.get('f00b') )
> $v
> $myBlockOutput
> $v
>
> The problem has been assigning the unicode value. The standard 'escape'
> does not seem to be working. We are using Velocity 1.5.
>
> Thank you.
>
>
> mailmur wrote:
> > http://koti.mbnet.fi/akini/java/unicodereader/
> > http://koti.mbnet.fi/akini/java/java_utf8_xml/
> >
> > Velocity 1.5+ has UnicodeFileResourceLoader loader
> > implementation. You can save .vm files as UTF-8 (with
> > or without BOM) text files. It saves you all the
> > troubles.
> >
> > Only issue then is to make sure you send HttpResponse
> > headers accordingly.
> > Content-Type: text/html; charset=UTF-8
> >
> > --- "Gary M. Catlin" <gc...@gmail.com> wrote:
> >
> >
> >> How do I assign and output a unicode character in
> >> velocity? I need to
> >> output the value of "f00b" prior to a block of
> >> calculated output.
> >>
> >> TIA
> >>
> >
> >
> >
> >
> > ____________________________________________________________________________________
> > Pinpoint customers who are looking for what you sell.
> > http://searchmarketing.yahoo.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Unicode in Velocity
Posted by "Gary M. Catlin" <gc...@gmail.com>.
Thank you for the reply, but not sure if that will help. My solution
needs to be at a higher level. I need to "set" a variable with a unicode
value, and to output this value before and after a block of output:
#set ($v = "\uf00b")
$v
$myBlockOutput
$v
The problem has been assigning the unicode value. The standard 'escape'
does not seem to be working. We are using Velocity 1.5.
Thank you.
mailmur wrote:
> http://koti.mbnet.fi/akini/java/unicodereader/
> http://koti.mbnet.fi/akini/java/java_utf8_xml/
>
> Velocity 1.5+ has UnicodeFileResourceLoader loader
> implementation. You can save .vm files as UTF-8 (with
> or without BOM) text files. It saves you all the
> troubles.
>
> Only issue then is to make sure you send HttpResponse
> headers accordingly.
> Content-Type: text/html; charset=UTF-8
>
> --- "Gary M. Catlin" <gc...@gmail.com> wrote:
>
>
>> How do I assign and output a unicode character in
>> velocity? I need to
>> output the value of "f00b" prior to a block of
>> calculated output.
>>
>> TIA
>>
>
>
>
>
> ____________________________________________________________________________________
> Pinpoint customers who are looking for what you sell.
> http://searchmarketing.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org