Skip to content

Commit

Permalink
Render as much content as possible - even if there are missing parame…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
tomcz committed Oct 25, 2011
1 parent 8a50d58 commit 448a497
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions example-webapp.ipr
Expand Up @@ -351,6 +351,7 @@
<root url="jar://$PROJECT_DIR$/lib/compile/source/freemarker-2.3.18.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/compile/source/hibernate-core-3.6.7.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/compile/source/spring-webmvc-3.0.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/compile/source/spring-context-support-3.0.6.RELEASE.jar!/" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile/jar" recursive="false" />
</library>
Expand Down
25 changes: 25 additions & 0 deletions src/main/example/ftl/HtmlExceptionHandler.java
@@ -0,0 +1,25 @@
package example.ftl;

import freemarker.core.Environment;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.Writer;

public class HtmlExceptionHandler implements TemplateExceptionHandler {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException {
logger.warn(te.getMessage() + "\n" + te.getFTLInstructionStack());
try {
out.write("???");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
19 changes: 19 additions & 0 deletions src/main/example/ftl/HtmlFreeMarkerConfigurer.java
@@ -1,8 +1,12 @@
package example.ftl;

import freemarker.cache.TemplateLoader;
import freemarker.log.Logger;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;
import java.util.List;

public class HtmlFreeMarkerConfigurer extends FreeMarkerConfigurer {
Expand All @@ -18,4 +22,19 @@ protected void postProcessTemplateLoaders(List<TemplateLoader> templateLoaders)
// spring.ftl from classpath will not work with the HtmlTemplateLoader
// use /WEB-INF/templates/spring.ftl instead
}

@Override
protected void postProcessConfiguration(Configuration config) throws IOException, TemplateException {
config.setTemplateExceptionHandler(new HtmlExceptionHandler());
}

@Override
public void afterPropertiesSet() throws IOException, TemplateException {
try {
Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
super.afterPropertiesSet();
}
}
1 change: 1 addition & 0 deletions src/main/logback.xml
Expand Up @@ -8,6 +8,7 @@

<logger name="example" level="INFO" />
<logger name="org.mortbay" level="INFO" />
<logger name="freemarker.runtime" level="OFF" />
<logger name="STATS" level="TRACE" />

<root level="WARN">
Expand Down

0 comments on commit 448a497

Please sign in to comment.