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