use of freemarker.template.TemplateNotFoundException in project ninja by ninjaframework.
the class TemplateEngineFreemarker method throwRenderingException.
public void throwRenderingException(Context context, Result result, Exception cause, String knownTemplateSourcePath) {
// a more useful ParseException
if (cause instanceof IOException && cause.getCause() != null && cause.getCause() instanceof ParseException) {
cause = (ParseException) cause.getCause();
}
if (cause instanceof TemplateNotFoundException) {
// inner cause will be better to display
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker template not found", knownTemplateSourcePath, -1);
} else if (cause instanceof TemplateException) {
TemplateException te = (TemplateException) cause;
String templateSourcePath = te.getTemplateSourceName();
if (templateSourcePath == null) {
templateSourcePath = knownTemplateSourcePath;
}
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker render exception", templateSourcePath, te.getLineNumber());
} else if (cause instanceof ParseException) {
ParseException pe = (ParseException) cause;
String templateSourcePath = pe.getTemplateName();
if (templateSourcePath == null) {
templateSourcePath = knownTemplateSourcePath;
}
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker parser exception", templateSourcePath, pe.getLineNumber());
}
// fallback to throwing generic rendering exception
throw new RenderingException(cause.getMessage(), cause, result, knownTemplateSourcePath, -1);
}
use of freemarker.template.TemplateNotFoundException in project greenDAO by greenrobot.
the class DaoGenerator method getConfiguration.
private Configuration getConfiguration(String probingTemplate) throws IOException {
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
config.setClassForTemplateLoading(getClass(), "/");
try {
config.getTemplate(probingTemplate);
} catch (TemplateNotFoundException e) {
// When running from an IDE like IntelliJ, class loading resources may fail for some reason (Gradle is OK)
// Working dir is module dir
File dir = new File("src/main/resources/");
if (!dir.exists()) {
// Working dir is base module dir
dir = new File("DaoGenerator/src/main/resources/");
}
if (dir.exists() && new File(dir, probingTemplate).exists()) {
config.setDirectoryForTemplateLoading(dir);
config.getTemplate(probingTemplate);
} else {
throw e;
}
}
return config;
}
Aggregations