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