NIHVIVO-3729 Stop storing the FreemarkerConfiguration as a request attribute. Instead, get it from the FreemarkerConfigurationLoader when you need it.

This commit is contained in:
j2blake 2012-04-20 20:23:29 +00:00
parent 21828f9233
commit 981ac675c9
6 changed files with 10 additions and 22 deletions

View file

@ -112,7 +112,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
String originalReferer = getOriginalRefererFromSession(vreq);
Configuration config = (Configuration) vreq.getAttribute("freemarkerConfig");
Configuration config = FreemarkerConfigurationLoader.getConfig(vreq);
String msgText = composeEmail(webusername, webuseremail, comments,
deliveryfrom, originalReferer, vreq.getRemoteAddr(), config, vreq);

View file

@ -35,7 +35,6 @@ public class FreemarkerComponentGenerator extends FreemarkerHttpServlet {
// Mimic what FreemarkerHttpServlet does for a new request
VitroRequest vreq = new VitroRequest(request);
FreemarkerConfiguration config = getConfig(vreq);
vreq.setAttribute("freemarkerConfig", config);
Map<String, Object> map = getPageTemplateValues(vreq);
request.setAttribute("ftl_head", getHead("head", map, config, vreq));

View file

@ -101,7 +101,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
}
FreemarkerConfiguration config = getConfig(vreq);
vreq.setAttribute("freemarkerConfig", config);
responseValues = processRequest(vreq);
doResponse(vreq, response, responseValues);
@ -346,7 +345,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
private Map<String, Object> buildRequestUrls(VitroRequest vreq) {
Map<String, Object> requestUrls = new HashMap<String, Object>();
FreemarkerConfiguration config = (FreemarkerConfiguration)vreq.getAttribute("freemarkerConfig");
FreemarkerConfiguration config = FreemarkerConfigurationLoader.getConfig(vreq);
TemplateModel urlModel = config.getSharedVariable("urls");
try {

View file

@ -25,6 +25,8 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
@ -57,7 +59,9 @@ public class FreemarkerEmailFactory {
}
FreemarkerEmailFactory factory = getFactory(vreq);
return new FreemarkerEmailMessage(vreq, factory.getEmailSession(),
FreemarkerConfiguration fConfig = FreemarkerConfigurationLoader
.getConfig(vreq);
return new FreemarkerEmailMessage(fConfig, factory.getEmailSession(),
factory.getReplyToAddress());
}

View file

@ -23,7 +23,6 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -48,9 +47,6 @@ public class FreemarkerEmailMessage {
private static final Log log = LogFactory
.getLog(FreemarkerEmailMessage.class);
private static final String CONFIG_ATTRIBUTE = "freemarkerConfig";
private final HttpServletRequest req;
private final Session session;
private final FreemarkerConfiguration config;
@ -67,21 +63,11 @@ public class FreemarkerEmailMessage {
/**
* Package access - should only be created by the factory.
*/
FreemarkerEmailMessage(HttpServletRequest req, Session session,
FreemarkerEmailMessage(FreemarkerConfiguration fConfig, Session session,
InternetAddress replyToAddress) {
this.req = req;
this.session = session;
this.replyToAddress = replyToAddress;
Object o = req.getAttribute(CONFIG_ATTRIBUTE);
if (!(o instanceof FreemarkerConfiguration)) {
String oClass = (o == null) ? "null" : o.getClass().getName();
throw new IllegalStateException(
"Request does not contain a Configuration at '"
+ CONFIG_ATTRIBUTE + "': " + oClass);
}
this.config = (FreemarkerConfiguration) o;
this.config = fConfig;
}
public void addRecipient(RecipientType type, String emailAddress) {

View file

@ -71,7 +71,7 @@ public class ViewFinder {
private String findCustomTemplateByVClasses(Individual individual, VitroRequest vreq) {
//
// Method method = view.getMethod();
// TemplateLoader templateLoader = ((Configuration) vreq.getAttribute("freemarkerConfig")).getTemplateLoader();
// TemplateLoader templateLoader = FreemarkerConfigurationLoader.getConfig(vreq).getTemplateLoader();
//
// /* RY The logic here is incorrect. The vclasses are
// * returned in a random order, whereas we need to