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.cache.TemplateLoader;
20 import freemarker.template.Configuration;
21
22 import java.io.File;
23 import java.io.InputStream;
24
25
26
27
28 public class FreemarkerAftTmplMthdBlanketAppGenerator {
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(FreemarkerAftTmplMthdBlanketAppGenerator.class, DIR_TMPL);
36
37 public static void main(String[] args) throws Exception {
38 cfg.setTemplateLoader(templateLoader);
39
40 String propLocation = "/GenFiles/AdminTmplMthdBlanketAppAftNavBase.properties";
41 if (args.length > 0) {
42 propLocation = "/GenFiles/" + args[0];
43 }
44
45 String template = "TmplMthdBlanketAppSTNavBase.ftl";
46
47
48 createFile(propLocation, template);
49 }
50
51 private static void createFile(String propLocation, String template) throws Exception {
52 try {
53 InputStream in = FreemarkerAftTmplMthdBlanketAppGenerator.class.getResourceAsStream(propLocation);
54 File f1 = new File("src" + File.separatorChar + "it" + File.separatorChar + "resources"
55 + File.separatorChar + "GenFiles" + File.separatorChar
56 + propLocation.substring(propLocation.lastIndexOf("/"), propLocation.lastIndexOf("."))
57 + template.substring(0, template.length() - 4) + ".java");
58 FreemarkerUtil.ftlWrite(f1, cfg.getTemplate(template), in);
59
60 } catch (Exception e) {
61 e.printStackTrace();
62 throw new Exception("Unable to generate files", e);
63 }
64 }
65 }