From ca844e91a2407c549732aad0e5c913d1c6c6d856 Mon Sep 17 00:00:00 2001 From: j2blake Date: Tue, 6 Mar 2012 21:39:24 +0000 Subject: [PATCH] NIHVIVO-3270 Instead of storing request-specific URLs in the FreemarkerConfiguration (where they become global), create a "urls" variable in the body map that includes both request-specific and context-general values, and that masks that "urls" variable in the config. --- .../freemarker/FreemarkerHttpServlet.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java index 876f1bb04..470d19bdb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java @@ -338,42 +338,38 @@ public class FreemarkerHttpServlet extends VitroHttpServlet { return appBean.getThemeDir().replaceAll("/$", ""); } - /** - * Define the request-specific URLs that are accessible to the templates. - * @param VitroRequest vreq - */ - private void setRequestUrls(VitroRequest vreq) { - + /** + * Define the request-specific URLs that are accessible to the templates. + * Merge it with the context-specific URLs from the configuration, because + * this map will mask that one. + */ + private Map buildRequestUrls(VitroRequest vreq) { + Map requestUrls = new HashMap(); + FreemarkerConfiguration config = (FreemarkerConfiguration)vreq.getAttribute("freemarkerConfig"); TemplateModel urlModel = config.getSharedVariable("urls"); try { @SuppressWarnings("unchecked") - Map urls = (Map) DeepUnwrap.permissiveUnwrap(urlModel); + Map configUrls = (Map) DeepUnwrap.permissiveUnwrap(urlModel); + requestUrls.putAll(configUrls); // This is request-specific because email can be configured // and de-configured in the application interface. if (FreemarkerEmailFactory.isConfigured(vreq)) { - urls.put("contact", UrlBuilder.getUrl(Route.CONTACT)); - } else { - urls.remove("contact"); // clear value from a previous request + requestUrls.put("contact", UrlBuilder.getUrl(Route.CONTACT)); } - urls.put("currentPage", getCurrentPageUrl(vreq)); - urls.put("referringPage", getReferringPageUrl(vreq)); + requestUrls.put("currentPage", getCurrentPageUrl(vreq)); + requestUrls.put("referringPage", getReferringPageUrl(vreq)); if (PolicyHelper.isAuthorizedForActions(vreq, SimplePermission.EDIT_OWN_ACCOUNT.ACTIONS)) { - urls.put("myAccount", UrlBuilder.getUrl("/accounts/myAccount")); - } else { - urls.remove("myAccount"); // clear value from a previous request + requestUrls.put("myAccount", UrlBuilder.getUrl("/accounts/myAccount")); } - - config.setSharedVariable("urls", urls); - } catch (TemplateModelException e) { log.error(e, e); } - + return requestUrls; } private String getCurrentPageUrl(HttpServletRequest request) { @@ -424,7 +420,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet { // This may be overridden by the body data model received from the subcontroller. map.put("title", getTitle(vreq.getAppBean().getApplicationName(), vreq)); - setRequestUrls(vreq); + map.put("urls", buildRequestUrls(vreq)); map.put("menu", getDisplayModelMenu(vreq));