commit 51ce052a8740207be67f996a9caa5e3209aca4b1
Author: Pavel Fidranský <fidransky@outlook.com>
Date:   Sun Nov 11 16:53:28 2018 +0100

    clean up web.xml servlet context parameters

diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java
index 49cd2bd..224cea9 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java
@@ -55,7 +55,7 @@ public class UploadFiles extends BaseServlet {
         } else {
             request.getSession().setAttribute("json_graph", jsonData.get("file"));
             request.getSession().setAttribute("json_graph_type", jsonData.get("jsonFileFormat"));
-            response.sendRedirect(getServletContext().getInitParameter("HOME_URL") + "graph");
+            response.sendRedirect(getServletContext().getInitParameter("APP_HOME_URL") + "graph");
         }
     }
 }
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
index 69b3d4f..630f6f5 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
@@ -13,26 +13,24 @@ import javax.servlet.ServletContext;
  */
 
 public class DB {
-	private Connection conn = null;
+	private Connection connection;
 	
 	/**
-	 * Constructor opens connection do database. Access data must be save in ServletContext as InitParameter( DbUrl, DbName, DbUser, DbPsw ).
+	 * Constructor opens connection do database. Access credentials must be stored in ServletContext as InitParameter.
 	 */
-	public DB(ServletContext context){	
-		    
-			try {
-				Class.forName("com.mysql.jdbc.Driver");
+	public DB(ServletContext context) {
+		String driverClassName = context.getInitParameter("jdbc.driverClassName");
+		String url = context.getInitParameter("jdbc.url");
+		String username = context.getInitParameter("jdbc.username");
+		String password = context.getInitParameter("jdbc.password");
 
-				String dbUrl = context.getInitParameter("DbUrl");
-				String dbName = context.getInitParameter("DbName");
-				String dbUser = context.getInitParameter("DbUser");
-				String dbPsw = context.getInitParameter("DbPsw");
-
-				conn = DriverManager.getConnection(dbUrl + dbName + "?user=" + dbUser + "&password=" + dbPsw + "&useUnicode=true&characterEncoding=UTF-8");
-				conn.setAutoCommit(true);
-			} catch (ClassNotFoundException | SQLException e) {
-				e.printStackTrace();
-			}
+		try {
+			Class.forName(driverClassName);
+			connection = DriverManager.getConnection(url, username, password);
+			connection.setAutoCommit(true);
+		} catch (ClassNotFoundException | SQLException e) {
+			e.printStackTrace();
+		}
 	}
 
 	/**
@@ -42,10 +40,11 @@ public class DB {
 	 * @param returnGeneratedKeys true - RETURN_GENERATED_KEYS flag is set, false - no flag is set
 	 */
 	PreparedStatement getPreparedStatement(String query, boolean returnGeneratedKeys) throws SQLException {
-		if(returnGeneratedKeys)
-			return conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
-		else
-			return conn.prepareStatement(query);
+		if (returnGeneratedKeys) {
+			return connection.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
+		} else {
+			return connection.prepareStatement(query);
+		}
 	}
 
 	/**
@@ -54,7 +53,7 @@ public class DB {
 	 * @param preparedStatement prepared statement with query and set all parameters.
 	 * @return ResultSet - data from database.
 	 */
-	ResultSet executeQuery(PreparedStatement preparedStatement){
+	ResultSet executeQuery(PreparedStatement preparedStatement) {
 		try {
 			preparedStatement.execute();
 			return preparedStatement.getResultSet();
@@ -69,7 +68,7 @@ public class DB {
 	 * @param preparedStatement prepared statement with query and set all parameters.
 	 * @return ResultSet - generated keys or null.
 	 */
-	ResultSet executeUpdate(PreparedStatement preparedStatement){
+	ResultSet executeUpdate(PreparedStatement preparedStatement) {
 		try {
 			preparedStatement.executeUpdate();
 			return preparedStatement.getGeneratedKeys();
@@ -84,13 +83,13 @@ public class DB {
 	 * @param sql - completed sql query
 	 * @return ResultSet - data from database
 	 */
-	ResultSet executeQuery(String sql){
-		try{
-			Statement stat = conn.createStatement();
+	ResultSet executeQuery(String sql) {
+		try {
+			Statement stat = connection.createStatement();
 			stat.execute(sql);
 			return stat.getResultSet();
 
-		}catch(SQLException | NullPointerException e){
+		} catch(SQLException | NullPointerException e) {
 			e.printStackTrace();
 		}
 		return null;
@@ -102,33 +101,12 @@ public class DB {
 	 * @return count of affected rows or -1 on SQLException and -2 on NullPointerException
 	 * */
 	int executeStatement(PreparedStatement preparedStatement) {
-
-		try{
+		try {
 			return preparedStatement.executeUpdate();
-		}catch(SQLException e){
-			e.printStackTrace();
-			return -1;
-		}catch (NullPointerException e){
-			e.printStackTrace();
-			return -2;
-		}
-	}
-
-
-	/**
-	 * Method execute sql query. Sql query can be INSERT, DELETE, UPDATE
-	 *
-	 * @return count of affected rows or -1 on SQLException and -2 on NullPointerException
-	 * */
-	int executeStatement(String sql) {
-
-		try{
-			Statement stat = conn.createStatement();
-			return stat.executeUpdate(sql);
-		}catch(SQLException e){
+		} catch(SQLException e) {
 			e.printStackTrace();
 			return -1;
-		}catch (NullPointerException e){
+		} catch (NullPointerException e) {
 			e.printStackTrace();
 			return -2;
 		}
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
index 6b4f0b5..cd587fb 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
@@ -171,33 +171,18 @@ public class Diagram {
      * Method deletes diagram from database.
      */
     public void delete() {
-        if (id == 0) return;
+        if (this.id == 0) return;
 
-        String qy = "DELETE FROM diagram WHERE id = '" + this.id + "' LIMIT 1";
-        db.executeStatement(qy);
-    }
-
-    /**
-     * Method change graph_json in diagram and return number of affected rows in database.
-     *
-     * @param graphJson json of diagram
-     * @return number of affected rows in database
-     */
-    public int updateGraphJson(String graphJson){
-        if(this.id == 0) return 0;
-
-        String qy = "UPDATE diagram SET graph_json = ? WHERE id = ?";
+        String qy = "DELETE FROM diagram WHERE id = ? LIMIT 1";
 
         try {
             PreparedStatement pst = db.getPreparedStatement(qy, false);
-            pst.setString(1, graphJson);
-            pst.setInt(2, this.id);
-            return db.executeStatement(pst);
+            pst.setInt(1, this.id);
+            db.executeStatement(pst);
 
         } catch (SQLException e) {
             e.printStackTrace();
         }
-        return 0;
     }
 
     /**
diff --git a/sources/src/main/webapp/WEB-INF/web.xml b/sources/src/main/webapp/WEB-INF/web.xml
index 642a3e9..831086b 100644
--- a/sources/src/main/webapp/WEB-INF/web.xml
+++ b/sources/src/main/webapp/WEB-INF/web.xml
@@ -4,37 +4,28 @@
 		 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 		 version="3.0">
 	<context-param>
-		<param-name>DbUrl</param-name>
-		<param-value>jdbc:mysql://127.0.0.1/</param-value>
+		<param-name>jdbc.driverClassName</param-name>
+		<param-value>com.mysql.jdbc.Driver</param-value>
 	</context-param>
 	<context-param>
-		<param-name>DbName</param-name>
-		<param-value>visualization_tool</param-value>
+		<param-name>jdbc.url</param-name>
+		<param-value>jdbc:mysql://localhost/visualization_tool?useUnicode=true&amp;characterEncoding=UTF-8</param-value>
 	</context-param>
 	<context-param>
-		<param-name>DbUser</param-name>
+		<param-name>jdbc.username</param-name>
 		<param-value>admin</param-value>
 	</context-param>
 	<context-param>
-		<param-name>DbPsw</param-name>
+		<param-name>jdbc.password</param-name>
 		<param-value>admin</param-value>
 	</context-param>
 	<context-param>
-		<param-name>HOME_URL</param-name>
-		<param-value>http://localhost:8080/imiger/</param-value>
-	</context-param>
-	<context-param>
-		<param-name>configLocation</param-name>
-		<param-value>C:\Users\Tomas\Sources\swi\IMiGEr\config</param-value>
+		<param-name>APP_NAME</param-name>
+		<param-value>IMiGEr</param-value>
 	</context-param>
-
 	<context-param>
-		<param-name>minInterfaceDiameter</param-name>
-		<param-value>20</param-value>
-	</context-param>
-	<context-param>
-		<param-name>maxInterfaceDiameter</param-name>
-		<param-value>40</param-value>
+		<param-name>APP_HOME_URL</param-name>
+		<param-value>http://localhost:8080/imiger/</param-value>
 	</context-param>
 
 	<!--
diff --git a/sources/src/main/webapp/showGraph.jsp b/sources/src/main/webapp/showGraph.jsp
index b277a0e..469a619 100644
--- a/sources/src/main/webapp/showGraph.jsp
+++ b/sources/src/main/webapp/showGraph.jsp
@@ -1,8 +1,8 @@
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 
-<c:set var="APP_NAME" value="IMiGEr"/>
-<c:set var="APP_HOME_URL" value="${initParam.HOME_URL}"/>
+<c:set var="APP_NAME" value="${initParam.APP_NAME}"/>
+<c:set var="APP_HOME_URL" value="${initParam.APP_HOME_URL}"/>
 <c:set var="isLoggedIn" value="${sessionScope.isLoggedIn}"/>
 <c:set var="user" value="${sessionScope.user}"/>
 
@@ -91,7 +91,7 @@
 
 		<script src="js/constants.js"></script>
 
-		<title>IMiGEr</title>
+		<title>${APP_NAME}</title>
 	</head>
 
 	<body class="${isLoggedIn ? 'loggedIn' : 'loggedOut'}">
diff --git a/sources/src/main/webapp/uploadFiles.jsp b/sources/src/main/webapp/uploadFiles.jsp
index 8f226fe..3ec9b7a 100644
--- a/sources/src/main/webapp/uploadFiles.jsp
+++ b/sources/src/main/webapp/uploadFiles.jsp
@@ -1,8 +1,8 @@
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 
-<c:set var="APP_NAME" value="IMiGEr"/>
-<c:set var="APP_HOME_URL" value="${initParam.HOME_URL}"/>
+<c:set var="APP_NAME" value="${initParam.APP_NAME}"/>
+<c:set var="APP_HOME_URL" value="${initParam.APP_HOME_URL}"/>
 <c:set var="isLoggedIn" value="${sessionScope.isLoggedIn}"/>
 <c:set var="user" value="${sessionScope.user}"/>
 
@@ -86,7 +86,7 @@
 				<ul id="privateDiagramList">
 					<c:forEach items="${diagramsPrivate}" var="diagram">
 						<li>
-							<a href="${HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
+							<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
 
 							<button class="button remove-diagram-button" data-id="${diagram.id}" data-name="${diagram.name}">
 								<img src="images/button_cancel.png" alt="odstranit">
@@ -102,7 +102,7 @@
 				<ul id="publicDiagramList">
 					<c:forEach items="${diagramsPublic}" var="diagram">
 						<li>
-							<a href="${HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
+							<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a>
 						</li>
 					</c:forEach>
 				</ul>
