FreeMarker is a java based template engine for complex template processing.
This requires the library freemarker-2.3.16.jar to be in classpath.
The following example shows using String replace built-in function.
//Get template from classpath
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(StringReplaceTest.class, "/");
Template template = cfg.getTemplate("replace.ftl");
//Prepare data model
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("msg", "ONE TWO THREE FOUR");
dataModel.put("msg2", "ONE, TWO, THREE, FOUR");
//Merge template and data
OutputStreamWriter output = new OutputStreamWriter(System.out);
template.process(dataModel, output);
}
}