I have a requirement for auditing where I have an Object and a String like so:
Person.getAge()
Person.getName()
"${person.name} is ${person.age} years old."
Is there a simple lighweight solution to this? I hav ewritten my own in the past using BeanUtils...
-
I need a light weigh solution for a template engine.. (3 messages)
- Posted by: Matthew Wilson
- Posted on: June 03 2005 07:44 EDT
Threaded Messages (3)
- I need a light weigh solution for a template engine.. by Time PassX on June 03 2005 08:43 EDT
- I need a light weigh solution for a template engine.. by Matthew Wilson on June 03 2005 08:48 EDT
- I need a light weigh solution for a template engine.. by Michael Abato on June 03 2005 11:40 EDT
- I need a light weigh solution for a template engine.. by Matthew Wilson on June 03 2005 08:48 EDT
-
I need a light weigh solution for a template engine..[ Go to top ]
- Posted by: Time PassX
- Posted on: June 03 2005 08:43 EDT
- in response to Matthew Wilson
-
I need a light weigh solution for a template engine..[ Go to top ]
- Posted by: Matthew Wilson
- Posted on: June 03 2005 08:48 EDT
- in response to Time PassX
Yes, that it a bit heavy for just audit logging I think. Maybe not. -
I need a light weigh solution for a template engine..[ Go to top ]
- Posted by: Michael Abato
- Posted on: June 03 2005 11:40 EDT
- in response to Matthew Wilson
Velocity is probably the lightest one out there that does bean-style translation (templates). It works well as a heavy lifter (e.g.: jsp alternative) but also works well as a simple string formatter:
VelocityEngine engine = new VelocityEngine();
engine.init();
VelocityContext context = new VelocityContext();
context.put("person", person);
engine.evaluate(
context,
new OutputStreamWriter(System.out),
"QUICKIE",
"$person.name is $person.age yearend old.");
Contexts are lightweight enough create as needed (except in situations where you'd think twice about creating a String :-) The engine should be pre-allocated.
The only part that proves a bit "heavy" for this usage pattern is that it throws unfashionable checked exceptions. A little wrapper classes fixes that in a jiffy.
Michael Abato