1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package edu.sampleu.common;
17  
18  import freemarker.cache.ClassTemplateLoader;
19  import freemarker.template.Configuration;
20  import freemarker.template.Template;
21  import freemarker.template.TemplateException;
22  import org.apache.log4j.Logger;
23  import org.junit.Before;
24  import org.kuali.rice.testtools.common.PropertiesUtils;
25  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
26  
27  import java.io.File;
28  import java.io.FileInputStream;
29  import java.io.IOException;
30  import java.io.InputStream;
31  import java.util.Properties;
32  
33  
34  
35  
36  
37  public abstract class FreemarkerAftBase extends WebDriverLegacyITBase {
38  
39      protected final Logger LOG = Logger.getLogger(getClass());
40  
41      protected Configuration cfg;
42  
43      protected abstract String getTemplateDir();
44  
45      @Override
46      @Before
47      public void testSetUp() {
48          super.testSetUp();
49          
50          cfg = new Configuration();
51          cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), getTemplateDir()));
52      }
53  
54      
55  
56  
57  
58  
59  
60  
61  
62  
63      public File ftlWrite(File output, Template template, InputStream inputStream) throws IOException, TemplateException {
64  
65          return FreemarkerUtil.ftlWrite(output.getName(), output, template, inputStream);
66      }
67  
68      
69  
70  
71  
72  
73  
74  
75  
76      protected Properties loadProperties(String fileLocation, String resourceLocation) throws IOException {
77          Properties props = null;
78          InputStream in = null;
79          if(fileLocation != null) {
80              in = new FileInputStream(fileLocation);
81          } else {
82              in = getClass().getClassLoader().getResourceAsStream(resourceLocation);
83          }
84          if(in != null) {
85              props = new PropertiesUtils().loadProperties(in);
86              in.close();
87          }
88  
89          return props;
90      }
91  
92      
93  
94  
95  
96  
97  
98  
99  
100 
101     protected static File writeTemplateToFile(File file, Template template, Properties props) throws IOException, TemplateException {
102         return FreemarkerUtil.writeTemplateToFile(file, template, props);
103     }
104 }