Conversation
| private final VelocityContext velocityContext; | ||
| private final VelocityEngine velocityEngine; | ||
|
|
||
| public TemplateExecutor(Map<String, Reader> readers, TemplateFunctions templateFunctions, boolean failInvalidRef, boolean trimTemplate, boolean templateInResourcesFolder, TemplateMap templateMap, Formatter formatter) { |
There was a problem hiding this comment.
Reader(s) should probably not be in the constructor but passed as parameter when the execution of a template is requested. Via CLI this is not important, but if used as a library can facilitate the reuse of the same TemplateExecutor instance.
There was a problem hiding this comment.
Because the VelocityContext (line 73) depends on the Reader(s), passing in the Reader(s) to the executor method would mean recreating the VelocityContext at each execution, which was the initial problem
There was a problem hiding this comment.
The problem is not initialising the VelocityEngine twice; this is why readers should not be in the constructor. It is ok to create different VelocityContext when requesting the VelocityEngine to execute a template.
mapping-template/src/main/java/com/cefriel/template/TemplateExecutor.java
Lines 187 to 188 in e8ae166
The
TemplateExecutorclass now supports multiple readers. The same class also has been refactored so that the VelocityContext and VelocityEngine are no longer created every time one of theexecuteMappingsmethods is run.