You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tommy Svensson <to...@askus.se> on 2002/03/26 08:30:36 UTC

Strange use of velocity - question

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


Re: Strange use of velocity - question

Posted by Christoph Reck <Ch...@dlr.de>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Strange use of velocity - question

Posted by Anthony Eden <ae...@signaturedomains.com>.
As an alternative you may want to try using Jython ( http://www.jython.org/ ).  IMO, Velocity is best reserved for the
presentation layer in any system.  Jython syntax is extremely easy to understand and you have almost complete access to
both Python and Java libraries.  While Velocity may be able to do the initial job it will be a lot easier to grow your
logic in the future if you use a full blown scripting language.

Sincerely,
Anthony Eden

> -----Original Message-----
> From: Tommy Svensson [mailto:tommy.svensson@askus.se]
> Sent: Tuesday, March 26, 2002 2:31 AM
> To: 'velocity-user@jakarta.apache.org'
> Subject: Strange use of velocity - question
>
>
> 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
>
>


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


Re: Strange use of velocity - question

Posted by "Geir Magnusson Jr." <ge...@earthlink.net>.
On 3/26/02 2:30 AM, "Tommy Svensson" <to...@askus.se> 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 ?

No.  I think the simplicity is good - I just did a similar scripting
language for another purpose.  I re-did it because the # wasn't needed
(wasn't embedding in schmoo) and I needed funky execution behavior (needed
to stop and checkpoint the execution of a script arbitrarily, and then
resume....  But the basic idea of references, introspection for methods and
properties, and the nice easy ability to drop in any tool you want makes it
work very well...


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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