NIHVIVO-1297 Undid the effects of revision 6246. This was a mistake, since including the body template from the page template rather than pregenerating the body string doesn't allow the addition of stylesheet tags to the page head.
This commit is contained in:
parent
0bbe23a7fa
commit
c178c8d922
8 changed files with 103 additions and 65 deletions
|
@ -32,7 +32,9 @@ public class FreemarkerComponentGenerator extends FreemarkerHttpServlet {
|
|||
VitroRequest vreq = new VitroRequest(request);
|
||||
Configuration config = getConfig(vreq);
|
||||
|
||||
Map<String, Object> root = getPageValues(vreq, new HashMap<String, Object>());
|
||||
// root is the map used to create the page shell - header, footer, menus, etc.
|
||||
Map<String, Object> root = getSharedVariables(vreq, new HashMap<String, Object>());
|
||||
root.putAll(getRootValues(vreq));
|
||||
|
||||
request.setAttribute("ftl_identity", get("identity", root, config));
|
||||
request.setAttribute("ftl_menu", get("menu", root, config));
|
||||
|
|
|
@ -259,14 +259,32 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
Configuration config = getConfig(vreq);
|
||||
Map<String, Object> bodyMap = values.getMap();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.putAll(getPageValues(vreq, bodyMap));
|
||||
|
||||
// Add the values from the subcontroller.
|
||||
map.putAll(bodyMap);
|
||||
map.put("bodyTemplate", values.getTemplateName());
|
||||
// We can't use shared variables in the Freemarker configuration to store anything
|
||||
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
||||
// just put the shared variables in both root and body.
|
||||
Map<String, Object> sharedVariables = getSharedVariables(vreq, bodyMap);
|
||||
|
||||
writePage(map, config, response);
|
||||
// root is the map used to create the page shell - header, footer, menus, etc.
|
||||
Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
|
||||
|
||||
// body is the map used to create the page body
|
||||
Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
|
||||
root.putAll(getRootValues(vreq));
|
||||
|
||||
// Add the values that we got, and merge to the template.
|
||||
String bodyTemplate = values.getTemplateName();
|
||||
String bodyString;
|
||||
if (bodyTemplate != null) {
|
||||
body.putAll(bodyMap);
|
||||
bodyString = mergeMapToTemplate(bodyTemplate, body, config);
|
||||
} else {
|
||||
// The subcontroller has not defined a body template. All markup for the page
|
||||
// is specified in the main page template.
|
||||
bodyString = "";
|
||||
}
|
||||
root.put("body", bodyString);
|
||||
|
||||
writePage(root, config, response);
|
||||
}
|
||||
|
||||
protected void doRedirect(HttpServletRequest request, HttpServletResponse response, ResponseValues values)
|
||||
|
@ -312,6 +330,50 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
doTemplate(vreq, response, trv);
|
||||
}
|
||||
|
||||
// We can't use shared variables in the Freemarker configuration to store anything
|
||||
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
||||
// we'll get all the shared variables here, and put them in both root and body maps.
|
||||
protected Map<String, Object> getSharedVariables(VitroRequest vreq, Map<String, Object> bodyMap) {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
Portal portal = vreq.getPortal();
|
||||
// Ideally, templates wouldn't need portal id. Currently used as a hidden input value
|
||||
// in the site search box, so needed for now.
|
||||
map.put("portalId", portal.getPortalId());
|
||||
|
||||
String siteName = portal.getAppName();
|
||||
map.put("siteName", siteName);
|
||||
|
||||
// In some cases the title is determined during the subclass processRequest() method; e.g.,
|
||||
// for an Individual profile page, the title should be the Individual's label. In that case,
|
||||
// put that title in the sharedVariables map because it's needed by the page root map as well
|
||||
// to generate the <title> element. Otherwise, use the getTitle() method to generate the title.
|
||||
String title = (String) bodyMap.get("title");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = getTitle(siteName);
|
||||
}
|
||||
map.put("title", title);
|
||||
|
||||
String themeDir = getThemeDir(portal);
|
||||
UrlBuilder urlBuilder = new UrlBuilder(portal);
|
||||
|
||||
map.put("urls", getUrls(themeDir, urlBuilder));
|
||||
|
||||
map.put("themeDir", themeDir);
|
||||
|
||||
map.put("themeDir", themeDir);
|
||||
|
||||
map.put("stylesheets", getStylesheetList(themeDir));
|
||||
map.put("scripts", getScriptList(themeDir));
|
||||
map.put("headScripts", getScriptList(themeDir));
|
||||
|
||||
map.putAll(getDirectives());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public String getThemeDir(Portal portal) {
|
||||
return portal.getThemeDir().replaceAll("/$", "");
|
||||
}
|
||||
|
@ -382,65 +444,43 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
return map;
|
||||
}
|
||||
|
||||
// Values needed to generate the page frame - header, footer, menus, etc. Some may also be used in the
|
||||
// page 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.
|
||||
// Once we don't need that (i.e., jsps have been eliminated) we can make it private.
|
||||
protected Map<String, Object> getPageValues(VitroRequest vreq, Map<String, Object> bodyMap) {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
protected Map<String, Object> getRootValues(VitroRequest vreq) {
|
||||
|
||||
Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("tabMenu", getTabMenu(vreq));
|
||||
|
||||
Portal portal = vreq.getPortal();
|
||||
// Ideally, templates wouldn't need portal id. Currently used as a hidden input value
|
||||
// in the site search box, so needed for now.
|
||||
map.put("portalId", portal.getPortalId());
|
||||
|
||||
String siteName = portal.getAppName();
|
||||
map.put("siteName", siteName);
|
||||
|
||||
// In some cases the title is determined during the subclass processRequest() method; e.g.,
|
||||
// for an Individual profile page, the title should be the Individual's label. In that case,
|
||||
// put that title in the sharedVariables map because it's needed by the page root map as well
|
||||
// to generate the <title> element. Otherwise, use the getTitle() method to generate the title.
|
||||
String title = (String) bodyMap.get("title");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = getTitle(siteName);
|
||||
}
|
||||
map.put("title", title);
|
||||
|
||||
String themeDir = getThemeDir(portal);
|
||||
UrlBuilder urlBuilder = new UrlBuilder(portal);
|
||||
map.put("urls", getUrls(themeDir, urlBuilder));
|
||||
map.put("themeDir", themeDir);
|
||||
map.put("stylesheets", getStylesheetList(themeDir));
|
||||
map.put("scripts", getScriptList(themeDir));
|
||||
map.put("headScripts", getScriptList(themeDir));
|
||||
map.putAll(getDirectives());
|
||||
map.put("tabMenu", getTabMenu(vreq));
|
||||
|
||||
ApplicationBean appBean = vreq.getAppBean();
|
||||
PortalWebUtil.populateSearchOptions(portal, appBean, vreq.getWebappDaoFactory().getPortalDao());
|
||||
PortalWebUtil.populateNavigationChoices(portal, vreq, appBean, vreq.getWebappDaoFactory().getPortalDao());
|
||||
|
||||
map.putAll(getLoginValues(vreq));
|
||||
root.putAll(getLoginValues(vreq));
|
||||
|
||||
map.put("copyright", getCopyrightInfo(portal));
|
||||
map.put("siteTagline", portal.getShortHand());
|
||||
map.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(vreq));
|
||||
UrlBuilder urlBuilder = new UrlBuilder(portal);
|
||||
root.put("version", getRevisionInfo(urlBuilder));
|
||||
|
||||
root.put("copyright", getCopyrightInfo(portal));
|
||||
root.put("siteTagline", portal.getShortHand());
|
||||
root.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(vreq));
|
||||
|
||||
String themeDir = getThemeDir(portal);
|
||||
|
||||
// This value is used only in stylesheets.ftl and already contains the context path.
|
||||
map.put("stylesheetPath", UrlBuilder.getUrl(themeDir + "/css"));
|
||||
root.put("stylesheetPath", UrlBuilder.getUrl(themeDir + "/css"));
|
||||
|
||||
String bannerImage = portal.getBannerImage();
|
||||
if ( ! StringUtils.isEmpty(bannerImage)) {
|
||||
map.put("bannerImage", UrlBuilder.getUrl(themeDir + "site_icons/" + bannerImage));
|
||||
root.put("bannerImage", UrlBuilder.getUrl(themeDir + "site_icons/" + bannerImage));
|
||||
}
|
||||
|
||||
map.put("version", getRevisionInfo(urlBuilder));
|
||||
|
||||
return map;
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
private TabMenu getTabMenu(VitroRequest vreq) {
|
||||
int portalId = vreq.getPortal().getPortalId();
|
||||
return new TabMenu(vreq, portalId);
|
||||
|
|
|
@ -23,10 +23,8 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
// Add home page data to body here
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
// Add home page data to body here
|
||||
return new TemplateResponseValues(BODY_TEMPLATE, body);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
|||
/** Show error message */
|
||||
public static final String TEMPLATE_SERVER_ERROR = Template.ERROR_MESSAGE.toString();
|
||||
|
||||
public static final String BODY_LOGIN_NAME = "username";
|
||||
public static final String BODY_LOGIN_NAME = "loginName";
|
||||
public static final String BODY_FORM_ACTION = "formAction";
|
||||
public static final String BODY_INFO_MESSAGE = "infoMessage";
|
||||
public static final String BODY_ERROR_MESSAGE = "errorMessage";
|
||||
|
@ -156,11 +156,14 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
|||
private String doTemplate(VitroRequest vreq, TemplateResponseValues values) {
|
||||
// Set it up like FreeMarkerHttpServlet.doGet() would do.
|
||||
Configuration config = getConfig(vreq);
|
||||
Map<String, Object> root = getPageValues(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> body = new HashMap<String, Object>(sharedVariables);
|
||||
root.putAll(getRootValues(vreq));
|
||||
|
||||
// Add the TemplateResponseValues
|
||||
root.putAll(values.getMap());
|
||||
return mergeMapToTemplate(values.getTemplateName(), root, config);
|
||||
// Add the values that we got, and merge to the template.
|
||||
body.putAll(values.getMap());
|
||||
return mergeMapToTemplate(values.getTemplateName(), body, config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
<form action="${formAction}" method="post">
|
||||
<label for="loginName">Email or Username</label>
|
||||
<input id="loginName" class="focus" name="loginName" type="text" value="${username}" />
|
||||
<input id="loginName" class="focus" name="loginName" type="text" value="${loginName}" />
|
||||
<label for="loginPassword">Password</label>
|
||||
<input id="loginPassword" type="password" name="loginPassword" />
|
||||
<input name="loginForm" type="submit" class="submit" value="Log in"/>
|
||||
|
|
|
@ -56,4 +56,4 @@
|
|||
|
||||
</div> <!-- end contentsBrowseGroup -->
|
||||
|
||||
${stylesheets.addFromTheme("/css/search.css")}
|
||||
${stylesheets.addFromTheme("/css/search.css")}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Page template for home page -->
|
||||
|
||||
<#include "page.ftl">
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<div id="contentwrap">
|
||||
<div id="content">
|
||||
<#include bodyTemplate>
|
||||
${body}
|
||||
</div> <!-- content -->
|
||||
</div> <!-- contentwrap -->
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue