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 split built-in function.
//Get template from classpath
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(StringSplitTest.class, "/");
Template template = cfg.getTemplate("split.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);
}
}
It gives the following output,
ONE
TWO
THREE
FOUR
ONE
TWO
THREE
FOUR
ONE
TWO
THREE
FOUR