VIVO-246 Set up the Freemarker directives in only one place.

This commit is contained in:
j2blake 2013-08-05 16:54:49 -04:00
parent 9a0ec5a76e
commit 7083d8acc4
3 changed files with 8 additions and 17 deletions

View file

@ -29,6 +29,8 @@ import edu.cornell.mannlib.vitro.webapp.i18n.freemarker.I18nMethodModel;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.web.directives.IndividualShortViewDirective;
import edu.cornell.mannlib.vitro.webapp.web.directives.UrlDirective;
import edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualPlaceholderImageUrlMethod;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod;
@ -167,12 +169,16 @@ public class FreemarkerConfiguration extends Configuration {
return urls;
}
public static Map<String, Object> getDirectives() {
private static Map<String, Object> getDirectives() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("dump", new freemarker.ext.dump.DumpDirective());
map.put("dumpAll", new freemarker.ext.dump.DumpAllDirective());
map.put("help", new freemarker.ext.dump.HelpDirective());
map.put("shortView", new IndividualShortViewDirective());
map.put("url", new UrlDirective());
map.put("widget", new WidgetDirective());
return map;
}

View file

@ -427,10 +427,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// 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());
map.putAll( FreemarkerConfiguration.getDirectives() );
// Add these accumulator objects. They will collect tags so the template can write them
// at the appropriate location.
map.put("stylesheets", new Tags().wrap());

View file

@ -13,10 +13,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
import freemarker.core.Environment;
import freemarker.core.ParseException;
import freemarker.template.Configuration;
import freemarker.template.Template;
@ -75,16 +73,7 @@ public class FreemarkerProcessingServiceImpl implements
StringWriter writer = new StringWriter();
try {
// Add directives to the map. For some reason, having them in the
// configuration is not enough.
map.putAll(FreemarkerConfiguration.getDirectives());
// Add request and servlet context as custom attributes of the
// environment, so they
// can be used in directives.
Environment env = template.createProcessingEnvironment(map, writer);
env.setCustomAttribute("request", req);
env.process();
template.process(map, writer);
return writer.toString();
} catch (TemplateException e) {
throw new TemplateProcessingException(