Coverage Report - org.webslinger.ext.template.freemarker.FreemarkerCompiler
 
Classes in this File Line Coverage Branch Coverage Complexity
FreemarkerCompiler
64%
9/14
N/A
0
 
 1  
 package org.webslinger.ext.template.freemarker;
 2  
 
 3  
 import java.io.StringReader;
 4  
 import java.io.IOException;
 5  
 
 6  
 import org.apache.bsf.BSFDeclaredBean;
 7  
 import org.apache.bsf.BSFException;
 8  
 
 9  
 import freemarker.core.Environment;
 10  
 import freemarker.ext.beans.BeanModel;
 11  
 import freemarker.ext.beans.BeansWrapper;
 12  
 import freemarker.template.Configuration;
 13  
 import freemarker.template.SimpleHash;
 14  
 import freemarker.template.SimpleScalar;
 15  
 import freemarker.template.Template;
 16  
 import freemarker.template.TemplateHashModel;
 17  
 import freemarker.template.TemplateModel;
 18  
 import freemarker.template.TemplateModelException;
 19  
 
 20  
 import org.webslinger.bsf.ApplyKey;
 21  
 import org.webslinger.bsf.Compiler;
 22  
 import org.webslinger.bsf.EvalKey;
 23  
 import org.webslinger.bsf.ExecKey;
 24  
 import org.webslinger.bsf.Key;
 25  
 
 26  6
 public class FreemarkerCompiler extends Compiler<LocalFreemarkerTemplate, LocalFreemarkerTemplate> {
 27  
     protected final Configuration config;
 28  
 
 29  
     public FreemarkerCompiler(FreemarkerTemplateEngine engine) throws BSFException {
 30  3
         super(engine);
 31  3
         config = new Configuration();
 32  3
         config.setObjectWrapper(new BeansWrapper());
 33  
         //config.setTemplateLoader(new FreemarkerLoader(this));
 34  3
     }
 35  
 
 36  
     public void declareBean(BSFDeclaredBean bean) throws BSFException {
 37  107
     }
 38  
 
 39  
     public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
 40  0
     }
 41  
 
 42  
     protected CompilerContext newContext(Key<LocalFreemarkerTemplate> key) throws BSFException {
 43  3
         return new CompilerContext(key);
 44  
     }
 45  
 
 46  
     protected LocalFreemarkerTemplate init(CompilerContext context, LocalFreemarkerTemplate compiled) {
 47  3
         return compiled;
 48  
     }
 49  
 
 50  
     public LocalFreemarkerTemplate compileKey(ApplyKey<LocalFreemarkerTemplate> key, CompilerContext context) throws BSFException {
 51  
         // FIXME: set path
 52  
         try {
 53  3
             return new LocalFreemarkerTemplate(null, new StringReader(context.text), config, "UTF-8", key.getNames());
 54  0
         } catch (IOException e) {
 55  0
             throw (BSFException) new BSFException(e.getMessage()).initCause(e);
 56  
         }
 57  
     }
 58  
 
 59  
     public LocalFreemarkerTemplate compileKey(EvalKey<LocalFreemarkerTemplate> key, CompilerContext context) throws BSFException {
 60  0
         if (true) throw new IllegalArgumentException();
 61  
         return null;
 62  
     }
 63  
 
 64  
     public LocalFreemarkerTemplate compileKey(ExecKey<LocalFreemarkerTemplate> key, CompilerContext context) throws BSFException {
 65  0
         if (true) throw new IllegalArgumentException();
 66  
         return null;
 67  
     }
 68  
 }