Coverage Report - org.jbehave.core.reporters.FreemarkerProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
FreemarkerProcessor
100%
15/15
N/A
1.4
FreemarkerProcessor$FreemarkerProcessingFailed
100%
2/2
N/A
1.4
 
 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  
 public class FreemarkerProcessor implements TemplateProcessor {
 10  
     private Class<?> templateLoadingFrom;
 11  
         
 12  
     public FreemarkerProcessor() {
 13  2
         this(FreemarkerProcessor.class);
 14  2
     }
 15  
 
 16  335
     public FreemarkerProcessor(Class<?> templateLoadingFrom) {
 17  335
         this.templateLoadingFrom = templateLoadingFrom;
 18  335
     }
 19  
 
 20  
     public void process(String resource, Map<String, Object> dataModel, Writer writer) {
 21  294
         Configuration configuration = configuration();
 22  
         try {
 23  294
             configuration.getTemplate(resource).process(dataModel, writer);
 24  1
         } catch (Exception e) {
 25  1
             throw new FreemarkerProcessingFailed(configuration, resource, dataModel, e);
 26  293
         }
 27  293
     }
 28  
 
 29  
     public Configuration configuration() {
 30  294
         Configuration configuration = new Configuration();
 31  294
         configuration.setClassForTemplateLoading(templateLoadingFrom, "/");
 32  294
         configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
 33  294
         return configuration;
 34  
     }
 35  
 
 36  
     @SuppressWarnings("serial")
 37  
     public static class FreemarkerProcessingFailed extends RuntimeException {
 38  
 
 39  
         public FreemarkerProcessingFailed(Configuration configuration, String resource, Map<String, Object> dataModel, Exception cause) {
 40  1
             super("Freemarker failed to process template " + resource + " using configuration "+configuration + " and data model "+dataModel, cause);
 41  1
         }
 42  
         
 43  
     }
 44  
 
 45  
 }