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() {
|
||||
try {
|
||||
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/");
|
||||
if (lastIndexOf < 0) {
|
||||
root = new File("");
|
||||
|
@ -79,7 +80,8 @@ public class Main {
|
|||
}
|
||||
StandardContext ctx = (StandardContext) tomcat.addWebapp("", webContentFolder.getAbsolutePath());
|
||||
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());
|
||||
|
||||
System.out.println("configuring app with basedir: " + webContentFolder.getAbsolutePath());
|
||||
|
@ -91,13 +93,16 @@ public class Main {
|
|||
|
||||
WebResourceSet resourceSet;
|
||||
if (additionWebInfClassesFolder.exists()) {
|
||||
resourceSet = new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClassesFolder.getAbsolutePath(), "/");
|
||||
System.out.println("loading WEB-INF resources from as '" + additionWebInfClassesFolder.getAbsolutePath() + "'");
|
||||
resourceSet = new DirResourceSet(resources, "/WEB-INF/classes",
|
||||
additionWebInfClassesFolder.getAbsolutePath(), "/");
|
||||
System.out.println(
|
||||
"loading WEB-INF resources from as '" + additionWebInfClassesFolder.getAbsolutePath() + "'");
|
||||
} else {
|
||||
resourceSet = new EmptyResourceSet(resources);
|
||||
}
|
||||
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);
|
||||
tomcat.getConnector();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
public class HelloJspViewModel {
|
||||
private final List<Integer> data;
|
||||
|
||||
public HelloJspViewModel(List<Integer> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import javax.servlet.http.HttpSession;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class Survey.
|
||||
*/
|
||||
|
@ -25,7 +23,6 @@ public class Dump extends HttpServlet {
|
|||
|
||||
private FormGenerator formGenerator = new FormGenerator();
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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 result = !name.equals("");
|
||||
if (result) result = db.addName(name);
|
||||
if (result)
|
||||
result = db.addName(name);
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean answerOk(Database db, String answerOne, String answerTwo, String answerThree, String answerFour) {
|
||||
boolean result = !answerOne.equals("") && !answerTwo.equals("") && !answerThree.equals("") && !answerFour.equals("");
|
||||
if(result) result = db.addAnswer(answerFour, answerOne, answerTwo, answerThree, answerFour);
|
||||
boolean result = !answerOne.equals("") && !answerTwo.equals("") && !answerThree.equals("")
|
||||
&& !answerFour.equals("");
|
||||
if (result)
|
||||
result = db.addAnswer(answerFour, answerOne, answerTwo, answerThree, answerFour);
|
||||
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) {
|
||||
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 {
|
||||
// Try with resources to create a connection, will ensure close is always called.
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// Try with resources to create a connection, will ensure close is always
|
||||
// called.
|
||||
try (Database db = new Database()) {
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package servlet;
|
||||
|
||||
/*
|
||||
* This class provides forms to be displayed to the user
|
||||
*/
|
||||
public class FormGenerator {
|
||||
|
||||
|
||||
private String formElement(String par) {
|
||||
return '"' + par + '"';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Form for requesting user name
|
||||
*/
|
||||
|
|
|
@ -10,8 +10,6 @@ import javax.servlet.http.HttpSession;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class Survey.
|
||||
*/
|
||||
|
@ -26,7 +24,6 @@ public class Survey extends HttpServlet {
|
|||
|
||||
private FormGenerator formGenerator = new FormGenerator();
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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 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) {
|
||||
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 {
|
||||
// Try with resources to create a connection, will ensure close is always called.
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// Try with resources to create a connection, will ensure close is always
|
||||
// called.
|
||||
try (Database db = new Database()) {
|
||||
|
||||
// Get the session
|
||||
|
@ -89,12 +92,12 @@ public class Survey extends HttpServlet {
|
|||
session.setAttribute("name", name); // save the name in the session
|
||||
state = NEED_PROJECT_INFO;
|
||||
out.println(formGenerator.projectDetailsRequestForm());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out.println("That was not a valid name. Maybe it is already taken by someone else.");
|
||||
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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue