diff --git a/pom.xml b/pom.xml index 1b1d200648d81d9de1f61b5a18735c66451573ab..2ec06051d529664290daa9680098461e8a0e4e4d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>nl.utwente.di</groupId> <artifactId>bookQuote</artifactId> diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9604c915d7b8d2e3c47081ab1bfbca343bb98a7e Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b3d3e6a890c419ff4ab0116838ad01b78e6aab14 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1f7f65d64d1006adb887faa93a5b8f93a5e321a4 Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/nl/.DS_Store b/src/main/java/nl/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6fdf55269a335fc97cdc0407f8750abebf7f9d44 Binary files /dev/null and b/src/main/java/nl/.DS_Store differ diff --git a/src/main/java/nl/utwente/.DS_Store b/src/main/java/nl/utwente/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f5b25add2ed564d3cc1ce506e4997c735a2b1b27 Binary files /dev/null and b/src/main/java/nl/utwente/.DS_Store differ diff --git a/src/main/java/nl/utwente/di/.DS_Store b/src/main/java/nl/utwente/di/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b78fbe517ba739f21a6f316098c5ce346f5b9188 Binary files /dev/null and b/src/main/java/nl/utwente/di/.DS_Store differ diff --git a/src/main/java/nl/utwente/di/bookQuote/.DS_Store b/src/main/java/nl/utwente/di/bookQuote/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/src/main/java/nl/utwente/di/bookQuote/.DS_Store differ diff --git a/src/main/java/nl/utwente/di/bookQuote/BookQuote.java b/src/main/java/nl/utwente/di/bookQuote/BookQuote.java new file mode 100644 index 0000000000000000000000000000000000000000..1fd7c12b572ae32ac59e2ad8d90fed28a37141ac --- /dev/null +++ b/src/main/java/nl/utwente/di/bookQuote/BookQuote.java @@ -0,0 +1,45 @@ +package nl.utwente.di.bookQuote; + +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; + +/** Example of a Servlet that gets an ISBN number and returns the book price + */ + +public class BookQuote extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; + private Quoter quoter; + + public void init() throws ServletException { + quoter = new Quoter(); + } + + public void doGet(HttpServletRequest request, + HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + String docType = + "<!DOCTYPE HTML>\n"; + String title = "Book Quote"; + out.println(docType + + "<HTML>\n" + + "<HEAD><TITLE>" + title + "</TITLE>" + + "<LINK REL=STYLESHEET HREF=\"styles.css\">" + + "</HEAD>\n" + + "<BODY BGCOLOR=\"#FDF5E6\">\n" + + "<H1>" + title + "</H1>\n" + + " <P>ISBN number: " + + request.getParameter("isbn") + "\n" + + " <P>Price: " + + Double.toString(quoter.getBookPrice(request.getParameter("isbn"))) + + "</BODY></HTML>"); + } + + +} diff --git a/src/main/java/nl/utwente/di/bookQuote/Quoter.java b/src/main/java/nl/utwente/di/bookQuote/Quoter.java new file mode 100644 index 0000000000000000000000000000000000000000..46046d10a7a9808fb1458b8ca8e21ab6418a0866 --- /dev/null +++ b/src/main/java/nl/utwente/di/bookQuote/Quoter.java @@ -0,0 +1,25 @@ +package nl.utwente.di.bookQuote; + +public class Quoter +{ + public double getBookPrice(String isbn) + { + switch(Integer.parseInt(isbn.replaceAll("[^\\d.]", ""))) + { + case 1: + return 10.0; + case 2: + return 45.0; + case 3: + return 20.0; + case 4: + return 34.0; + case 5: + return 50.0; + default: + return 0.0; + + } + + } +} diff --git a/src/main/webapp/.DS_Store b/src/main/webapp/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..34b18dad257fe72a0cf9d568c090684b302e333f Binary files /dev/null and b/src/main/webapp/.DS_Store differ diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..3771996b1dd961b0d9de5e32e72deb658eb31450 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee + http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> + + <display-name>di.bookQuote</display-name> + + <welcome-file-list> + <welcome-file>index.html</welcome-file> + <welcome-file>index.htm</welcome-file> + <welcome-file>index.jsp</welcome-file> + <welcome-file>default.html</welcome-file> + <welcome-file>default.htm</welcome-file> + <welcome-file>default.jsp</welcome-file> + </welcome-file-list> + <servlet> + <description>BookQuote Servlet</description> + <display-name>BookQuote</display-name> + <servlet-name>BookQuote</servlet-name> + <servlet-class>nl.utwente.di.bookQuote.BookQuote</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>BookQuote</servlet-name> + <url-pattern>/bookQuote</url-pattern> + </servlet-mapping> +</web-app> \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7240a9b36739bdc5d9eb43e8e880b83655284e58 --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,20 @@ +<!DOCTYPE HTML> +<!-- Front end for the webBookQuote Servlet. --> + +<html lang="en"> +<head> +<title>Web Book Quote Application</title> +<link rel="stylesheet" href="styles.css"> +<meta charset="UTF-8"> +</head> + +<body> +<h1>Web Book Quote Application</h1> + +<form ACTION="./bookQuote"> + <p>Enter ISBN number: <input TYPE="TEXT" NAME="isbn"></p> + <input TYPE="SUBMIT"> +</form> + +</body> +</html> diff --git a/src/main/webapp/styles.css b/src/main/webapp/styles.css new file mode 100644 index 0000000000000000000000000000000000000000..e3911593be8c37faac51502a8d09f71ee477ee70 --- /dev/null +++ b/src/main/webapp/styles.css @@ -0,0 +1,52 @@ +BODY { background-color: WHITE } + +H1 { color: PURPLE; + text-align: left; + font-size: 28px; + font-family: Arial, Helvetica, sans-serif; + font-weight: normal +} +.LARGER { font-size: 120% } +.TINY { font-size: 50% } +H2 { color: #440000; + text-align: left; + font-family: Arial, Helvetica, sans-serif +} +H3 { color: #440000; + text-align: left; + font-family: Arial, Helvetica, sans-serif +} +UL { margin-top: 0; + border-top-width: 0; + padding-top: 0 +} + +P { color: BLACK; + text-align: left; + font-size: 20px; + font-family: Arial, Helvetica, sans-serif +} + +FORM { color: BLACK; + text-align: left; + font-size: 20px; + font-family: Arial, Helvetica, sans-serif +} + +PRE { font-size: 105%; +} +CODE { font-size: 105%; +} +.TOC { font-size: 90%; + font-weight: bold; + font-family: Arial, Helvetica, sans-serif +} +TH.COLORED { background-color: #FFAD00 +} +TR.COLORED { background-color: #FFAD00 +} +TH.TITLE { background-color: #EF8429; + font-size: 40px; + font-family: Arial, Helvetica, sans-serif; +} +A:hover { color: red } diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d Binary files /dev/null and b/src/test/.DS_Store differ diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1f7f65d64d1006adb887faa93a5b8f93a5e321a4 Binary files /dev/null and b/src/test/java/.DS_Store differ diff --git a/src/test/java/TestQuoter.java b/src/test/java/TestQuoter.java new file mode 100644 index 0000000000000000000000000000000000000000..7d751619b8429209359af2742b217e7fbd66a607 --- /dev/null +++ b/src/test/java/TestQuoter.java @@ -0,0 +1,14 @@ +import nl.utwente.di.bookQuote.Quoter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class TestQuoter +{ + @Test + public void testBook1() throws Exception + { + Quoter quoter = new Quoter(); + double price = quoter.getBookPrice("1"); + Assertions.assertEquals(10.0, price, 0.0, "Price of book 1"); + } +}