A co-worker and I are writing plug-ins for the Atlassian tools JIRA and Confluence.
Our plug-ins for JIRA are using Velocity (see http://org.apache.velocity) templates effectively. The "Report" object I'm using implicitly loads the template and generally hides Velocity from me, so all we have to do is populate a Map<String, Object> name/value pairs and write the supporting Velocity template.
Unfortunately for Confluence, we're stuck with a model which does not implicitly invoke a template. I've been trying to find an example in the on-line developers code base that does what I'd like, but so far I'm batting zero.
The basic problem is that I really don't understand in-depth how things wire together, so we're stuck programming by copy/example at the moment. This is very frustrating, but we'll get past it.
In the meanwhile, is there a method that I can use to process a Velocity template in-line in the code and get the resulting string? Once I have the string, it's easy enough to plug it into the Confluence output stream and display whatever I want.
I'm pretty certain that the answer is three lines of code, please help by filling in the blanks ....
Expand|Select|Wrap|Line Numbers
- Map<String, Object> values = new Map<String, Object>;
- values.add("name1", object1);
- values.add("name2", object2);
- String templateBody = lookupResource("template-id");
- VelocityTemplate template = new VelocityTemplate(templateBody);
- String result = template.apply(values);
Oralloy