mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
templates can be loaded from webapp context or classpath
This commit is contained in:
@@ -38,6 +38,11 @@ package sonia.scm.template;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import freemarker.cache.ClassTemplateLoader;
|
||||||
|
import freemarker.cache.MultiTemplateLoader;
|
||||||
|
import freemarker.cache.TemplateLoader;
|
||||||
|
import freemarker.cache.WebappTemplateLoader;
|
||||||
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
@@ -64,6 +69,9 @@ import javax.servlet.ServletContext;
|
|||||||
public class FreemarkerTemplateHandler implements TemplateHandler
|
public class FreemarkerTemplateHandler implements TemplateHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String DIRECTORY_CLASS_TEMPLATES = "/templates";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String DIRECTORY_TEMPLATES = "/";
|
public static final String DIRECTORY_TEMPLATES = "/";
|
||||||
|
|
||||||
@@ -89,9 +97,18 @@ public class FreemarkerTemplateHandler implements TemplateHandler
|
|||||||
public FreemarkerTemplateHandler(ServletContext servletContext)
|
public FreemarkerTemplateHandler(ServletContext servletContext)
|
||||||
{
|
{
|
||||||
configuration = new Configuration();
|
configuration = new Configuration();
|
||||||
configuration.setServletContextForTemplateLoading(servletContext,
|
|
||||||
DIRECTORY_TEMPLATES);
|
|
||||||
configuration.setEncoding(Locale.ENGLISH, ENCODING);
|
configuration.setEncoding(Locale.ENGLISH, ENCODING);
|
||||||
|
//J-
|
||||||
|
configuration.setTemplateLoader(
|
||||||
|
new MultiTemplateLoader(
|
||||||
|
new TemplateLoader[] {
|
||||||
|
new WebappTemplateLoader(servletContext, DIRECTORY_TEMPLATES),
|
||||||
|
new ClassTemplateLoader(FreemarkerTemplateHandler.class,
|
||||||
|
DIRECTORY_CLASS_TEMPLATES)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//J+
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user