1 16 17 package org.springframework.web.servlet.view.freemarker; 18 19 import java.io.IOException ; 20 import java.util.List ; 21 22 import javax.servlet.ServletContext ; 23 24 import freemarker.cache.ClassTemplateLoader; 25 import freemarker.ext.jsp.TaglibFactory; 26 import freemarker.template.Configuration; 27 import freemarker.template.TemplateException; 28 29 import org.springframework.beans.factory.InitializingBean; 30 import org.springframework.context.ResourceLoaderAware; 31 import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory; 32 import org.springframework.web.context.ServletContextAware; 33 34 78 public class FreeMarkerConfigurer extends FreeMarkerConfigurationFactory 79 implements FreeMarkerConfig, InitializingBean, ResourceLoaderAware, ServletContextAware { 80 81 private Configuration configuration; 82 83 private TaglibFactory taglibFactory; 84 85 86 93 public void setConfiguration(Configuration configuration) { 94 this.configuration = configuration; 95 } 96 97 100 public void setServletContext(ServletContext servletContext) { 101 this.taglibFactory = new TaglibFactory(servletContext); 102 } 103 104 105 112 public void afterPropertiesSet() throws IOException , TemplateException { 113 if (this.configuration == null) { 114 this.configuration = createConfiguration(); 115 } 116 } 117 118 122 protected void postProcessTemplateLoaders(List templateLoaders) { 123 templateLoaders.add(new ClassTemplateLoader(FreeMarkerConfigurer.class, "")); 124 logger.info("ClassTemplateLoader for Spring macros added to FreeMarker configuration"); 125 } 126 127 128 131 public Configuration getConfiguration() { 132 return this.configuration; 133 } 134 135 138 public TaglibFactory getTaglibFactory() { 139 return this.taglibFactory; 140 } 141 142 } 143 | Popular Tags |