NIHVIVO-3307:Moved code relating to the copyright text from FreemarkerConfiguration.java back to FreemarkerHTTPServlet.java where it had been previously.

This commit is contained in:
tworrall 2011-11-15 15:24:52 +00:00
parent dcca5381b4
commit f093795db1
2 changed files with 25 additions and 17 deletions

View file

@ -137,7 +137,6 @@ public class FreemarkerConfiguration extends Configuration {
sharedVariables.putAll(getDirectives());
sharedVariables.putAll(getMethods());
sharedVariables.put("copyright", getCopyrightInfo());
sharedVariables.put("siteTagline", appBean.getShortHand());
for ( Map.Entry<String, Object> variable : sharedVariables.entrySet() ) {
@ -210,22 +209,6 @@ public class FreemarkerConfiguration extends Configuration {
return map;
}
private final Map<String, Object> getCopyrightInfo() {
Map<String, Object> copyright = null;
String copyrightText = appBean.getCopyrightAnchor();
if ( ! StringUtils.isEmpty(copyrightText) ) {
copyright = new HashMap<String, Object>();
copyright.put("text", copyrightText);
int thisYear = Calendar.getInstance().get(Calendar.YEAR); // use ${copyrightYear?c} in template
//String thisYear = ((Integer)Calendar.getInstance().get(Calendar.YEAR)).toString(); // use ${copyrightYear} in template
//SimpleDate thisYear = new SimpleDate(Calendar.getInstance().getTime(), TemplateDateModel.DATE); // use ${copyrightYear?string("yyyy")} in template
copyright.put("year", thisYear);
copyright.put("url", appBean.getCopyrightURL());
}
return copyright;
}
// Define template locations. Template loader will look first in the theme-specific
// location, then in the vitro location.
protected final TemplateLoader createTemplateLoader() {

View file

@ -7,6 +7,8 @@ import static javax.mail.Message.RecipientType.TO;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -15,6 +17,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -419,6 +422,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
Map<String, Object> map = new HashMap<String, Object>();
ApplicationBean appBean = vreq.getAppBean();
// This may be overridden by the body data model received from the subcontroller.
map.put("title", getTitle(vreq.getAppBean().getApplicationName(), vreq));
@ -435,6 +439,9 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// Let the page template know which page it's processing.
map.put("currentServlet", normalizeServletName(vreq.getServletPath().replaceFirst("/", "")));
// NIHVIVO-3307: we need this here instead of FreemarkerConfiguration.java so that updates to
// the copyright text can be viewed with having to restart Tomcat
map.put("copyright", getCopyrightInfo(appBean));
map.put("url", new edu.cornell.mannlib.vitro.webapp.web.directives.UrlDirective());
map.put("widget", new edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective());
@ -454,6 +461,24 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(url);
}
// NIHVIVO-3307: we need this here instead of FreemarkerConfiguration.java so that updates to
// the copyright text can be viewed with having to restart Tomcat
private final Map<String, Object> getCopyrightInfo(ApplicationBean appBean) {
Map<String, Object> copyright = null;
String copyrightText = appBean.getCopyrightAnchor();
if ( ! StringUtils.isEmpty(copyrightText) ) {
copyright = new HashMap<String, Object>();
copyright.put("text", copyrightText);
int thisYear = Calendar.getInstance().get(Calendar.YEAR); // use ${copyrightYear?c} in template
//String thisYear = ((Integer)Calendar.getInstance().get(Calendar.YEAR)).toString(); // use ${copyrightYear} in template
//SimpleDate thisYear = new SimpleDate(Calendar.getInstance().getTime(), TemplateDateModel.DATE); // use ${copyrightYear?string("yyyy")} in template
copyright.put("year", thisYear);
copyright.put("url", appBean.getCopyrightURL());
}
return copyright;
}
// Subclasses may override. This serves as a default.
protected String getTitle(String siteName, VitroRequest vreq) {
return siteName;