1 package com.salto.db.generator.plugin;
2
3 import java.util.Date;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import salto.tool.jdo.data.JdoInfo;
8 import salto.tool.jdo.util.CreatorUtil;
9
10 import com.salto.db.generator.Constants;
11 import com.salto.db.generator.ZipUtil;
12
13 /***
14 * @author rflament@salto-consulting.com
15 *
16 */
17 public class SpringWebappPlugin extends VelocityAbstractPlugin {
18
19 private SpringEJB3AndHibernateDAOPlugin plugin;
20
21 public static final String TEMPLATE_PATH = "springwebapp";
22
23 public void execute(String className, JdoInfo info) throws Exception {
24 plugin.execute(className, info);
25
26 CreatorUtil.getDoNameCreator().setPrefix(doPrefix);
27 CreatorUtil.getDoNameCreator().setDefaultNameOffset(this.defaultNameOffset);
28 Map context = new HashMap();
29 context.put("jdoInfo", info);
30 context.put("util", CreatorUtil.getInstance());
31 context.put("templatePath", TEMPLATE_PATH);
32 context.put("generatorVersion", Constants.GENERATOR_NAME + " / " + this.getShortDescription());
33 context.put("date", new Date());
34 info.setJavaPckName(pckName);
35 info.setJavaClassName(className);
36
37 runVelocity(TEMPLATE_PATH, "listcontroller.vm", srcPath + "/src/" + (pckName + ".webapp.controller").replace('.', '/') + "/", className + "ListController.java", context);
38
39 runVelocity(TEMPLATE_PATH, "addupdatecontroller.vm", srcPath + "/src/" + (pckName + ".webapp.controller").replace('.', '/') + "/", className + "AddUpdateController.java", context);
40
41 runVelocity(TEMPLATE_PATH, "ajaxdeletecontroller.vm", srcPath + "/src/" + (pckName + ".webapp.controller").replace('.', '/') + "/", className + "AjaxDeleteController.java", context);
42
43 runVelocity(TEMPLATE_PATH, "searchcontroller.vm", srcPath + "/src/" + (pckName + ".webapp.controller").replace('.', '/') + "/", className + "SearchController.java", context);
44
45 runVelocity(TEMPLATE_PATH, "editor.vm", srcPath + "/src/" + (pckName + ".webapp.editor").replace('.', '/') + "/", className + "EditorSupport.java", context);
46
47 runVelocity(TEMPLATE_PATH, "emlist.jsp.vm", srcPath + "/WebContent/WEB-INF/pages", CreatorUtil.getDoNameCreator().class2attribute(className) + "EmList.jsp", context);
48
49 runVelocity(TEMPLATE_PATH, "list.jsp.vm", srcPath + "/WebContent/WEB-INF/pages", CreatorUtil.getDoNameCreator().class2attribute(className) + "List.jsp", context);
50
51 runVelocity(TEMPLATE_PATH, "form.jsp.vm", srcPath + "/WebContent/WEB-INF/pages", CreatorUtil.getDoNameCreator().class2attribute(className) + "Form.jsp", context);
52 runVelocity(TEMPLATE_PATH, "searchform.jsp.vm", srcPath + "/WebContent/WEB-INF/pages", CreatorUtil.getDoNameCreator().class2attribute(className) + "SearchForm.jsp", context);
53
54 }
55
56 public void postExecute(JdoInfo[] infos) throws Exception {
57
58 plugin.postExecute(infos);
59
60 CreatorUtil.getDoNameCreator().setPrefix(doPrefix);
61 CreatorUtil.getDoNameCreator().setDefaultNameOffset(this.defaultNameOffset);
62 Map context = new HashMap();
63 context.put("jdoInfos", infos);
64 context.put("connInfo", infos[0].getConnInfo());
65 context.put("util", CreatorUtil.getInstance());
66 context.put("templatePath", TEMPLATE_PATH);
67 context.put("generatorVersion", Constants.GENERATOR_NAME + " / " + this.getShortDescription());
68 context.put("date", new Date());
69 context.put("dialect", this.plugin);
70 context.put("pckName", pckName);
71 context.put("hibernateDialectHelper", new HibernateDialectHelper());
72
73 runVelocity(TEMPLATE_PATH, "action-servlet.xml.vm", srcPath + "/WebContent/WEB-INF/", "action-servlet.xml", context);
74 runVelocity(TEMPLATE_PATH, "web.xml.vm", srcPath + "/WebContent/WEB-INF/", "web.xml", context);
75 runVelocity(TEMPLATE_PATH, "ApplicationResources.properties.vm", srcPath + "/src/", "ApplicationResources.properties", context);
76 runVelocity(TEMPLATE_PATH, "menu.jsp.vm", srcPath + "/WebContent/common", "menu.jsp", context);
77 runVelocity(TEMPLATE_PATH, "menu2.jsp.vm", srcPath + "/WebContent/WEB-INF/pages", "menu.jsp", context);
78 runVelocity(TEMPLATE_PATH, "menu-config.xml.vm", srcPath + "/WebContent/WEB-INF/", "menu-config.xml", context);
79 runVelocity(TEMPLATE_PATH, "log4j.properties.vm", srcPath + "/src/", "log4j.properties", context);
80 runVelocity(TEMPLATE_PATH, "pom.xml.vm", srcPath + "/", "pom.xml", context);
81
82
83 ZipUtil.unzip(this.getClass().getClassLoader().getResourceAsStream("appfuse.zip"), srcPath + "/");
84
85 }
86
87 public String getLongDescription() {
88 return "Generate a complete Spring/Hibernate and Spring MVC webapp";
89 }
90
91 public String getName() {
92 return "springWebapp";
93 }
94
95 public String getShortDescription() {
96 return "Generate a complete Spring/Hibernate and Spring MVC webapp";
97 }
98
99 public void init(String doPrefix, int defaultNameOffset, String srcPath, String pckName) throws Exception {
100 super.init(doPrefix, defaultNameOffset, srcPath, pckName);
101 plugin = new SpringEJB3AndHibernateDAOPlugin();
102 plugin.init(doPrefix, defaultNameOffset, srcPath + "/src", pckName);
103 }
104
105 }