public void renderTemplate(String templatePath, Map model, Writer writer) throws Exception {
final VelocityContext velocityContext = new VelocityContext(model);
// May throw parsing error if template could not be obtained
Template template = null;
String charset = configService.getCharset();
if (charset != null) {
template = velocityEngine.getTemplate(templatePath, charset);
} else {
template = velocityEngine.getTemplate(templatePath);
}
VelocityWriter velocityWriter = null;
try {
velocityWriter = (VelocityWriter) writerPool.get();
if (velocityWriter == null) {
velocityWriter =
new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
} else {
velocityWriter.recycle(writer);
}
template.merge(velocityContext, velocityWriter);
} catch (Exception error) {
// Exception occured merging template and model. It is possible
// that some output has already been written, so we will append the
// error report to the previous output.