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