01: package com.technoetic.xplanner.mail;
02:
03: import java.util.List;
04: import java.io.Writer;
05: import java.io.StringWriter;
06:
07: import com.technoetic.xplanner.XPlannerProperties;
08: import com.technoetic.xplanner.util.HttpClient;
09:
10: import org.apache.velocity.app.VelocityEngine;
11: import org.apache.velocity.Template;
12: import org.apache.velocity.VelocityContext;
13:
14: /**
15: * User: Mateusz Prokopowicz
16: * Date: May 19, 2005
17: * Time: 4:15:39 PM
18: */
19: public class EmailFormatterImpl implements EmailFormatter {
20: private VelocityEngine velocityEngine;
21: private HttpClient httpClient;
22:
23: public void setVelocityEngine(VelocityEngine velocityEngine) {
24: this .velocityEngine = velocityEngine;
25: }
26:
27: public void setHttpClient(HttpClient httpClient) {
28: this .httpClient = httpClient;
29: }
30:
31: public String formatEmailEntry(String header, String footer,
32: String storyLabel, String taskLabel, List bodyEntryList)
33: throws Exception {
34: Template template = velocityEngine
35: .getTemplate("com/technoetic/xplanner/mail/velocity/email_notifications.vm");
36: VelocityContext velocityContext = new VelocityContext();
37: XPlannerProperties properties = new XPlannerProperties();
38: String applicationUrl = properties
39: .getProperty(XPlannerProperties.APPLICATION_URL_KEY);
40: String style = httpClient.getPage(applicationUrl
41: + "/default.css");
42: velocityContext.put("hostUrl", applicationUrl);
43: velocityContext.put("style", style);
44: velocityContext.put("header", header);
45: velocityContext.put("footer", footer);
46: velocityContext.put("taskLabel", taskLabel);
47: velocityContext.put("storyLabel", storyLabel);
48: velocityContext.put("bodyEntries", bodyEntryList);
49: Writer stringWriter = new StringWriter();
50: template.merge(velocityContext, stringWriter);
51: stringWriter.close();
52: return stringWriter.toString();
53: }
54: }
|