1 package org.apache.fulcrum.template; 2 3 56 57 import java.net.URL ; 58 import java.util.Hashtable ; 59 60 import javax.mail.MessagingException ; 61 62 import org.apache.commons.mail.HtmlEmail; 63 64 92 public class TemplateHtmlEmail 93 extends HtmlEmail 94 { 95 99 private String htmlTemplate = null; 100 101 105 private TemplateContext context = null; 106 107 111 private String textTemplate = null; 112 113 114 private Hashtable embmap = null; 115 116 122 public TemplateHtmlEmail(TemplateContext context) 123 throws MessagingException 124 { 125 super.init(); 126 this.context = context; 127 embmap = new Hashtable (); 128 } 129 130 138 public TemplateHtmlEmail setHtmlTemplate(String template) 139 { 140 this.htmlTemplate = template; 141 return this; 142 } 143 144 152 public TemplateHtmlEmail setTextTemplate(String template) 153 { 154 this.textTemplate = template; 155 return this; 156 } 157 158 163 public void send() 164 throws MessagingException 165 { 166 context.put("mail",this); 167 168 String htmlbody = ""; 169 String textbody = ""; 170 171 try 173 { 174 if(htmlTemplate != null) 175 { 176 htmlbody = TurbineTemplate.handleRequest( 177 context, htmlTemplate); 178 } 179 180 if(textTemplate != null) 181 { 182 textbody = TurbineTemplate.handleRequest( 183 context, textTemplate); 184 } 185 } 186 catch( Exception e) 187 { 188 throw new MessagingException ("Cannot parse template", e); 189 } 190 191 setHtmlMsg(htmlbody); 192 setTextMsg(textbody); 193 194 super.send(); 195 } 196 197 221 public String embed(String surl, 222 String name) 223 throws MessagingException 224 { 225 String cid =""; 226 try 227 { 228 URL url = new URL (surl); 229 cid = super.embed(url, name); 230 embmap.put(name,cid); 231 } 232 catch( Exception e ) 233 { 234 } 236 return cid; 237 } 238 239 246 public String getCid(String filename) 247 { 248 String cid = (String )embmap.get(filename); 249 return "cid:"+cid; 250 } 251 } 252 253 | Popular Tags |