NIHVIVO-564 Refactoring in FreemarkerHelper to take Configuration object in constructor and store as instance variable; individual methods don't need the param.

This commit is contained in:
rjy7 2010-08-05 15:32:48 +00:00
parent 528414e4c7
commit 107162012a
5 changed files with 15 additions and 9 deletions

View file

@ -16,8 +16,14 @@ import freemarker.template.TemplateException;
public class FreemarkerHelper { public class FreemarkerHelper {
private static final Log log = LogFactory.getLog(FreemarkerHelper.class); private static final Log log = LogFactory.getLog(FreemarkerHelper.class);
private Configuration config = null;
public FreemarkerHelper(Configuration config) {
this.config = config;
}
public StringWriter mergeToTemplate(String templateName, Map<String, Object> map, Configuration config) { public StringWriter mergeToTemplate(String templateName, Map<String, Object> map) {
Template template = null; Template template = null;
try { try {
@ -40,8 +46,8 @@ public class FreemarkerHelper {
return sw; return sw;
} }
public String mergeMapToTemplate(String templateName, Map<String, Object> map, Configuration config) { public String mergeMapToTemplate(String templateName, Map<String, Object> map) {
return mergeToTemplate(templateName, map, config).toString(); return mergeToTemplate(templateName, map).toString();
} }
} }

View file

@ -376,8 +376,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
} }
protected StringWriter mergeToTemplate(String templateName, Map<String, Object> map, Configuration config) { protected StringWriter mergeToTemplate(String templateName, Map<String, Object> map, Configuration config) {
FreemarkerHelper helper = new FreemarkerHelper(); FreemarkerHelper helper = new FreemarkerHelper(config);
return helper.mergeToTemplate(templateName, map, config); return helper.mergeToTemplate(templateName, map);
} }
protected String mergeBodyToTemplate(String templateName, Map<String, Object> map, Configuration config) { protected String mergeBodyToTemplate(String templateName, Map<String, Object> map, Configuration config) {

View file

@ -32,7 +32,7 @@ public abstract class BaseTemplateDirectiveModel implements TemplateDirectiveMod
} }
protected String mergeToTemplate(Map<String, Object> map, Configuration config) { protected String mergeToTemplate(Map<String, Object> map, Configuration config) {
return new FreemarkerHelper().mergeMapToTemplate("directive-help.ftl", map, config); return new FreemarkerHelper(config).mergeMapToTemplate("directive-help.ftl", map);
} }
} }

View file

@ -82,8 +82,8 @@ public class DumpAllDirective extends BaseTemplateDirectiveModel {
map.put("datamodel", dataModel); map.put("datamodel", dataModel);
map.put("containingTemplate", env.getTemplate().getName()); map.put("containingTemplate", env.getTemplate().getName());
FreemarkerHelper helper = new FreemarkerHelper(); FreemarkerHelper helper = new FreemarkerHelper(config);
String output = helper.mergeMapToTemplate(templateName, map, config); String output = helper.mergeMapToTemplate(templateName, map);
Writer out = env.getOut(); Writer out = env.getOut();
out.write(output); out.write(output);

View file

@ -116,7 +116,7 @@ public class DumpDirective extends BaseTemplateDirectiveModel {
map.put("stylesheets", dataModel.get("stylesheets")); map.put("stylesheets", dataModel.get("stylesheets"));
//map.put("dump", this); // would need for recursive calls //map.put("dump", this); // would need for recursive calls
String output = new FreemarkerHelper().mergeMapToTemplate("dump-var.ftl", map, env.getConfiguration()); String output = new FreemarkerHelper(env.getConfiguration()).mergeMapToTemplate("dump-var.ftl", map);
Writer out = env.getOut(); Writer out = env.getOut();
out.write(output); out.write(output);