mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
return null if no template could be found
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.template;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -43,8 +44,12 @@ import freemarker.cache.WebappTemplateLoader;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -68,6 +73,12 @@ public class FreemarkerTemplateEngine implements TemplateEngine
|
||||
public static final TemplateType TYPE = new TemplateType("freemarker",
|
||||
"Freemarker", "ftl", "freemarker");
|
||||
|
||||
/**
|
||||
* the logger for FreemarkerTemplateEngine
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(FreemarkerTemplateEngine.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -110,13 +121,28 @@ public class FreemarkerTemplateEngine implements TemplateEngine
|
||||
public FreemarkerTemplate getTemplate(String templatePath) throws IOException
|
||||
{
|
||||
FreemarkerTemplate template = null;
|
||||
freemarker.template.Template t = configuration.getTemplate(templatePath,
|
||||
ENCODING);
|
||||
freemarker.template.Template t = null;
|
||||
|
||||
try
|
||||
{
|
||||
t = configuration.getTemplate(templatePath, ENCODING);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("could not find template ".concat(templatePath), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (t != null)
|
||||
{
|
||||
template = new FreemarkerTemplate(t);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find freemarker template at {}", templatePath);
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user