Added "templateType" to page and body template models so we know whether we're in a page or body template during processing. Changed a method name.

This commit is contained in:
rjy7 2010-11-03 14:52:31 +00:00
parent 74da549755
commit 8cfe11d615
3 changed files with 23 additions and 17 deletions

View file

@ -34,7 +34,7 @@ public class FreemarkerComponentGenerator extends FreemarkerHttpServlet {
// root is the map used to create the page shell - header, footer, menus, etc. // root is the map used to create the page shell - header, footer, menus, etc.
Map<String, Object> root = getSharedVariables(vreq, new HashMap<String, Object>()); Map<String, Object> root = getSharedVariables(vreq, new HashMap<String, Object>());
root.putAll(getRootValues(vreq)); root.putAll(getPageTemplateValues(vreq));
request.setAttribute("ftl_identity", get("identity", root, config)); request.setAttribute("ftl_identity", get("identity", root, config));
request.setAttribute("ftl_menu", get("menu", root, config)); request.setAttribute("ftl_menu", get("menu", root, config));

View file

@ -266,16 +266,22 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// root is the map used to create the page shell - header, footer, menus, etc. // root is the map used to create the page shell - header, footer, menus, etc.
Map<String, Object> root = new HashMap<String, Object>(sharedVariables); Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
root.putAll(getPageTemplateValues(vreq));
// body is the map used to create the page body // Tell the template and any directives it uses that we're processing a page template.
Map<String, Object> body = new HashMap<String, Object>(sharedVariables); root.put("templateType", "page");
root.putAll(getRootValues(vreq));
// Add the values that we got, and merge to the template. // Add the values that we got, and merge to the template.
String bodyTemplate = values.getTemplateName(); String bodyTemplate = values.getTemplateName();
String bodyString; String bodyString;
if (bodyTemplate != null) { if (bodyTemplate != null) {
// body is the map used to create the page body
// Adding sharedVariables before bodyMap values is important. If the body
// processing has changed a shared value such as title, we want to get that
// value.
Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
body.putAll(bodyMap); body.putAll(bodyMap);
// Tell the template and any directives it uses that we're processing a body template.
body.put("templateType", "body");
bodyString = mergeMapToTemplate(bodyTemplate, body, config); bodyString = mergeMapToTemplate(bodyTemplate, body, config);
} else { } else {
// The subcontroller has not defined a body template. All markup for the page // The subcontroller has not defined a body template. All markup for the page
@ -447,10 +453,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// Add variables that should be available only to the page's root map, not to the body. // Add variables that should be available only to the page's root map, not to the body.
// RY This is protected instead of private so FreeMarkerComponentGenerator can access. // RY This is protected instead of private so FreeMarkerComponentGenerator can access.
// Once we don't need that (i.e., jsps have been eliminated) we can make it private. // Once we don't need that (i.e., jsps have been eliminated) we can make it private.
protected Map<String, Object> getRootValues(VitroRequest vreq) { protected Map<String, Object> getPageTemplateValues(VitroRequest vreq) {
Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
root.put("tabMenu", getTabMenu(vreq)); map.put("tabMenu", getTabMenu(vreq));
Portal portal = vreq.getPortal(); Portal portal = vreq.getPortal();
@ -458,26 +464,26 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
PortalWebUtil.populateSearchOptions(portal, appBean, vreq.getWebappDaoFactory().getPortalDao()); PortalWebUtil.populateSearchOptions(portal, appBean, vreq.getWebappDaoFactory().getPortalDao());
PortalWebUtil.populateNavigationChoices(portal, vreq, appBean, vreq.getWebappDaoFactory().getPortalDao()); PortalWebUtil.populateNavigationChoices(portal, vreq, appBean, vreq.getWebappDaoFactory().getPortalDao());
root.putAll(getLoginValues(vreq)); map.putAll(getLoginValues(vreq));
UrlBuilder urlBuilder = new UrlBuilder(portal); UrlBuilder urlBuilder = new UrlBuilder(portal);
root.put("version", getRevisionInfo(urlBuilder)); map.put("version", getRevisionInfo(urlBuilder));
root.put("copyright", getCopyrightInfo(portal)); map.put("copyright", getCopyrightInfo(portal));
root.put("siteTagline", portal.getShortHand()); map.put("siteTagline", portal.getShortHand());
root.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(vreq)); map.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(vreq));
String themeDir = getThemeDir(portal); String themeDir = getThemeDir(portal);
// This value is used only in stylesheets.ftl and already contains the context path. // This value is used only in stylesheets.ftl and already contains the context path.
root.put("stylesheetPath", UrlBuilder.getUrl(themeDir + "/css")); map.put("stylesheetPath", UrlBuilder.getUrl(themeDir + "/css"));
String bannerImage = portal.getBannerImage(); String bannerImage = portal.getBannerImage();
if ( ! StringUtils.isEmpty(bannerImage)) { if ( ! StringUtils.isEmpty(bannerImage)) {
root.put("bannerImage", UrlBuilder.getUrl(themeDir + "site_icons/" + bannerImage)); map.put("bannerImage", UrlBuilder.getUrl(themeDir + "site_icons/" + bannerImage));
} }
return root; return map;
} }

View file

@ -159,7 +159,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
Map<String, Object> sharedVariables = getSharedVariables(vreq, new HashMap<String, Object>()); Map<String, Object> sharedVariables = getSharedVariables(vreq, new HashMap<String, Object>());
Map<String, Object> root = new HashMap<String, Object>(sharedVariables); Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
Map<String, Object> body = new HashMap<String, Object>(sharedVariables); Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
root.putAll(getRootValues(vreq)); root.putAll(getPageTemplateValues(vreq));
// Add the values that we got, and merge to the template. // Add the values that we got, and merge to the template.
body.putAll(values.getMap()); body.putAll(values.getMap());