Repository navigation
Expand file tree
/
Copy pathHelp.java
More file actions
169 lines (143 loc) · 6.78 KB
/
Copy pathHelp.java
File metadata and controls
169 lines (143 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (C) 2015 Peter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.genelet.helper.GeneClass;
import com.genelet.helper.GeneConfig;
import com.genelet.helper.GeneHelp;
import static com.genelet.helper.GeneHelp.chdir;
import static com.genelet.helper.GeneHelp.firstUpper;
import com.genelet.helper.ViewAG;
import com.genelet.helper.ViewJsp;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
/**
*
* @author Peter
*/
public class Help {
/**
* @param args the command line arguments
* @throws java.sql.SQLException
* @throws java.io.FileNotFoundException
* @throws org.kohsuke.args4j.CmdLineException
*/
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException, CmdLineException {
GeneHelp gh = new GeneHelp();
CmdLineParser parser = new CmdLineParser(gh);
parser.parseArgument(args);
if( gh.tables.isEmpty() ) {
System.err.println("Usage: Help [options] table1 table2 ...\n" +
" --root program root, default '.'\n" +
" --dbtype database type 'sqlite' or 'mysql', default 'mysql'\n" +
" --dbname database name, mandatory\n" +
" --dbuser database username, default ''\n" +
" --dbpass database password, default ''\n" +
" --proj project name, default to 'myproject'\n" +
" --scri script name, default to 'myscript'\n" +
" --force if to override existing files, default to false\n" +
" --angular if to include Angular 1.3 files, default to false");
System.exit(1);
}
try ( //Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(gh.jdbc_name(), gh.dbuser, gh.dbpass)) {
gh.dir_all();
String root = gh.root;
String proj = gh.proj;
String scri = gh.scri;
List<String> tables = gh.tables;
GeneConfig cnf = new GeneConfig(gh);
GeneClass cls = new GeneClass(proj, scri, tables);
ViewAG ag = new ViewAG(proj, scri, tables);
ViewJsp jsp = new ViewJsp(proj, scri, tables);
if (chdir(root+"/web")) {
gh.write_it("index.html", jsp.index());
}
if (chdir(root+"/web/WEB-INF")) {
gh.write_it("config.json", cnf.config());
gh.write_it("web.xml", cnf.xml());
}
if (chdir(root+"/src/"+proj)) {
gh.write_it(firstUpper(proj)+"Filter.java", cls.filter());
gh.write_it(firstUpper(proj)+"Model.java", cls.model());
gh.write_it(firstUpper(proj)+"Servlet.java", cls.servlet());
gh.write_it(firstUpper(proj)+"ServletListener.java", cls.listener());
}
if (chdir(root+"/web/WEB-INF/views/admin")) {
gh.write_it("login.html", jsp.login());
}
if (chdir(root+"/web") && gh.angular) {
gh.write_it("index.html", ag.index());
gh.write_it("init.js", ag.init());
//gh.write_it("genelet.js", ag.ag_geneletjs());
}
if (chdir(root+"/web/admin") && gh.angular) {
gh.write_it("header.html", ag.header(ag.bar()));
gh.write_it("footer.html", "");
gh.write_it("login.html", ag.login());
}
if (chdir(root+"/web/public") && gh.angular) {
gh.write_it("header.html", ag.header(""));
gh.write_it("footer.html", "");
}
if (chdir(root+"/web/public/"+ag.tables.get(0)) && gh.angular) {
gh.write_it("startnew.html", ag.rolepublic());
}
int i=0;
for (String t : tables) {
List<Object> tmp = gh.obj(conn, t);
String pk = (String) tmp.get(0);
String ak = (String) tmp.get(1);
List<String> nons = (List<String>) tmp.get(2);
List<String> fields = (List<String>) tmp.get(3);
System.err.println(t);
System.err.println(fields);
if (chdir(root+"/src/"+proj+"/"+t.replace("_",""))) {
if (i==0) {
gh.write_it("component.json", cls.obj_json(t, pk, ak, nons, fields, ", \"groups\" : [\"public\"]"));
} else {
gh.write_it("component.json", cls.obj_json(t, pk, ak, nons, fields, ""));
}
gh.write_it("Filter.java", cls.obj_filter(t));
gh.write_it("Model.java", cls.obj_model(t));
}
if (i==0 && chdir(root+"/web/WEB-INF/views/public/"+t.replace("_",""))) {
gh.write_it("topics.html", jsp.topics(t, ak, pk, fields));
}
if (chdir(root+"/web/WEB-INF/views/admin/"+t.replace("_",""))) {
gh.write_it("insert.html", jsp.top()+"<h3>Added</h3>" +jsp.bottom());
gh.write_it("delete.html", jsp.top()+"<h3>Deleted</h3>"+jsp.bottom());
gh.write_it("update.html", jsp.top()+"<h3>Updated</h3>"+jsp.bottom());
gh.write_it("startnew.html",jsp.startnew(t, pk, nons, fields));
gh.write_it("topics.html", jsp.topics(t, ak, pk, fields));
gh.write_it("edit.html", jsp.edit(t, pk, fields));
}
if (chdir(root+"/web/admin/"+t) && gh.angular) {
gh.write_it("startnew.html", ag.startnew(t, pk, nons, fields));
gh.write_it("topics.html", ag.topics(t, pk, fields));
gh.write_it("edit.html", ag.edit(t, pk, fields));
}
i++;
}
conn.close();
}
}
}