NIHVIVO-3729 small refactoring in how to create a FreemarkerConfiguration
This commit is contained in:
parent
9386832142
commit
ac873fe238
2 changed files with 9 additions and 13 deletions
|
@ -17,7 +17,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod;
|
||||
|
@ -40,14 +39,12 @@ public class FreemarkerConfiguration extends Configuration {
|
|||
private final String themeDir;
|
||||
private final ServletContext context;
|
||||
private final ApplicationBean appBean;
|
||||
private final String appName;
|
||||
|
||||
FreemarkerConfiguration(String themeDir, VitroRequest vreq, ServletContext context) {
|
||||
FreemarkerConfiguration(String themeDir, ApplicationBean appBean, ServletContext context) {
|
||||
|
||||
this.themeDir = themeDir;
|
||||
this.context = context;
|
||||
this.appBean = vreq.getAppBean();
|
||||
this.appName = appBean.getApplicationName();
|
||||
this.appBean = appBean;
|
||||
|
||||
String buildEnv = ConfigurationProperties.getBean(context).getProperty("Environment.build");
|
||||
log.debug("Current build environment: " + buildEnv);
|
||||
|
@ -88,7 +85,7 @@ public class FreemarkerConfiguration extends Configuration {
|
|||
|
||||
setTemplateLoader(createTemplateLoader());
|
||||
|
||||
setSharedVariables(vreq);
|
||||
setSharedVariables();
|
||||
|
||||
}
|
||||
|
||||
|
@ -96,13 +93,12 @@ public class FreemarkerConfiguration extends Configuration {
|
|||
* These are values that are accessible to all
|
||||
* templates loaded by the Configuration's TemplateLoader. They
|
||||
* should be application- rather than request-specific.
|
||||
* @param VitroRequest vreq
|
||||
*/
|
||||
private void setSharedVariables(VitroRequest vreq) {
|
||||
private void setSharedVariables() {
|
||||
|
||||
Map<String, Object> sharedVariables = new HashMap<String, Object>();
|
||||
|
||||
sharedVariables.put("siteName", appName);
|
||||
sharedVariables.put("siteName", appBean.getApplicationName());
|
||||
sharedVariables.put("version", getRevisionInfo());
|
||||
sharedVariables.put("urls", getSiteUrls());
|
||||
sharedVariables.put("themeDir", themeDir);
|
||||
|
|
|
@ -22,7 +22,7 @@ public class FreemarkerConfigurationLoader {
|
|||
public static FreemarkerConfiguration getConfig(VitroRequest vreq,
|
||||
ServletContext context) {
|
||||
String themeDir = getThemeDir(vreq.getAppBean());
|
||||
return getConfigForTheme(themeDir, vreq, context);
|
||||
return getConfigForTheme(themeDir, vreq.getAppBean(), context);
|
||||
}
|
||||
|
||||
private static String getThemeDir(ApplicationBean appBean) {
|
||||
|
@ -46,16 +46,16 @@ public class FreemarkerConfigurationLoader {
|
|||
* 1. The template loader is theme-specific, since it specifies a theme
|
||||
* directory to load templates from.
|
||||
*
|
||||
* 2. Shared variables like stylesheets are theme-specific.
|
||||
* 2. Some shared variables are theme-specific.
|
||||
*/
|
||||
private static FreemarkerConfiguration getConfigForTheme(String themeDir,
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
ApplicationBean appBean, ServletContext context) {
|
||||
synchronized (themeToConfigMap) {
|
||||
if (themeToConfigMap.containsKey(themeDir)) {
|
||||
return themeToConfigMap.get(themeDir);
|
||||
} else {
|
||||
FreemarkerConfiguration config = new FreemarkerConfiguration(
|
||||
themeDir, vreq, context);
|
||||
themeDir, appBean, context);
|
||||
themeToConfigMap.put(themeDir, config);
|
||||
return config;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue