Commit 87d3b4ec authored by Joshua Priestley's avatar Joshua Priestley
Browse files

Stylesheet now handled externally

parent 6472fb19
Pipeline #172853 passed with stages
in 13 seconds
......@@ -20,19 +20,9 @@ public class HTMLResultPage implements Page {
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
File style = new File("style.html");
BufferedReader reader = new BufferedReader(new FileReader(style));
writer.println(
"<html>\n" + " <head>\n" + " <title>\n" + " Welcome\n" + " </title>\n");
String line = reader.readLine();
while (line != null){
writer.println(line);
line = reader.readLine();
}
"<html>\n" + " <head><link rel = \"stylesheet\" href=\"https://drive.google.com/uc?export=view&id=1b-2_6zWL_6F360SBlZrdIGrpsuWgNkKz\" />\n" + " <title>\n" + " Welcome\n" + " </title>\n");
writer.println("</head><body><div class=\"container\"><h1>");
if (answer == null || answer.isEmpty()) {
writer.println("Query Not Found");
......
......@@ -12,18 +12,10 @@ public class IndexPage implements Page {
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
File style = new File("style.html");
BufferedReader reader = new BufferedReader(new FileReader(style));
// Header
writer.println(
"<html>\n" + " <head>\n" + " <title>\n" + " Welcome\n" + " </title>\n");
String line = reader.readLine();
while (line != null){
writer.println(line);
line = reader.readLine();
}
"<html>\n" + " <head><link rel = \"stylesheet\" href=\"https://drive.google.com/uc?export=view&id=1b-2_6zWL_6F360SBlZrdIGrpsuWgNkKz\" />\n" + " <title>\n" + " Welcome\n" + " </title>\n");
writer.println(
......
......@@ -23,32 +23,38 @@ public class MarkdownResultPage implements Page {
@Override
public void writeTo(HttpServletResponse resp) throws IOException {
File markdown = getFile();
outputStreams(markdown);
resp.setContentType("file/markdown");
resp.setHeader("Content-Disposition", "Inline; filename=" + query + ".md");
outputStreams(markdown, resp);
// Remove temporary file
markdown.delete();
}
void outputStreams(File markdown) throws IOException {
void outputStreams(File markdown, HttpServletResponse resp) throws IOException {
// Byte streams
InputStream inputStream = new FileInputStream(markdown);
OutputStream outputStream = new FileOutputStream(markdown);
inputStream.transferTo(outputStream);
InputStream inputStream = new FileInputStream(markdown);
inputStream.transferTo(resp.getOutputStream());
}
File getFile() throws IOException {
File markdown = new File("result.md");
// Header
FileWriter writer = new FileWriter("result.md");
writer.write(query + "\n");
writer.write("======\n");
// Content
if (answer == null || answer.isEmpty()) {
writer.write("Sorry, we did not understand your query.\n");
} else {
writer.write(answer);
}
return markdown;
File markdown = File.createTempFile("result", ".md");
// Header
FileWriter writer = new FileWriter(markdown);
writer.write("<h1>" + query + "<h1>");
writer.write("-------------------------------------------------<br>");
// Content
if (answer == null || answer.isEmpty()) {
writer.write("Sorry, we did not understand your query.\n");
} else {
writer.write("<p>" + answer + "</p>");
}
writer.flush();
return markdown;
}
}
......@@ -15,12 +15,12 @@ public class PDFResultPage extends MarkdownResultPage {
File markdown = getFile();
ProcessBuilder pb = new ProcessBuilder();
pb.command("pandoc -s -o result.pdf result.md");
pb.command("pandoc -s -o result.pdf " + markdown.getAbsolutePath());
pb.start();
File pdf = new File("result.pdf");
outputStreams(markdown);
outputStreams(markdown, resp);
// Remove temporary file
markdown.delete();
......
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