if (encoding != null) {
contentType = contentType + ";charset=" + encoding;
}
Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding);
Context context = createContext(velocityManager, stack, request, response, finalLocation);
Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);
response.setContentType(contentType);
t.merge(context, writer);
// always flush the writer (we used to only flush it if this was a jspWriter, but someone asked
// to do it all the time (WW-829). Since Velocity support is being deprecated, we'll oblige :)
writer.flush();
} catch (Exception e) {