NIHVIVO-2051 Fix currentPage value sent to template: make home page value consistent regardless of the requested url, and change from servletPath to requestURI so we get full path value below the context path. Also add urls.currentPage to replace ${urls.base}/${currentPage} in templates. This value is similarly normalized for the home page.

This commit is contained in:
rjy7 2011-02-08 16:50:19 +00:00
parent f07999fc14
commit a05a001704
4 changed files with 24 additions and 20 deletions

View file

@ -242,16 +242,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// Define the URLs that are accessible to the templates. Note that we do not create menus here, // Define the URLs that are accessible to the templates. Note that we do not create menus here,
// because we want the templates to be free to define the link text and where the links are displayed. // because we want the templates to be free to define the link text and where the links are displayed.
private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder) { private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder, VitroRequest vreq) {
// The urls that are accessible to the templates.
// NB We are not using our menu object mechanism to build menus here, because we want the
// view to control which links go where, and the link text and title.
Map<String, String> urls = new HashMap<String, String>(); Map<String, String> urls = new HashMap<String, String>();
urls.put("home", urlBuilder.getHomeUrl()); urls.put("home", urlBuilder.getHomeUrl());
// Templates use this to construct urls. // Templates use this to construct urls.
urls.put("base", urlBuilder.contextPath); urls.put("base", UrlBuilder.contextPath);
urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT)); urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT));
if (ContactMailServlet.getSmtpHostFromProperties() != null) { if (ContactMailServlet.getSmtpHostFromProperties() != null) {
@ -264,9 +261,12 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN)); urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images")); urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
urls.put("images", urlBuilder.getUrl("/images")); urls.put("images", UrlBuilder.getUrl("/images"));
urls.put("theme", urlBuilder.getUrl(themeDir)); urls.put("theme", UrlBuilder.getUrl(themeDir));
urls.put("index", urlBuilder.getUrl("/browse")); urls.put("index", UrlBuilder.getUrl("/browse"));
//urls.put("currentPage", vreq.getRequestURI());
urls.put("currentPage", getCurrentPageValue(vreq));
return urls; return urls;
} }
@ -353,15 +353,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String themeDir = getThemeDir(portal); String themeDir = getThemeDir(portal);
UrlBuilder urlBuilder = new UrlBuilder(portal); UrlBuilder urlBuilder = new UrlBuilder(portal);
map.put("urls", getUrls(themeDir, urlBuilder)); map.put("urls", getUrls(themeDir, urlBuilder, vreq));
map.put("themeDir", themeDir); map.put("themeDir", themeDir);
map.put("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1)); map.put("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1));
map.put("stylesheets", getStylesheetList(themeDir)); map.put("stylesheets", getStylesheetList(themeDir));
map.put("scripts", getScriptList(themeDir)); map.put("scripts", getScriptList(themeDir));
map.put("headScripts", getScriptList(themeDir)); map.put("headScripts", getScriptList(themeDir));
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
map.putAll(getDirectives()); map.putAll(getDirectives());
map.putAll(getMethods()); map.putAll(getMethods());
@ -395,13 +393,23 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
} }
// Let the page template know which page it's processing. // Let the page template know which page it's processing.
map.put("currentPage", vreq.getServletPath().replaceFirst("/", "")); String currentPage = getCurrentPageValue(vreq).replaceFirst(vreq.getContextPath() + "/", "");
map.put("currentPage", currentPage);
// Allow template to send domain name to JavaScript (needed for AJAX calls) // Allow template to send domain name to JavaScript (needed for AJAX calls)
map.put("requestedPage", vreq.getRequestURL().toString()); map.put("requestedPage", vreq.getRequestURL().toString());
return map; return map;
} }
private String getCurrentPageValue(HttpServletRequest request) {
String currentPage = request.getRequestURI();
// Return a uniform value for the home page
if (currentPage.equals("") || currentPage.equals("index.jsp")) {
currentPage = "home";
}
return currentPage;
}
private TabMenu getTabMenu(VitroRequest vreq) { private TabMenu getTabMenu(VitroRequest vreq) {
int portalId = vreq.getPortal().getPortalId(); int portalId = vreq.getPortal().getPortalId();

View file

@ -15,7 +15,7 @@
</#if> </#if>
<#if menuN3??> <#if menuN3??>
<form class="" action="${urls.base}/${currentPage}" method="post"> <form class="" action="${urls.currentPage}" method="post">
<label for="navigatioN3">Setup the primary navigation menu for your website</label> <label for="navigatioN3">Setup the primary navigation menu for your website</label>
<textarea name="navigationN3" id="navigationN3" cols="45" rows="40" class="maxWidth"> <textarea name="navigationN3" id="navigationN3" cols="45" rows="40" class="maxWidth">
${menuN3}<#t><#-- The trim directive here is to trim leading and trailing white-space --> ${menuN3}<#t><#-- The trim directive here is to trim leading and trailing white-space -->

View file

@ -15,10 +15,6 @@ ${stylesheets.add("/css/browseClassGroups.css")}
<#if !firstPopulatedClassGroup??> <#if !firstPopulatedClassGroup??>
<#assign firstPopulatedClassGroup = group /> <#assign firstPopulatedClassGroup = group />
</#if> </#if>
<#-- Remove "index.jsp" from URL (should verify with RY if this can be taken care of in the controller) -->
<#if currentPage == "index.jsp">
<#assign currentPage = "" />
</#if>
<#-- Determine the active (selected) group --> <#-- Determine the active (selected) group -->
<#assign activeGroup = "" /> <#assign activeGroup = "" />
<#if !classGroup??> <#if !classGroup??>
@ -28,7 +24,7 @@ ${stylesheets.add("/css/browseClassGroups.css")}
<#elseif classGroup.uri == group.uri> <#elseif classGroup.uri == group.uri>
<#assign activeGroup = selected /> <#assign activeGroup = selected />
</#if> </#if>
<li role="listitem"><a ${activeGroup}href="${urls.base}/${currentPage}?classgroupUri=${group.uri?url}#browse" title="Browse ${group.publicName?capitalize}" data-uri="${group.uri}" data-count="${group.individualCount}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li> <li role="listitem"><a ${activeGroup}href="${urls.currentPage}?classgroupUri=${group.uri?url}#browse" title="Browse ${group.publicName?capitalize}" data-uri="${group.uri}" data-count="${group.individualCount}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
</#if> </#if>
</#list> </#list>
</#assign> </#assign>

View file

@ -17,7 +17,7 @@
<ul id="browse-classgroups" role="list"> <ul id="browse-classgroups" role="list">
<#list vclassGroupList as group> <#list vclassGroupList as group>
<#if (group.individualCount > 0)> <#if (group.individualCount > 0)>
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${group.uri?url}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li> <li role="listitem"><a href="${urls.currentPage}?classgroupUri=${group.uri?url}">${group.publicName?capitalize} <span class="count-classes">(${group.individualCount})</span></a></li>
</#if> </#if>
</#list> </#list>
</ul> </ul>
@ -35,7 +35,7 @@
<ul id="classes-in-classgroup" role="list"> <ul id="classes-in-classgroup" role="list">
<#list classes as class> <#list classes as class>
<#if (class.individualCount > 0)> <#if (class.individualCount > 0)>
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.uri?url}&vclassUri=${class.uri?url}">${class.name} <span class="count-individuals"> (${class.individualCount})</span></a></li> <li role="listitem"><a href="${urls.currentPage}?classgroupUri=${classGroup.uri?url}&vclassUri=${class.uri?url}">${class.name} <span class="count-individuals"> (${class.individualCount})</span></a></li>
</#if> </#if>
</#list> </#list>
</ul> </ul>