1 | |
package org.jbehave.core.reporters; |
2 | |
|
3 | |
import java.io.Writer; |
4 | |
import java.util.Map; |
5 | |
|
6 | |
import freemarker.template.Configuration; |
7 | |
import freemarker.template.ObjectWrapper; |
8 | |
|
9 | 938 | public class FreemarkerProcessor implements TemplateProcessor { |
10 | |
|
11 | |
public void process(String resource, Map<String, Object> dataModel, Writer writer) { |
12 | 52 | Configuration configuration = configuration(); |
13 | |
try { |
14 | 52 | configuration.getTemplate(resource).process(dataModel, writer); |
15 | 1 | } catch (Exception e) { |
16 | 1 | throw new FreemarkerProcessingFailed(configuration, resource, dataModel, e); |
17 | 51 | } |
18 | 51 | } |
19 | |
|
20 | |
public Configuration configuration() { |
21 | 52 | Configuration configuration = new Configuration(); |
22 | 52 | configuration.setClassForTemplateLoading(FreemarkerProcessor.class, "/"); |
23 | 52 | configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER); |
24 | 52 | return configuration; |
25 | |
} |
26 | |
|
27 | 938 | @SuppressWarnings("serial") |
28 | |
public static class FreemarkerProcessingFailed extends RuntimeException { |
29 | |
|
30 | |
public FreemarkerProcessingFailed(Configuration configuration, String resource, Map<String, Object> dataModel, Exception cause) { |
31 | 1 | super("Freemarker failed to process template " + resource + " using configuration "+configuration + " and data model "+dataModel, cause); |
32 | 1 | } |
33 | |
|
34 | |
} |
35 | |
|
36 | |
} |