/** * Create the template loader. The default implementation will create a {@link ClassTemplateLoader} if the template * path starts with {@code "class://"}, a {@link FileTemplateLoader} if the template path starts with * {@code "file://"}, and a {@link WebappTemplateLoader} otherwise. Also, if * {@link Configuration#Configuration(freemarker.template.Version) incompatible_improvements} is 2.3.22 or higher, * it will create a {@link MultiTemplateLoader} if the template path starts with {@code "["}. * * @param templatePath * the template path to create a loader for * @return a newly created template loader */ protected TemplateLoader createTemplateLoader(String templatePath) throws IOException { return InitParamParser.createTemplateLoader(templatePath, getConfiguration(), getClass(), getServletContext()); }
/** * Create the template loader. The default implementation will create a {@link ClassTemplateLoader} if the template * path starts with {@code "class://"}, a {@link FileTemplateLoader} if the template path starts with * {@code "file://"}, and a {@link WebappTemplateLoader} otherwise. Also, if * {@link Configuration#Configuration(freemarker.template.Version) incompatible_improvements} is 2.3.22 or higher, * it will create a {@link MultiTemplateLoader} if the template path starts with {@code "["}. * * @param templatePath * the template path to create a loader for * @return a newly created template loader */ protected TemplateLoader createTemplateLoader(String templatePath) throws IOException { return InitParamParser.createTemplateLoader(templatePath, getConfiguration(), getClass(), getServletContext()); }
/** * Create the template loader. The default implementation will create a {@link ClassTemplateLoader} if the template * path starts with {@code "class://"}, a {@link FileTemplateLoader} if the template path starts with * {@code "file://"}, and a {@link WebappTemplateLoader} otherwise. Also, if * {@link Configuration#Configuration(freemarker.template.Version) incompatible_improvements} is 2.3.22 or higher, * it will create a {@link MultiTemplateLoader} if the template path starts with {@code "["}. * * @param templatePath * the template path to create a loader for * @return a newly created template loader */ protected TemplateLoader createTemplateLoader(String templatePath) throws IOException { return InitParamParser.createTemplateLoader(templatePath, getConfiguration(), getClass(), getServletContext()); }
@Override public void init() throws ServletException { super.init(); /* * we here need to inject our own template loader. We cannot do this in createConfiguration() as we would like, * because the FreemarkerServlet sets the template loader in the init() *after* createConfiguration() again, to the default * WebappTemplateLoader */ Configuration conf = super.getConfiguration(); TemplateLoader defaultLoader = conf.getTemplateLoader(); // repository template loader TemplateLoader repositoryLoader = new RepositoryTemplateLoader(); TemplateLoader[] loaders = new TemplateLoader[] { defaultLoader, repositoryLoader }; TemplateLoader multiLoader = new MultiTemplateLoader(loaders); conf.setTemplateLoader(multiLoader); conf.setLocalizedLookup(false); }
super.init(config); Configuration conf = super.getConfiguration();