Formatting
This commit is contained in:
parent
dae126f721
commit
66ff5c2efd
6 changed files with 242 additions and 224 deletions
|
@ -22,7 +22,8 @@ public class Main {
|
||||||
private static File getRootFolder() {
|
private static File getRootFolder() {
|
||||||
try {
|
try {
|
||||||
File root;
|
File root;
|
||||||
String runningJarPath = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath().replaceAll("\\\\", "/");
|
String runningJarPath = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()
|
||||||
|
.replaceAll("\\\\", "/");
|
||||||
int lastIndexOf = runningJarPath.lastIndexOf("/target/");
|
int lastIndexOf = runningJarPath.lastIndexOf("/target/");
|
||||||
if (lastIndexOf < 0) {
|
if (lastIndexOf < 0) {
|
||||||
root = new File("");
|
root = new File("");
|
||||||
|
@ -79,7 +80,8 @@ public class Main {
|
||||||
}
|
}
|
||||||
StandardContext ctx = (StandardContext) tomcat.addWebapp("", webContentFolder.getAbsolutePath());
|
StandardContext ctx = (StandardContext) tomcat.addWebapp("", webContentFolder.getAbsolutePath());
|
||||||
ctx.setDocBase(webContentFolder.getAbsolutePath() + File.separator + "static");
|
ctx.setDocBase(webContentFolder.getAbsolutePath() + File.separator + "static");
|
||||||
//Set execution independent of current thread context classloader (compatibility with exec:java mojo)
|
// Set execution independent of current thread context classloader
|
||||||
|
// (compatibility with exec:java mojo)
|
||||||
ctx.setParentClassLoader(Main.class.getClassLoader());
|
ctx.setParentClassLoader(Main.class.getClassLoader());
|
||||||
|
|
||||||
System.out.println("configuring app with basedir: " + webContentFolder.getAbsolutePath());
|
System.out.println("configuring app with basedir: " + webContentFolder.getAbsolutePath());
|
||||||
|
@ -91,13 +93,16 @@ public class Main {
|
||||||
|
|
||||||
WebResourceSet resourceSet;
|
WebResourceSet resourceSet;
|
||||||
if (additionWebInfClassesFolder.exists()) {
|
if (additionWebInfClassesFolder.exists()) {
|
||||||
resourceSet = new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClassesFolder.getAbsolutePath(), "/");
|
resourceSet = new DirResourceSet(resources, "/WEB-INF/classes",
|
||||||
System.out.println("loading WEB-INF resources from as '" + additionWebInfClassesFolder.getAbsolutePath() + "'");
|
additionWebInfClassesFolder.getAbsolutePath(), "/");
|
||||||
|
System.out.println(
|
||||||
|
"loading WEB-INF resources from as '" + additionWebInfClassesFolder.getAbsolutePath() + "'");
|
||||||
} else {
|
} else {
|
||||||
resourceSet = new EmptyResourceSet(resources);
|
resourceSet = new EmptyResourceSet(resources);
|
||||||
}
|
}
|
||||||
resources.addPreResources(resourceSet);
|
resources.addPreResources(resourceSet);
|
||||||
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/jsp", webContentFolder.getAbsolutePath() + File.separator + "jsp", "/"));
|
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/jsp",
|
||||||
|
webContentFolder.getAbsolutePath() + File.separator + "jsp", "/"));
|
||||||
ctx.setResources(resources);
|
ctx.setResources(resources);
|
||||||
tomcat.getConnector();
|
tomcat.getConnector();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class HelloJspViewModel {
|
public class HelloJspViewModel {
|
||||||
private final List<Integer> data;
|
private final List<Integer> data;
|
||||||
|
|
||||||
public HelloJspViewModel(List<Integer> data) {
|
public HelloJspViewModel(List<Integer> data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import javax.servlet.http.HttpSession;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servlet implementation class Survey.
|
* Servlet implementation class Survey.
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +23,6 @@ public class Dump extends HttpServlet {
|
||||||
|
|
||||||
private FormGenerator formGenerator = new FormGenerator();
|
private FormGenerator formGenerator = new FormGenerator();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -33,24 +30,30 @@ public class Dump extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks first if name includes characters (i.e. is longer than zero characters) and then
|
* Checks first if name includes characters (i.e. is longer than zero
|
||||||
|
* characters) and then
|
||||||
* if so if the name is possible to add to
|
* if so if the name is possible to add to
|
||||||
* the database. It is not possible to add an already existing name to the database.
|
* the database. It is not possible to add an already existing name to the
|
||||||
|
* database.
|
||||||
*/
|
*/
|
||||||
boolean nameOk(Database db, String name) {
|
boolean nameOk(Database db, String name) {
|
||||||
boolean result = !name.equals("");
|
boolean result = !name.equals("");
|
||||||
if (result) result = db.addName(name);
|
if (result)
|
||||||
|
result = db.addName(name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean answerOk(Database db, String answerOne, String answerTwo, String answerThree, String answerFour) {
|
boolean answerOk(Database db, String answerOne, String answerTwo, String answerThree, String answerFour) {
|
||||||
boolean result = !answerOne.equals("") && !answerTwo.equals("") && !answerThree.equals("") && !answerFour.equals("");
|
boolean result = !answerOne.equals("") && !answerTwo.equals("") && !answerThree.equals("")
|
||||||
if(result) result = db.addAnswer(answerFour, answerOne, answerTwo, answerThree, answerFour);
|
&& !answerFour.equals("");
|
||||||
|
if (result)
|
||||||
|
result = db.addAnswer(answerFour, answerOne, answerTwo, answerThree, answerFour);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks if a value entered as answer is OK. Answers should be between 1 and 10.
|
* Checks if a value entered as answer is OK. Answers should be between 1 and
|
||||||
|
* 10.
|
||||||
*/
|
*/
|
||||||
boolean valueOk(int value) {
|
boolean valueOk(int value) {
|
||||||
return value > 0 && value < 11;
|
return value > 0 && value < 11;
|
||||||
|
@ -61,10 +64,13 @@ public class Dump extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
||||||
|
* response)
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
// Try with resources to create a connection, will ensure close is always called.
|
throws ServletException, IOException {
|
||||||
|
// Try with resources to create a connection, will ensure close is always
|
||||||
|
// called.
|
||||||
try (Database db = new Database()) {
|
try (Database db = new Database()) {
|
||||||
|
|
||||||
// Get the session
|
// Get the session
|
||||||
|
@ -104,9 +110,11 @@ public class Dump extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
|
||||||
|
* response)
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package servlet;
|
package servlet;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This class provides forms to be displayed to the user
|
* This class provides forms to be displayed to the user
|
||||||
*/
|
*/
|
||||||
public class FormGenerator {
|
public class FormGenerator {
|
||||||
|
|
||||||
|
|
||||||
private String formElement(String par) {
|
private String formElement(String par) {
|
||||||
return '"' + par + '"';
|
return '"' + par + '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Form for requesting user name
|
* Form for requesting user name
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,8 +10,6 @@ import javax.servlet.http.HttpSession;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servlet implementation class Survey.
|
* Servlet implementation class Survey.
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +24,6 @@ public class Survey extends HttpServlet {
|
||||||
|
|
||||||
private FormGenerator formGenerator = new FormGenerator();
|
private FormGenerator formGenerator = new FormGenerator();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -34,9 +31,11 @@ public class Survey extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks first if name includes characters (i.e. is longer than zero characters) and then
|
* Checks first if name includes characters (i.e. is longer than zero
|
||||||
|
* characters) and then
|
||||||
* if so if the name is possible to add to
|
* if so if the name is possible to add to
|
||||||
* the database. It is not possible to add an already existing name to the database.
|
* the database. It is not possible to add an already existing name to the
|
||||||
|
* database.
|
||||||
*/
|
*/
|
||||||
boolean nameOk(Database db, String name) {
|
boolean nameOk(Database db, String name) {
|
||||||
boolean result = !name.equals("");
|
boolean result = !name.equals("");
|
||||||
|
@ -46,17 +45,21 @@ public class Survey extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks if a value entered as answer is OK. Answers should be between 1 and 10.
|
* Checks if a value entered as answer is OK. Answers should be between 1 and
|
||||||
|
* 10.
|
||||||
*/
|
*/
|
||||||
boolean valueOk(int value) {
|
boolean valueOk(int value) {
|
||||||
return value > 0 && value < 11;
|
return value > 0 && value < 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
||||||
|
* response)
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
// Try with resources to create a connection, will ensure close is always called.
|
throws ServletException, IOException {
|
||||||
|
// Try with resources to create a connection, will ensure close is always
|
||||||
|
// called.
|
||||||
try (Database db = new Database()) {
|
try (Database db = new Database()) {
|
||||||
|
|
||||||
// Get the session
|
// Get the session
|
||||||
|
@ -89,12 +92,12 @@ public class Survey extends HttpServlet {
|
||||||
session.setAttribute("name", name); // save the name in the session
|
session.setAttribute("name", name); // save the name in the session
|
||||||
state = NEED_PROJECT_INFO;
|
state = NEED_PROJECT_INFO;
|
||||||
out.println(formGenerator.projectDetailsRequestForm());
|
out.println(formGenerator.projectDetailsRequestForm());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out.println("That was not a valid name. Maybe it is already taken by someone else.");
|
out.println("That was not a valid name. Maybe it is already taken by someone else.");
|
||||||
out.println(formGenerator.nameRequestForm());
|
out.println(formGenerator.nameRequestForm());
|
||||||
}
|
}
|
||||||
}else{ // name was null, probably because no form has been filled out yet. Display form.
|
} else { // name was null, probably because no form has been filled out yet. Display
|
||||||
|
// form.
|
||||||
out.println(formGenerator.nameRequestForm());
|
out.println(formGenerator.nameRequestForm());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -166,9 +169,11 @@ public class Survey extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
|
||||||
|
* response)
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue