You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Sebastian Gumpold <se...@sbs.co.at> on 2007/04/23 16:06:29 UTC

VelocityFormatter.limitLen() depricated

Hi all!

I'm new to Velocity and tried to find a way to limit the length of an 
String. The solution I found worked great for my needs: 
VelocityFormatter.limitLen().
Much to my regret I noticed that with Velocity 1.5 (and Tools 1.3) 
VelocityFormatter got marked as depricated and I didn't find a proper 
replacement for this method in any of the both suggested Tools classes 
NumberTool and DateTool.

So here's my question: What's the suggested way to handle this: the usage 
of other Tools classes? Own code?

Thanks in advance,
Sebastian

Re: VelocityFormatter.limitLen() depricated

Posted by ap...@recks.org.
I opened a Jira issue on this:
  http://issues.apache.org/jira/browse/VELOCITY-540

:) Christoph

Nathan Bubna wrote:
> On 4/24/07, apache@recks.org <ap...@recks.org> wrote:
>> this example brings up the issue of making #local(...) a
>> core directive:
> 
> i'm always forgetting that #local is out there.  do we have a JIRA
> issue open about putting this in the core?  even if we couldn't reach
> consensus there (and with the #springBind issue, i'm sure we're
> getting closer to that), then it would be a good reminder and a place
> to keep discussion centralized.
> 
>> > #macro( truncate $stringVariable $length )
>> #local( $truncateMe )
>> > #set( $truncateMe = "$!stringVariable" )
>> > #if( $truncateMe.length() <=
>> > $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
>> #end
>> > #end
>>
>> I prefer #local vs velocimacro.context.localscope because
>> you can create macro libraries that allow declaring local vars
>> without polluting the namespace, but also enables setting global
>> variables. See the thread ending on 16.04.2007 "RE:
>> velocimacro.context.localscope"
>> with the #springBind example for such a case.
>>
>> :) Chirstoph
>>
[snip]

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


Re: VelocityFormatter.limitLen() depricated

Posted by Nathan Bubna <nb...@gmail.com>.
On 4/24/07, apache@recks.org <ap...@recks.org> wrote:
> this example brings up the issue of making #local(...) a
> core directive:

i'm always forgetting that #local is out there.  do we have a JIRA
issue open about putting this in the core?  even if we couldn't reach
consensus there (and with the #springBind issue, i'm sure we're
getting closer to that), then it would be a good reminder and a place
to keep discussion centralized.

> > #macro( truncate $stringVariable $length )
> #local( $truncateMe )
> > #set( $truncateMe = "$!stringVariable" )
> > #if( $truncateMe.length() <=
> > $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
> #end
> > #end
>
> I prefer #local vs velocimacro.context.localscope because
> you can create macro libraries that allow declaring local vars
> without polluting the namespace, but also enables setting global
> variables. See the thread ending on 16.04.2007 "RE: velocimacro.context.localscope"
> with the #springBind example for such a case.
>
> :) Chirstoph
>
> Nathan Bubna wrote:
> > Sorry, i didn't realize we had not fully covered the functions of
> > VelocityFormatter in Tools.  Looks like we missed some utils for
> > formatting arrays/vectors too.  I'll have to think about where to add
> > these.
> >
> > In the meantime, i suppose i would recommend writing a tool or macro
> > of your own.  The code can be copied straight out of VelocityFormatter
> > or written to suit you.  We have typically used a #truncate
> > velocimacro to do this in our apps:
> >
> > #macro( truncate $stringVariable $length )
> > #set( $truncateMe = "$!stringVariable" )
> > #if( $truncateMe.length() <=
> > $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
> > #end
> >
> >
> > On 4/23/07, Sebastian Gumpold <se...@sbs.co.at> wrote:
> >> Hi all!
> >>
> >> I'm new to Velocity and tried to find a way to limit the length of an
> >> String. The solution I found worked great for my needs:
> >> VelocityFormatter.limitLen().
> >> Much to my regret I noticed that with Velocity 1.5 (and Tools 1.3)
> >> VelocityFormatter got marked as depricated and I didn't find a proper
> >> replacement for this method in any of the both suggested Tools classes
> >> NumberTool and DateTool.
> >>
> >> So here's my question: What's the suggested way to handle this: the usage
> >> of other Tools classes? Own code?
> >>
> >> Thanks in advance,
> >> Sebastian
> >
> > ---------------------------------------------------------------------
> > 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: VelocityFormatter.limitLen() depricated

Posted by ap...@recks.org.
this example brings up the issue of making #local(...) a
core directive:

> #macro( truncate $stringVariable $length )
#local( $truncateMe )
> #set( $truncateMe = "$!stringVariable" )
> #if( $truncateMe.length() <=
> $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
#end
> #end

I prefer #local vs velocimacro.context.localscope because
you can create macro libraries that allow declaring local vars
without polluting the namespace, but also enables setting global
variables. See the thread ending on 16.04.2007 "RE: velocimacro.context.localscope"
with the #springBind example for such a case.

:) Chirstoph

Nathan Bubna wrote:
> Sorry, i didn't realize we had not fully covered the functions of
> VelocityFormatter in Tools.  Looks like we missed some utils for
> formatting arrays/vectors too.  I'll have to think about where to add
> these.
> 
> In the meantime, i suppose i would recommend writing a tool or macro
> of your own.  The code can be copied straight out of VelocityFormatter
> or written to suit you.  We have typically used a #truncate
> velocimacro to do this in our apps:
> 
> #macro( truncate $stringVariable $length )
> #set( $truncateMe = "$!stringVariable" )
> #if( $truncateMe.length() <=
> $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
> #end
> 
> 
> On 4/23/07, Sebastian Gumpold <se...@sbs.co.at> wrote:
>> Hi all!
>>
>> I'm new to Velocity and tried to find a way to limit the length of an
>> String. The solution I found worked great for my needs:
>> VelocityFormatter.limitLen().
>> Much to my regret I noticed that with Velocity 1.5 (and Tools 1.3)
>> VelocityFormatter got marked as depricated and I didn't find a proper
>> replacement for this method in any of the both suggested Tools classes
>> NumberTool and DateTool.
>>
>> So here's my question: What's the suggested way to handle this: the usage
>> of other Tools classes? Own code?
>>
>> Thanks in advance,
>> Sebastian
> 
> ---------------------------------------------------------------------
> 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: VelocityFormatter.limitLen() depricated

Posted by Nathan Bubna <nb...@gmail.com>.
Sorry, i didn't realize we had not fully covered the functions of
VelocityFormatter in Tools.  Looks like we missed some utils for
formatting arrays/vectors too.  I'll have to think about where to add
these.

In the meantime, i suppose i would recommend writing a tool or macro
of your own.  The code can be copied straight out of VelocityFormatter
or written to suit you.  We have typically used a #truncate
velocimacro to do this in our apps:

#macro( truncate $stringVariable $length )
#set( $truncateMe = "$!stringVariable" )
#if( $truncateMe.length() <=
$length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
#end


On 4/23/07, Sebastian Gumpold <se...@sbs.co.at> wrote:
> Hi all!
>
> I'm new to Velocity and tried to find a way to limit the length of an
> String. The solution I found worked great for my needs:
> VelocityFormatter.limitLen().
> Much to my regret I noticed that with Velocity 1.5 (and Tools 1.3)
> VelocityFormatter got marked as depricated and I didn't find a proper
> replacement for this method in any of the both suggested Tools classes
> NumberTool and DateTool.
>
> So here's my question: What's the suggested way to handle this: the usage
> of other Tools classes? Own code?
>
> Thanks in advance,
> Sebastian

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