Search in sources :

Example 1 with TemplatingException

use of com.outjected.email.api.TemplatingException in project simple-email by codylerum.

the class FreeMarkerTemplate method merge.

@Override
public String merge(Map<String, Object> context) {
    rootMap.putAll(context);
    StringWriter writer = new StringWriter();
    try {
        Template t = new Template("mailGenerated", template, configuration);
        t.process(rootMap, writer);
    } catch (IOException e) {
        throw new TemplatingException("Error creating template", e);
    } catch (TemplateException e) {
        throw new TemplatingException("Error rendering output", e);
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) TemplatingException(com.outjected.email.api.TemplatingException) Template(freemarker.template.Template)

Example 2 with TemplatingException

use of com.outjected.email.api.TemplatingException in project simple-email by codylerum.

the class VelocityTemplate method merge.

@Override
public String merge(Map<String, Object> context) {
    StringWriter writer = new StringWriter();
    velocityContext = new VelocityContext(context);
    try {
        velocityEngine.evaluate(velocityContext, writer, "mailGenerated", template);
    } catch (ResourceNotFoundException e) {
        throw new TemplatingException("Unable to find template", e);
    } catch (ParseErrorException e) {
        throw new TemplatingException("Unable to find template", e);
    } catch (MethodInvocationException e) {
        throw new TemplatingException("Error processing method referenced in context", e);
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) ParseErrorException(org.apache.velocity.exception.ParseErrorException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) TemplatingException(com.outjected.email.api.TemplatingException)

Aggregations

TemplatingException (com.outjected.email.api.TemplatingException)2 StringWriter (java.io.StringWriter)2 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 VelocityContext (org.apache.velocity.VelocityContext)1 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)1 ParseErrorException (org.apache.velocity.exception.ParseErrorException)1 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)1