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 import org.testng.annotations.BeforeMethod;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.Properties;
31
32
33
34
35
36 public abstract class FreemarkerSTBase extends WebDriverLegacyITBase {
37
38 protected final Logger LOG = Logger.getLogger(getClass());
39
40 protected Configuration cfg;
41
42 protected abstract String getTemplateDir();
43
44 @Override
45 @Before
46 @BeforeMethod
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 = FreemarkerUtil.loadProperties(in);
86 in.close();
87 }
88
89 return props;
90 }
91
92
93
94
95
96
97 protected void systemPropertiesOverride(Properties props, String key) {
98 FreemarkerUtil.systemPropertiesOverride(props, key);
99 }
100
101
102
103
104
105
106
107
108
109
110 protected static File writeTemplateToFile(File file, Template template, Properties props) throws IOException, TemplateException {
111 return FreemarkerUtil.writeTemplateToFile(file, template, props);
112 }
113 }