/** * Returns the result of substituting the variables defined by the fields of this class (a * concrete subclass of TemplateVars) into the template returned by {@link #parsedTemplate()}. */ String toText() { VelocityContext velocityContext = toVelocityContext(); StringWriter writer = new StringWriter(); SimpleNode parsedTemplate = parsedTemplate(); boolean rendered = velocityRuntimeInstance.render( velocityContext, writer, parsedTemplate.getTemplateName(), parsedTemplate); if (!rendered) { // I don't know when this happens. Usually you get an exception during rendering. throw new IllegalArgumentException("Template rendering failed"); } return writer.toString(); }