Commit a2309693 authored by Barr, Robert's avatar Barr, Robert
Browse files

Revert "Merge branch 'java_extensions' of..."

This reverts commit 84c1ba0a
parent 4f66cb4d
Pipeline #172419 passed with stages
in 53 seconds
......@@ -2,7 +2,6 @@ package ic.doc;
import ic.doc.web.HTMLResultPage;
import ic.doc.web.IndexPage;
import ic.doc.web.MarkdownResultPage;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
......@@ -28,11 +27,8 @@ public class WebServer {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String query = req.getParameter("q");
String isMarkdown = req.getParameter("markdown");
if (query == null) {
new IndexPage().writeTo(resp);
} else if("md".equals(isMarkdown)) {
new MarkdownResultPage(query, new QueryProcessor().process(query)).writeTo(resp);
} else {
new HTMLResultPage(query, new QueryProcessor().process(query)).writeTo(resp);
}
......
......@@ -6,93 +6,36 @@ import java.io.PrintWriter;
public class HTMLResultPage implements Page {
private final String query;
private final String answer;
private final String query;
private final String answer;
public HTMLResultPage(String query, String answer) {
this.query = query;
this.answer = answer;
}
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println(
"<html>\n" + " <head>\n" + " <title>\n" + " Welcome\n" + " </title>\n");
writer.println(
"<style>body {\n"
+ " font-family: Helvetica, sans-serif;\n"
+ " }\n"
+ "\n"
+ " .container {\n"
+ " width: 500px;\n"
+ " height: 350px;\n"
+ " background-color: rgb(238, 238, 238);\n"
+ " position: fixed;\n"
+ " border: 2px solid rgb(190, 190, 190);\n"
+ " top: 50%;\n"
+ " left: 50%;\n"
+ " transform: translate(-50%, -90%);\n"
+ " border-radius: 20px;\n"
+ " padding:40px;\n"
+ " }\n"
+ " \n"
+ " h1 {\n"
+ " font-family: Helvetica, sans-serif;\n"
+ " margin-top: 30px;\n"
+ " }\n"
+ " hr {\n"
+ " border: 3px solid rgb(190, 190, 190);\n"
+ " border-radius: 5px;\n"
+ " }\n"
+ " \n"
+ " input[type=text], select {\n"
+ " width: 100%;\n"
+ " padding: 12px 20px;\n"
+ " margin: 8px 0;\n"
+ " display: inline-block;\n"
+ " border: 1px solid #ccc;\n"
+ " border-radius: 4px;\n"
+ " box-sizing: border-box;\n"
+ "}\n"
+ "\n"
+ "input[type=submit], button {\n"
+ " width: 100%;\n"
+ " background-color: #4CAF50;\n"
+ " color: white;\n"
+ " padding: 14px 20px;\n"
+ " margin: 8px 0;\n"
+ " border: none;\n"
+ " border-radius: 4px;\n"
+ " cursor: pointer;\n"
+ " }\n"
+ "\n"
+ " input[type=submit]:hover {\n"
+ " background-color: #45a049;\n"
+ " }\n"
+ "\n"
+ " form {\n"
+ " margin-top: 30px;\n"
+ " }</style>");
writer.println("</head><body><div class=\"container\"><h1>");
if (answer == null || answer.isEmpty()) {
writer.println("Query Not Found");
} else {
writer.println(query.toUpperCase());
public HTMLResultPage(String query, String answer) {
this.query = query;
this.answer = answer;
}
writer.println("</h1><hr>");
if (answer == null || answer.isEmpty()) {
writer.print("<p>Sorry, we didn't understand <em>" + query + "</em></p>");
} else {
writer.println("<p>" + answer.replace("\n", "<br>") + "</p>");
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
// Header
writer.println("<html>");
writer.println("<head><title>" + query + "</title></head>");
writer.println("<body>");
// Content
if (answer == null || answer.isEmpty()) {
writer.println("<h1>Sorry</h1>");
writer.print("<p>Sorry, we didn't understand <em>" + query + "</em></p>");
} else {
writer.println("<h1>" + query + "</h1>");
writer.println("<p>" + answer.replace("\n", "<br>") + "</p>");
}
writer.println("<p><a href=\"/\">Back to Search Page</a></p>");
// Footer
writer.println("</body>");
writer.println("</html>");
}
writer.println("<a href=\"/\"><button>Back to Search Page</button></a>");
writer.println("</div></body></html>");
}
}
......@@ -6,15 +6,15 @@ import java.io.PrintWriter;
public class IndexPage implements Page {
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
// Header
writer.println(
"<html>\n" + " <head>\n" + " <title>\n" + " Welcome\n" + " </title>\n");
// Header
writer.println("<html>");
writer.println("<head><title>Welcome</title></head>");
writer.println("<body>");
<<<<<<< HEAD
// Content
writer.println(
"<h1>Welcome!!</h1>" +
......@@ -26,90 +26,10 @@ public class IndexPage implements Page {
"<br><br><input type=\"submit\">" +
"</form>" +
"</p>");
=======
writer.println(
"<style>body {\n"
+ " font-family: Helvetica, sans-serif;\n"
+ " }\n"
+ "\n"
+ " .container {\n"
+ " width: 500px;\n"
+ " height: 350px;\n"
+ " background-color: rgb(238, 238, 238);\n"
+ " position: fixed;\n"
+ " border: 2px solid rgb(190, 190, 190);\n"
+ " top: 50%;\n"
+ " left: 50%;\n"
+ " transform: translate(-50%, -90%);\n"
+ " border-radius: 20px;\n"
+ " padding:40px;\n"
+ " }\n"
+ " \n"
+ " h1 {\n"
+ " font-family: Helvetica, sans-serif;\n"
+ " margin-top: 30px;\n"
+ " }\n"
+ " hr {\n"
+ " border: 3px solid rgb(190, 190, 190);\n"
+ " border-radius: 5px;\n"
+ " }\n"
+ " \n"
+ " input[type=text], select {\n"
+ " width: 100%;\n"
+ " padding: 12px 20px;\n"
+ " margin: 8px 0;\n"
+ " display: inline-block;\n"
+ " border: 1px solid #ccc;\n"
+ " border-radius: 4px;\n"
+ " box-sizing: border-box;\n"
+ "}\n"
+ "\n"
+ "input[type=submit] {\n"
+ " width: 100%;\n"
+ " background-color: #4CAF50;\n"
+ " color: white;\n"
+ " padding: 14px 20px;\n"
+ " margin: 8px 0;\n"
+ " border: none;\n"
+ " border-radius: 4px;\n"
+ " cursor: pointer;\n"
+ " }\n"
+ "\n"
+ " input[type=submit]:hover {\n"
+ " background-color: #45a049;\n"
+ " }\n"
+ "\n"
+ " form {\n"
+ " margin-top: 30px;\n"
+ " }</style>");
>>>>>>> 3ff5d47141923be40daa258eba11f2769370e385
writer.println(
" </head>\n"
+ " <body>\n"
+ " <div class=\"container\">\n"
+ " <h1>\n"
+ " Search\n"
+ " </h1>\n"
+ " <hr>\n"
+ " <form>\n"
+ " <label>Enter your query in the box below.</label>\n"
+ " <input type=\"text\" name=\"q\" />\n"
+ " <label for=\"dl\">Choose a download type:</label>\n"
+ "\n"
+ " <select name=\"markdown\" id=\"dl\">\n"
+ " <option>No Download (Default)</option>\n"
+ " <option id=\"md\" name=\"markdown\" value=\"md\">Markdown File</option>\n"
+ " <option value=\"pdf\">PDF File</option>\n"
+ " </select>\n"
+ " <input type=\"submit\">\n"
+ " </form>\n"
+ " </div>\n"
+ " </body>\n"
+ "</html>");
// Footer
writer.println("</body>");
writer.println("</html>");
}
// Footer
writer.println("</body>");
writer.println("</html>");
}
}
......@@ -22,27 +22,16 @@ public class MarkdownResultPage implements Page {
@Override
public void writeTo(HttpServletResponse resp) throws IOException {
<<<<<<< HEAD
File markdown = new File("result.md");
// Header
FileWriter writer = new FileWriter("result.md");
writer.write(query + "\n");
writer.write("======\n");
=======
File markdown = File.createTempFile("result", ".md");
resp.setContentType("file/markdown");
resp.setHeader("Content-Disposition", "Inline; filename=" + query + ".md");
// Header
FileWriter writer = new FileWriter(markdown);
writer.write("<h1>" + query + "<h1>");
writer.write("-------------------------------------------------<br>");
>>>>>>> 3ff5d47141923be40daa258eba11f2769370e385
// Content
if (answer == null || answer.isEmpty()) {
writer.write("Sorry, we did not understand your query.\n");
} else {
<<<<<<< HEAD
writer.write(answer);
}
......@@ -53,21 +42,5 @@ public class MarkdownResultPage implements Page {
// Remove temporary file
markdown.delete();
=======
writer.write("<p>" + answer + "</p>");
}
writer.flush();
System.out.println(markdown.length());
System.out.println(markdown.getName());
// Byte streams
InputStream inputStream = new FileInputStream(markdown);
inputStream.transferTo(resp.getOutputStream());
// Remove temporary file
markdown.deleteOnExit();
>>>>>>> 3ff5d47141923be40daa258eba11f2769370e385
}
}
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