1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.common;
17
18 import freemarker.template.Configuration;
19 import freemarker.template.Template;
20 import freemarker.template.TemplateException;
21 import org.apache.commons.io.FileUtils;
22 import org.apache.log4j.Logger;
23 import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
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.Enumeration;
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
43
44
45
46
47
48
49
50
51 public File ftlWrite(File output, Template template, InputStream inputStream) throws IOException, TemplateException {
52
53 return FreemarkerUtil.ftlWrite(output.getName(), output, template, inputStream);
54 }
55
56
57
58
59
60
61
62
63
64 protected Properties loadProperties(String fileLocation, String resourceLocation) throws IOException {
65 Properties props = new Properties();
66 InputStream in = null;
67 if(fileLocation != null) {
68 in = new FileInputStream(fileLocation);
69 } else {
70 in = getClass().getClassLoader().getResourceAsStream(resourceLocation);
71 }
72 if(in != null) {
73 FreemarkerUtil.loadProperties(in);
74 in.close();
75 }
76
77 return props;
78 }
79
80
81
82
83
84
85 protected void systemPropertiesOverride(Properties props, String key) {
86 FreemarkerUtil.systemPropertiesOverride(props, key);
87 }
88
89
90
91
92
93
94
95
96
97
98 protected static File writeTemplateToFile(File file, Template template, Properties props) throws IOException, TemplateException {
99 return FreemarkerUtil.writeTemplateToFile(file, template, props);
100 }
101 }