I’m doing some research for a client in using Freemarker to generate documents using templates and Notes data. It turns out that it’s deceptively simple to create a very basic Notes wrapper object to pass into Freemarker’s templating engine for merging document fields with a template. The closest abstract class to implement for a document is Freemarker’s TemplateHashModel. The idea is that for any given Notes field, you’d want the template to get the value by referencing the field’s name. Assuming that we call getText()
on any retrieved item (I said it was a BASIC Notes wrapper) and convert the string results to Freemarker’s expected SimpleScalar, here’s the wrapper:
import lotus.domino.*; import freemarker.template.*; public class SimpleNotesDocumentWrapper implements TemplateHashModel { doc = note; } @Override Item item; try { if ((item = doc.getFirstItem(key)) != null) return new SimpleScalar(item.getText()); e.printStackTrace(); } return null; } @Override public boolean isEmpty() throws TemplateModelException { // TODO Auto-generated method stub return (doc == null) ? true : false; } }
and you can then access document fields in your template like so: memo subject: ${doc.Subject}.
(Assuming you’ve named the SimpleNotesDocumentWrapper object you placed in the root of the Freemarker object parse tree “doc.”)