velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <>
Subject Re: Strange use of velocity - question
Date Tue, 26 Mar 2002 08:06:42 GMT
Tommy Svensson wrote:
> Hello Velocity fans,
> I'm considering using velocity as a scripting language for log searches. It
> got the simple logic I need, that almost anybody can learn. For example:
> I'll put an object in the context that has a find method that takes a string
> specifying the search, and returns an Iterator which is passed to a
> #foreach. The Iterator returns LogEntry objects. The script can then use
> data from that LogEntry to do another find using the finder object and pass
> it to another #foreach loop which will generate result data. I'm even
> considering handing the result LogEntry objects to another object in the
> context which will pass them to the selected LogViewFormatter and pass to
> the user, and then make a NullOutputSream to send the velocity output to,
> thus using it purely as a scripting language.
> Is there any reason this is a bad idea ?
> Best Regards, Tommy Svensson

Event though some people take a strong point in recommending to use 
velocity as a pure view template tool, nothing keeps you from doing
some simple scripting within a template. If you do not comment well
what you are doing, it will be hard to understand at later time -
as in any piece of code.

Just note that a #foreach is not stoppable. You might consider adding
a method to your iterator or iterator-source to stop it - if you need
some kind of pager function (stopping after page is full with X 
formatted LogEntry objects).

Also note that nicely indent-structured code will produce stray 
whitespace in the output. I've used indentation using #* ... *# at 
every line beginning to avoid stray-whitespaces in macros (but within
templates it quickly gets utterly ugly).

Performance is another issue when looping and filtering thousands of
log entries. Consider using specially coded tools to assist and
reduce the performance impact when scripting.

:) Christoph Reck

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message