| 1 | package de.aikiit.mailversendala.template; | |
| 2 | ||
| 3 | import org.apache.velocity.Template; | |
| 4 | import org.apache.velocity.VelocityContext; | |
| 5 | import org.apache.velocity.app.VelocityEngine; | |
| 6 | import org.apache.velocity.runtime.RuntimeConstants; | |
| 7 | import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; | |
| 8 | ||
| 9 | import java.io.File; | |
| 10 | import java.io.StringWriter; | |
| 11 | ||
| 12 | /** | |
| 13 |  * Mailing template that is based on Apache Velocity templates. | |
| 14 |  */ | |
| 15 | public class VelocityMailTemplate implements MailTemplate { | |
| 16 | ||
| 17 |     private final VelocityEngine velocityEngine = new VelocityEngine(); | |
| 18 | ||
| 19 |     /** | |
| 20 |      * Instantiate underlying template engine. | |
| 21 |      */ | |
| 22 |     public VelocityMailTemplate() { | |
| 23 | 1
1. <init> : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED |         velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class"); | 
| 24 | 1
1. <init> : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED |         velocityEngine.setProperty("class.resource.loader.class", | 
| 25 |                 ClasspathResourceLoader.class.getName()); | |
| 26 | 1
1. <init> : removed call to org/apache/velocity/app/VelocityEngine::init → SURVIVED |         velocityEngine.init(); | 
| 27 |     } | |
| 28 | ||
| 29 |     @Override | |
| 30 |     public String getHtml() { | |
| 31 | 1
1. getHtml : replaced return value with "" for de/aikiit/mailversendala/template/VelocityMailTemplate::getHtml → KILLED |         return loadAndGetContents("template" + File.separator + BASE_NAME_HTML); | 
| 32 |     } | |
| 33 | ||
| 34 |     @Override | |
| 35 |     public String getPlaintext() { | |
| 36 | 1
1. getPlaintext : replaced return value with "" for de/aikiit/mailversendala/template/VelocityMailTemplate::getPlaintext → KILLED |         return loadAndGetContents("template" + File.separator + BASE_NAME_PLAINTEXT); | 
| 37 |     } | |
| 38 | ||
| 39 |     private VelocityContext handleAndGetContextChanges() { | |
| 40 |         VelocityContext context = new VelocityContext(); | |
| 41 |         context.put("firstName", "ME"); | |
| 42 |         context.put("lastName", "REALLY"); | |
| 43 | 1
1. handleAndGetContextChanges : replaced return value with null for de/aikiit/mailversendala/template/VelocityMailTemplate::handleAndGetContextChanges → KILLED |         return context; | 
| 44 |     } | |
| 45 | ||
| 46 |     private String loadAndGetContents(String templateName) { | |
| 47 |         Template t = velocityEngine.getTemplate(templateName); | |
| 48 | ||
| 49 |         StringWriter writer = new StringWriter(); | |
| 50 | 1
1. loadAndGetContents : removed call to org/apache/velocity/Template::merge → KILLED |         t.merge(handleAndGetContextChanges(), writer); | 
| 51 |         t.process(); | |
| 52 | ||
| 53 | 1
1. loadAndGetContents : replaced return value with "" for de/aikiit/mailversendala/template/VelocityMailTemplate::loadAndGetContents → KILLED |         return writer.toString().trim(); | 
| 54 |     } | |
| 55 | } | |
| Mutations | ||
| 23 | 1.1 | |
| 24 | 1.1 | |
| 26 | 1.1 | |
| 31 | 1.1 | |
| 36 | 1.1 | |
| 43 | 1.1 | |
| 50 | 1.1 | |
| 53 | 1.1 |