Use FreemarkerConfiguration rather than Configuration in FreemarkerEmailMessage.

This commit is contained in:
ryounes 2011-08-31 16:51:12 +00:00
parent 1a412bf7a7
commit 955a1473fc

View file

@ -28,10 +28,8 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective; import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
import freemarker.core.Environment;
import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
@ -39,24 +37,22 @@ import freemarker.template.TemplateException;
* A framework that makes it simpler to send email messages with a body built * A framework that makes it simpler to send email messages with a body built
* from a Freemarker template. * from a Freemarker template.
* *
* The template must contain the @email directive, which may provide the subject * The template must call the @email directive, which may provide the subject
* line, the HTML content, and the plain text content. If these values are not * line, the HTML content, and the plain text content. If these values are not
* provided by the directive, they default to empty strings, or to values that * provided by the directive, they default to empty strings, or to values that
* were set by the controller. * were set by the controller.
* *
* The directive also calls the send() method here.
*
* @see EmailDirective * @see EmailDirective
*/ */
public class FreemarkerEmailMessage { public class FreemarkerEmailMessage {
private static final Log log = LogFactory private static final Log log = LogFactory
.getLog(FreemarkerEmailMessage.class); .getLog(FreemarkerEmailMessage.class);
private static final String ATTRIBUTE_NAME = "freemarkerConfig"; private static final String CONFIG_ATTRIBUTE = "freemarkerConfig";
private final HttpServletRequest req; private final HttpServletRequest req;
private final Session session; private final Session session;
private final Configuration config; private final FreemarkerConfiguration config;
private final List<Recipient> recipients = new ArrayList<Recipient>(); private final List<Recipient> recipients = new ArrayList<Recipient>();
private final InternetAddress replyToAddress; private final InternetAddress replyToAddress;
@ -77,15 +73,15 @@ public class FreemarkerEmailMessage {
this.session = session; this.session = session;
this.replyToAddress = replyToAddress; this.replyToAddress = replyToAddress;
Object o = req.getAttribute(ATTRIBUTE_NAME); Object o = req.getAttribute(CONFIG_ATTRIBUTE);
if (!(o instanceof Configuration)) { if (!(o instanceof FreemarkerConfiguration)) {
String oClass = (o == null) ? "null" : o.getClass().getName(); String oClass = (o == null) ? "null" : o.getClass().getName();
throw new IllegalStateException( throw new IllegalStateException(
"Request does not contain a Configuration at '" "Request does not contain a Configuration at '"
+ ATTRIBUTE_NAME + "': " + oClass); + CONFIG_ATTRIBUTE + "': " + oClass);
} }
this.config = (Configuration) o; this.config = (FreemarkerConfiguration) o;
} }
public void addRecipient(RecipientType type, String emailAddress) { public void addRecipient(RecipientType type, String emailAddress) {