1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.common;
17
18 import java.io.File;
19 import java.io.InputStream;
20
21 import freemarker.cache.ClassTemplateLoader;
22 import freemarker.cache.TemplateLoader;
23 import freemarker.template.Configuration;
24
25
26
27
28 public class FreemarkerSTTmplMthdGenerator {
29 private static Configuration cfg = new Configuration();
30
31
32 private static String DIR_TMPL = "/Gen/";
33
34
35 private static TemplateLoader templateLoader = new ClassTemplateLoader(FreemarkerSTTmplMthdGenerator.class, DIR_TMPL);
36
37 public static void main(String[] args) throws Exception {
38 cfg.setTemplateLoader(templateLoader);
39
40 String propLocation = "/GenFiles/MainTmplMthdSTNavBase.properties";
41 String template = "TmplMthdSTNavBase.ftl";
42
43 createFile(propLocation, template);
44 }
45
46 private static void createFile(String propLocation, String template) throws Exception {
47 try {
48 InputStream in = FreemarkerSTTmplMthdGenerator.class.getResourceAsStream(propLocation);
49 File f1 = new File("src" + File.separatorChar + "it" + File.separatorChar + "resources"
50 + File.separatorChar + "GenFiles" + File.separatorChar
51 + propLocation.substring(propLocation.lastIndexOf("/"), propLocation.lastIndexOf("."))
52 + template.substring(0, template.length() - 4) + ".java");
53 FreemarkerUtil.ftlWrite(f1, cfg.getTemplate(template), in);
54
55 } catch (Exception e) {
56 e.printStackTrace();
57 throw new Exception("Unable to generate files", e);
58 }
59 }
60 }