Commit 6265fc97 authored by bc1417's avatar bc1417
Browse files

Moved the download buttons to html page; added css styling

parent a0597fe8
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>shared-resources</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>CSS Resources</name>
</project>
\ No newline at end of file
......@@ -3,13 +3,10 @@ package ic.doc;
import java.util.*;
public class QueryProcessor {
/*Add a map mapping query to answer; change if to switch?;*/
private final Map<List<String>, String> queryMap = new HashMap<>();
private final List<Query> queriesMap = new ArrayList<>();
public QueryProcessor() {
/*this.queryMap*/
this.queriesMap.add(new Query(Arrays.asList("william", "shakespeare"),
"William Shakespeare (26 April 1564 - 23 April 1616) was an\n" +
"English poet, playwright, and actor, widely regarded as the greatest\n" +
......@@ -62,6 +59,7 @@ public class QueryProcessor {
"scientific method.",
"https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Blaise_Pascal_Versailles.JPG/800px-Blaise_Pascal_Versailles.JPG",
"https://en.wikipedia.org/wiki/Blaise_Pascal"));
this.queriesMap.add(new Query(Arrays.asList("william", "wordsworth"),
"William Wordsworth (7 April 1770 – 23 April 1850) was a \n "+
"major English Romantic poet who, with Samuel Taylor Coleridge, \n " +
......
......@@ -27,23 +27,37 @@ public class WebServer {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String query = req.getParameter("q");
String type = req.getParameter("type");
if (query == null || type == null) {
new IndexPage().writeTo(resp);
String type = req.getParameter("type"); // || type == null
if (query == null) {
if(type != null) {
String[] queryAndType = type.split(",");
String[] q = queryAndType[0].split("\\+");
renderResultsPage(String.join(" ", q), queryAndType[1], resp);
} else {
new IndexPage().writeTo(resp);
}
} else {
QueryProcessor queryProcessor = new QueryProcessor();
List<Query> possibilities = queryProcessor.process(query);
if (possibilities.size() == 1) {
Query answer = possibilities.get(0);
renderResultsPage(query, "html", resp);
}
}
private void renderResultsPage(String query, String type, HttpServletResponse resp) throws IOException {
QueryProcessor queryProcessor = new QueryProcessor();
List<Query> possibilities = queryProcessor.process(query);
if (possibilities.size() == 1) {
Query answer = possibilities.get(0);
if(type != null) {
if (type.equals("html")) {
new HTMLResultPage(query, answer).writeTo(resp);
} else {
new DownloadPage(query, answer, type).writeTo(resp);
}
} else {
new ChoicePage(query, possibilities).writeTo(resp);
// may not need a choice page class, just put code here
}
} else {
new ChoicePage(query, possibilities).writeTo(resp);
// may not need a choice page class, just put code here
}
}
}
......
......@@ -23,7 +23,11 @@ public class ChoicePage implements Page {
// Header
writer.println("<html>");
writer.println("<head><title>" + ambiguousQuery + "</title></head>");
writer.println("<head>");
writer.println("<style>");
writer.println(htmlStyle);
writer.println("</style>");
writer.println("<title>" + ambiguousQuery + "</title></head>");
writer.println("<body>");
// Content - list of hyperlinked choices
......
......@@ -19,10 +19,13 @@ public class HTMLResultPage implements Page {
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
String name = String.join("+", answer.getQuery());
// Header
writer.println("<html>");
writer.println("<head><title>" + query + "</title></head>");
writer.println("<head>"+
"<style>"+htmlStyle+"</style>"+
"<title>" + query + "</title></head>");
writer.println("<body>");
......@@ -31,12 +34,26 @@ public class HTMLResultPage implements Page {
writer.println("<h1>Sorry</h1>");
writer.print("<p>Sorry, we didn't understand <em>" + query + "</em></p>");
} else {
writer.println("<header>");
writer.println("<h1>" + query + "</h1>");
writer.println("<p>" + answer.getAnswer().replace("\n", "<br>") + "</p>");
writer.println("<p> <img src=\"" + answer.getImgURL() + "\"> </p>");
writer.println("</header>");
writer.println("<p class=\"information\">" + answer.getAnswer().replace("\n", "<br>") + "</p>");
writer.println("<img src=\"" + answer.getImgURL() + "\">");
writer.println("<form>");
writer.println("<button type=\"submit\" name=\"type\" value=\""+name+",markdown\"> Markdown </button>");
writer.println("<button type=\"submit\" name=\"type\" value=\""+name+",pdf\"> PDF </button>");
writer.println("</form>");
writer.println("<p><a href=\""+answer.getWikiURL()+"\" target=\"_blank" +
"\">Learn More!</a></p>");
writer.println("<p><a href=\"/\">Back to Search Page</a></p>");
writer.println("<div class=\"credits\">");
writer.println("<a href=\"" + answer.getImgURL() + "\"> Image credits: from wikipedia");
writer.println("</div>");
}
......
......@@ -12,7 +12,11 @@ public class IndexPage implements Page {
// Header
writer.println("<html>");
writer.println("<head><title>Welcome</title></head>");
writer.println("<head>");
writer.println("<style>");
writer.println(htmlStyle);
writer.println("</style>");
writer.println("<title>Welcome</title></head>");
writer.println("<body>");
// Content
......@@ -21,12 +25,6 @@ public class IndexPage implements Page {
"<form>" +
"<input type=\"text\" name=\"q\" />" +
"<br><br>" +
"<input type=\"radio\" name=\"type\" value=\"html\"> HTML" +
"<br>" +
"<input type=\"radio\" name=\"type\" value=\"markdown\"> Download Markdown File" +
"<br>" +
"<input type=\"radio\" name=\"type\" value=\"pdf\"> PDF" +
"<br><br>" +
"<input type=\"submit\">" +
"</form>" +
"</p>");
......
......@@ -4,6 +4,112 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public interface Page {
String htmlStyle = "body {\n" +
" text-align: center;\n" +
" background-color: rgb(255, 255, 153);\n" +
" /* background-image: url(\"https://ae01.alicdn.com/kf/HTB1nAkRi9YH8KJjSspdq6ARgVXa4/white-damask-gray-grey-Floral-pattern-Background-Vinyl-cloth-High-quality-Computer-print-wall-photo-backdrop.jpg\"); */\n" +
"}\n" +
"\n" +
"header {\n" +
" position: sticky;\n" +
" top: 0;\n" +
" left: 0;\n" +
" right: 0;\n" +
" background-color: #ff9966;\n" +
"}\n" +
"\n" +
"h1 {\n" +
" color: teal;\n" +
" font-family: \"Old English Text MT\", cursive;\n" +
" /* background-color: maroon; */\n" +
" font-size: 100px;\n" +
" width: 100%;\n" +
"\n" +
"}\n" +
"\n" +
".information {\n" +
" text-align: left;\n" +
" width: 50%;\n" +
" left: 0;\n" +
" display: inline-block;\n" +
" font-size: 150%;\n" +
"}\n" +
"\n" +
"p {\n" +
" font-size: 200%;\n" +
" /* display: inline-block; */\n" +
"\n" +
" font-family: cursive;\n" +
" /* background-color: rebeccapurple; */\n" +
"}\n" +
"\n" +
".forms {\n" +
" /* background-color: rgb(204, 255, 204); */\n" +
"}\n" +
"\n" +
".forms input[type=\"text\"] {\n" +
" width: 250px;\n" +
" padding: 10px;\n" +
" font-weight: bold;\n" +
" background-color: yellow;\n" +
" font-family: \"Old English Text MT\", fantasy;\n" +
" font-size: 120%;\n" +
" /* color: blue; */\n" +
"}\n" +
"\n" +
".forms input[type=\"radio\"] {\n" +
" cursor: pointer;\n" +
" position: relative;\n" +
"}\n" +
"\n" +
".forms input[type=\"submit\"] {\n" +
" cursor: pointer;\n" +
" height: 50px;\n" +
" width: 100px;\n" +
" font-weight: bold;\n" +
" font-size: 120%;\n" +
" font-family: \"Old English Text MT\", cursive;\n" +
" background-color: maroon;\n" +
" color: yellow;\n" +
"}\n" +
"\n" +
".forms input[type=\"submit\"]:hover {\n" +
" background-color: blue;\n" +
"}\n" +
"\n" +
".radio-value {\n" +
" font-family: Stencil, cursive;\n" +
" font-size: 150%\n" +
"}\n" +
"\n" +
"img {\n" +
" display: inline-block;\n" +
" border-radius: 50%;\n" +
" /* align: right; */\n" +
" width: 250px;\n" +
" margin-right: 100px;\n" +
" /* padding-right: 40px; */\n" +
"}\n" +
"\n" +
"a:visited {\n" +
" color: red;\n" +
"}\n" +
"\n" +
"a:hover {\n" +
" color: rgb(51, 204, 51);\n" +
"}\n" +
"\n" +
"a:active {\n" +
" color: blue;\n" +
"}\n" +
"\n" +
".credits {\n" +
" position: static;\n" +
" text-align: left;\n" +
" bottom: 0;\n" +
" left: 0;\n" +
" font-size: 20px;\n" +
"}\n";
void writeTo(HttpServletResponse resp) throws IOException;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment