Revize 51ce052a
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java | ||
---|---|---|
55 | 55 |
} else { |
56 | 56 |
request.getSession().setAttribute("json_graph", jsonData.get("file")); |
57 | 57 |
request.getSession().setAttribute("json_graph_type", jsonData.get("jsonFileFormat")); |
58 |
response.sendRedirect(getServletContext().getInitParameter("HOME_URL") + "graph"); |
|
58 |
response.sendRedirect(getServletContext().getInitParameter("APP_HOME_URL") + "graph");
|
|
59 | 59 |
} |
60 | 60 |
} |
61 | 61 |
} |
sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java | ||
---|---|---|
13 | 13 |
*/ |
14 | 14 |
|
15 | 15 |
public class DB { |
16 |
private Connection conn = null;
|
|
16 |
private Connection connection;
|
|
17 | 17 |
|
18 | 18 |
/** |
19 |
* Constructor opens connection do database. Access data must be save in ServletContext as InitParameter( DbUrl, DbName, DbUser, DbPsw ).
|
|
19 |
* Constructor opens connection do database. Access credentials must be stored in ServletContext as InitParameter.
|
|
20 | 20 |
*/ |
21 |
public DB(ServletContext context){ |
|
22 |
|
|
23 |
try { |
|
24 |
Class.forName("com.mysql.jdbc.Driver"); |
|
21 |
public DB(ServletContext context) { |
|
22 |
String driverClassName = context.getInitParameter("jdbc.driverClassName"); |
|
23 |
String url = context.getInitParameter("jdbc.url"); |
|
24 |
String username = context.getInitParameter("jdbc.username"); |
|
25 |
String password = context.getInitParameter("jdbc.password"); |
|
25 | 26 |
|
26 |
String dbUrl = context.getInitParameter("DbUrl"); |
|
27 |
String dbName = context.getInitParameter("DbName"); |
|
28 |
String dbUser = context.getInitParameter("DbUser"); |
|
29 |
String dbPsw = context.getInitParameter("DbPsw"); |
|
30 |
|
|
31 |
conn = DriverManager.getConnection(dbUrl + dbName + "?user=" + dbUser + "&password=" + dbPsw + "&useUnicode=true&characterEncoding=UTF-8"); |
|
32 |
conn.setAutoCommit(true); |
|
33 |
} catch (ClassNotFoundException | SQLException e) { |
|
34 |
e.printStackTrace(); |
|
35 |
} |
|
27 |
try { |
|
28 |
Class.forName(driverClassName); |
|
29 |
connection = DriverManager.getConnection(url, username, password); |
|
30 |
connection.setAutoCommit(true); |
|
31 |
} catch (ClassNotFoundException | SQLException e) { |
|
32 |
e.printStackTrace(); |
|
33 |
} |
|
36 | 34 |
} |
37 | 35 |
|
38 | 36 |
/** |
... | ... | |
42 | 40 |
* @param returnGeneratedKeys true - RETURN_GENERATED_KEYS flag is set, false - no flag is set |
43 | 41 |
*/ |
44 | 42 |
PreparedStatement getPreparedStatement(String query, boolean returnGeneratedKeys) throws SQLException { |
45 |
if(returnGeneratedKeys) |
|
46 |
return conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); |
|
47 |
else |
|
48 |
return conn.prepareStatement(query); |
|
43 |
if (returnGeneratedKeys) { |
|
44 |
return connection.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); |
|
45 |
} else { |
|
46 |
return connection.prepareStatement(query); |
|
47 |
} |
|
49 | 48 |
} |
50 | 49 |
|
51 | 50 |
/** |
... | ... | |
54 | 53 |
* @param preparedStatement prepared statement with query and set all parameters. |
55 | 54 |
* @return ResultSet - data from database. |
56 | 55 |
*/ |
57 |
ResultSet executeQuery(PreparedStatement preparedStatement){ |
|
56 |
ResultSet executeQuery(PreparedStatement preparedStatement) {
|
|
58 | 57 |
try { |
59 | 58 |
preparedStatement.execute(); |
60 | 59 |
return preparedStatement.getResultSet(); |
... | ... | |
69 | 68 |
* @param preparedStatement prepared statement with query and set all parameters. |
70 | 69 |
* @return ResultSet - generated keys or null. |
71 | 70 |
*/ |
72 |
ResultSet executeUpdate(PreparedStatement preparedStatement){ |
|
71 |
ResultSet executeUpdate(PreparedStatement preparedStatement) {
|
|
73 | 72 |
try { |
74 | 73 |
preparedStatement.executeUpdate(); |
75 | 74 |
return preparedStatement.getGeneratedKeys(); |
... | ... | |
84 | 83 |
* @param sql - completed sql query |
85 | 84 |
* @return ResultSet - data from database |
86 | 85 |
*/ |
87 |
ResultSet executeQuery(String sql){ |
|
88 |
try{ |
|
89 |
Statement stat = conn.createStatement(); |
|
86 |
ResultSet executeQuery(String sql) {
|
|
87 |
try {
|
|
88 |
Statement stat = connection.createStatement();
|
|
90 | 89 |
stat.execute(sql); |
91 | 90 |
return stat.getResultSet(); |
92 | 91 |
|
93 |
}catch(SQLException | NullPointerException e){
|
|
92 |
} catch(SQLException | NullPointerException e) {
|
|
94 | 93 |
e.printStackTrace(); |
95 | 94 |
} |
96 | 95 |
return null; |
... | ... | |
102 | 101 |
* @return count of affected rows or -1 on SQLException and -2 on NullPointerException |
103 | 102 |
* */ |
104 | 103 |
int executeStatement(PreparedStatement preparedStatement) { |
105 |
|
|
106 |
try{ |
|
104 |
try { |
|
107 | 105 |
return preparedStatement.executeUpdate(); |
108 |
}catch(SQLException e){ |
|
109 |
e.printStackTrace(); |
|
110 |
return -1; |
|
111 |
}catch (NullPointerException e){ |
|
112 |
e.printStackTrace(); |
|
113 |
return -2; |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
/** |
|
119 |
* Method execute sql query. Sql query can be INSERT, DELETE, UPDATE |
|
120 |
* |
|
121 |
* @return count of affected rows or -1 on SQLException and -2 on NullPointerException |
|
122 |
* */ |
|
123 |
int executeStatement(String sql) { |
|
124 |
|
|
125 |
try{ |
|
126 |
Statement stat = conn.createStatement(); |
|
127 |
return stat.executeUpdate(sql); |
|
128 |
}catch(SQLException e){ |
|
106 |
} catch(SQLException e) { |
|
129 | 107 |
e.printStackTrace(); |
130 | 108 |
return -1; |
131 |
}catch (NullPointerException e){
|
|
109 |
} catch (NullPointerException e) {
|
|
132 | 110 |
e.printStackTrace(); |
133 | 111 |
return -2; |
134 | 112 |
} |
sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java | ||
---|---|---|
171 | 171 |
* Method deletes diagram from database. |
172 | 172 |
*/ |
173 | 173 |
public void delete() { |
174 |
if (id == 0) return; |
|
174 |
if (this.id == 0) return;
|
|
175 | 175 |
|
176 |
String qy = "DELETE FROM diagram WHERE id = '" + this.id + "' LIMIT 1"; |
|
177 |
db.executeStatement(qy); |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Method change graph_json in diagram and return number of affected rows in database. |
|
182 |
* |
|
183 |
* @param graphJson json of diagram |
|
184 |
* @return number of affected rows in database |
|
185 |
*/ |
|
186 |
public int updateGraphJson(String graphJson){ |
|
187 |
if(this.id == 0) return 0; |
|
188 |
|
|
189 |
String qy = "UPDATE diagram SET graph_json = ? WHERE id = ?"; |
|
176 |
String qy = "DELETE FROM diagram WHERE id = ? LIMIT 1"; |
|
190 | 177 |
|
191 | 178 |
try { |
192 | 179 |
PreparedStatement pst = db.getPreparedStatement(qy, false); |
193 |
pst.setString(1, graphJson); |
|
194 |
pst.setInt(2, this.id); |
|
195 |
return db.executeStatement(pst); |
|
180 |
pst.setInt(1, this.id); |
|
181 |
db.executeStatement(pst); |
|
196 | 182 |
|
197 | 183 |
} catch (SQLException e) { |
198 | 184 |
e.printStackTrace(); |
199 | 185 |
} |
200 |
return 0; |
|
201 | 186 |
} |
202 | 187 |
|
203 | 188 |
/** |
sources/src/main/webapp/WEB-INF/web.xml | ||
---|---|---|
4 | 4 |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" |
5 | 5 |
version="3.0"> |
6 | 6 |
<context-param> |
7 |
<param-name>DbUrl</param-name>
|
|
8 |
<param-value>jdbc:mysql://127.0.0.1/</param-value>
|
|
7 |
<param-name>jdbc.driverClassName</param-name>
|
|
8 |
<param-value>com.mysql.jdbc.Driver</param-value>
|
|
9 | 9 |
</context-param> |
10 | 10 |
<context-param> |
11 |
<param-name>DbName</param-name>
|
|
12 |
<param-value>visualization_tool</param-value>
|
|
11 |
<param-name>jdbc.url</param-name>
|
|
12 |
<param-value>jdbc:mysql://localhost/visualization_tool?useUnicode=true&characterEncoding=UTF-8</param-value>
|
|
13 | 13 |
</context-param> |
14 | 14 |
<context-param> |
15 |
<param-name>DbUser</param-name>
|
|
15 |
<param-name>jdbc.username</param-name>
|
|
16 | 16 |
<param-value>admin</param-value> |
17 | 17 |
</context-param> |
18 | 18 |
<context-param> |
19 |
<param-name>DbPsw</param-name>
|
|
19 |
<param-name>jdbc.password</param-name>
|
|
20 | 20 |
<param-value>admin</param-value> |
21 | 21 |
</context-param> |
22 | 22 |
<context-param> |
23 |
<param-name>HOME_URL</param-name> |
|
24 |
<param-value>http://localhost:8080/imiger/</param-value> |
|
25 |
</context-param> |
|
26 |
<context-param> |
|
27 |
<param-name>configLocation</param-name> |
|
28 |
<param-value>C:\Users\Tomas\Sources\swi\IMiGEr\config</param-value> |
|
23 |
<param-name>APP_NAME</param-name> |
|
24 |
<param-value>IMiGEr</param-value> |
|
29 | 25 |
</context-param> |
30 |
|
|
31 | 26 |
<context-param> |
32 |
<param-name>minInterfaceDiameter</param-name> |
|
33 |
<param-value>20</param-value> |
|
34 |
</context-param> |
|
35 |
<context-param> |
|
36 |
<param-name>maxInterfaceDiameter</param-name> |
|
37 |
<param-value>40</param-value> |
|
27 |
<param-name>APP_HOME_URL</param-name> |
|
28 |
<param-value>http://localhost:8080/imiger/</param-value> |
|
38 | 29 |
</context-param> |
39 | 30 |
|
40 | 31 |
<!-- |
sources/src/main/webapp/showGraph.jsp | ||
---|---|---|
1 | 1 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> |
2 | 2 |
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> |
3 | 3 |
|
4 |
<c:set var="APP_NAME" value="IMiGEr"/>
|
|
5 |
<c:set var="APP_HOME_URL" value="${initParam.HOME_URL}"/> |
|
4 |
<c:set var="APP_NAME" value="${initParam.APP_NAME}"/>
|
|
5 |
<c:set var="APP_HOME_URL" value="${initParam.APP_HOME_URL}"/>
|
|
6 | 6 |
<c:set var="isLoggedIn" value="${sessionScope.isLoggedIn}"/> |
7 | 7 |
<c:set var="user" value="${sessionScope.user}"/> |
8 | 8 |
|
... | ... | |
91 | 91 |
|
92 | 92 |
<script src="js/constants.js"></script> |
93 | 93 |
|
94 |
<title>IMiGEr</title>
|
|
94 |
<title>${APP_NAME}</title>
|
|
95 | 95 |
</head> |
96 | 96 |
|
97 | 97 |
<body class="${isLoggedIn ? 'loggedIn' : 'loggedOut'}"> |
sources/src/main/webapp/uploadFiles.jsp | ||
---|---|---|
1 | 1 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> |
2 | 2 |
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> |
3 | 3 |
|
4 |
<c:set var="APP_NAME" value="IMiGEr"/>
|
|
5 |
<c:set var="APP_HOME_URL" value="${initParam.HOME_URL}"/> |
|
4 |
<c:set var="APP_NAME" value="${initParam.APP_NAME}"/>
|
|
5 |
<c:set var="APP_HOME_URL" value="${initParam.APP_HOME_URL}"/>
|
|
6 | 6 |
<c:set var="isLoggedIn" value="${sessionScope.isLoggedIn}"/> |
7 | 7 |
<c:set var="user" value="${sessionScope.user}"/> |
8 | 8 |
|
... | ... | |
86 | 86 |
<ul id="privateDiagramList"> |
87 | 87 |
<c:forEach items="${diagramsPrivate}" var="diagram"> |
88 | 88 |
<li> |
89 |
<a href="${HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a> |
|
89 |
<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
|
|
90 | 90 |
|
91 | 91 |
<button class="button remove-diagram-button" data-id="${diagram.id}" data-name="${diagram.name}"> |
92 | 92 |
<img src="images/button_cancel.png" alt="odstranit"> |
... | ... | |
102 | 102 |
<ul id="publicDiagramList"> |
103 | 103 |
<c:forEach items="${diagramsPublic}" var="diagram"> |
104 | 104 |
<li> |
105 |
<a href="${HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a> |
|
105 |
<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
|
|
106 | 106 |
</li> |
107 | 107 |
</c:forEach> |
108 | 108 |
</ul> |
Také k dispozici: Unified diff
clean up web.xml servlet context parameters