Commit a12bcc14 authored by Alex Constantin-Gómez's avatar Alex Constantin-Gómez
Browse files

[all] added comments and cleaned up code

parent 83ad3bf2
Pipeline #172408 passed with stages
in 4 minutes and 18 seconds
FROM openjdk:11 FROM openjdk:11
# install maven and pandoc dependencies # install all dependencies
RUN apt-get update RUN apt-get update
RUN apt-get install curl RUN apt-get install curl
RUN apt-get install -y maven RUN apt-get install -y maven
RUN apt-get install -y texlive-latex-base texlive-fonts-recommended RUN apt-get install -y texlive-latex-base texlive-fonts-recommended
RUN apt-get install -y pandoc RUN apt-get install -y pandoc
# copy local files # copy required local files
WORKDIR /app WORKDIR /app
COPY pom.xml . COPY pom.xml .
COPY req_wacc.sh . COPY req_wacc.sh .
......
...@@ -17,6 +17,7 @@ public class WebServer { ...@@ -17,6 +17,7 @@ public class WebServer {
public WebServer() throws Exception { public WebServer() throws Exception {
Server server = new Server(Integer.valueOf(System.getenv("PORT"))); Server server = new Server(Integer.valueOf(System.getenv("PORT")));
ServletHandler handler = new ServletHandler(); ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(new CompilerWebsite()), WACC_COMPILER_PAGE_PATH); handler.addServletWithMapping(new ServletHolder(new CompilerWebsite()), WACC_COMPILER_PAGE_PATH);
handler.addServletWithMapping(new ServletHolder(new QueryWebsite()), "/*"); handler.addServletWithMapping(new ServletHolder(new QueryWebsite()), "/*");
...@@ -67,6 +68,7 @@ public class WebServer { ...@@ -67,6 +68,7 @@ public class WebServer {
resp.sendRedirect(WACC_COMPILER_PAGE_PATH); // send back to editor page resp.sendRedirect(WACC_COMPILER_PAGE_PATH); // send back to editor page
return; return;
} }
// Create temp file to send to WACC reference compiler // Create temp file to send to WACC reference compiler
File tempFile = File.createTempFile("test", ".wacc"); File tempFile = File.createTempFile("test", ".wacc");
FileWriter fw = new FileWriter(tempFile); FileWriter fw = new FileWriter(tempFile);
...@@ -74,8 +76,8 @@ public class WebServer { ...@@ -74,8 +76,8 @@ public class WebServer {
fw.flush(); fw.flush();
fw.close(); fw.close();
// Send HTTP request to reference compiler using curl
ProcessBuilder pb = new ProcessBuilder("sh", "req_wacc.sh", tempFile.getPath()); ProcessBuilder pb = new ProcessBuilder("sh", "req_wacc.sh", tempFile.getPath());
Process curl = pb.start(); Process curl = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(curl.getInputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(curl.getInputStream()));
try { try {
...@@ -86,8 +88,9 @@ public class WebServer { ...@@ -86,8 +88,9 @@ public class WebServer {
} }
tempFile.delete(); tempFile.delete();
// Parse the JSON response
String content = br.lines().reduce(String::concat).get(); String content = br.lines().reduce(String::concat).get();
System.out.println(content);
String field = "\"compiler_out\":"; String field = "\"compiler_out\":";
String out = content.substring(content.indexOf(field) + field.length()); String out = content.substring(content.indexOf(field) + field.length());
......
...@@ -31,6 +31,8 @@ public class IndexPage implements Page { ...@@ -31,6 +31,8 @@ public class IndexPage implements Page {
"</form>" + "</form>" +
"</p>"); "</p>");
writer.println("<br><br><a href=\"/wacc\">View our extension (WACC editor)</a>");
// Footer // Footer
writer.println("</body>"); writer.println("</body>");
writer.println("</html>"); writer.println("</html>");
......
...@@ -16,7 +16,7 @@ public class PdfResultPage implements Page { ...@@ -16,7 +16,7 @@ public class PdfResultPage implements Page {
this.query = query; this.query = query;
this.answer = answer; this.answer = answer;
} }
@Override
public void writeTo(HttpServletResponse resp) throws IOException { public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("application/pdf"); resp.setContentType("application/pdf");
ServletOutputStream os = resp.getOutputStream(); ServletOutputStream os = resp.getOutputStream();
......
package ic.doc.web; package ic.doc.web;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
public class WaccEditorPage implements Page { public class WaccEditorPage implements Page {
private final String code; private final String code;
private final String output; private final String output;
public WaccEditorPage(String code, String output) { public WaccEditorPage(String code, String output) {
this.code = code; this.code = code;
this.output = output; this.output = output;
} }
@Override @Override
public void writeTo(HttpServletResponse resp) throws IOException { public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html"); resp.setContentType("text/html");
PrintWriter writer = resp.getWriter(); PrintWriter writer = resp.getWriter();
// Header // Header
writer.println("<html>"); writer.println("<html>");
writer.println("<head><title>Online WACC Compiler</title></head>"); writer.println("<head><title>Online WACC Compiler</title></head>");
writer.println("<body>"); writer.println("<body>");
// Content and Form // Content and Form
writer.println("<h1>Online WACC Editor & Compiler</h1>"); writer.println("<h1>Online WACC Editor & Compiler</h1>");
writer.println("<p>Type in your WACC program below:</p>"); writer.println("<p>Type in your WACC program below:</p>");
...@@ -50,8 +37,6 @@ public class WaccEditorPage implements Page { ...@@ -50,8 +37,6 @@ public class WaccEditorPage implements Page {
writer.println("<input type=\"submit\" value=\"Compile and Execute\"></input>"); writer.println("<input type=\"submit\" value=\"Compile and Execute\"></input>");
writer.println("</form>"); writer.println("</form>");
// Show the output from the compiler // Show the output from the compiler
if (output != null) { if (output != null) {
writer.println("<br><br><h3>Output:</h3>"); writer.println("<br><br><h3>Output:</h3>");
...@@ -61,8 +46,6 @@ public class WaccEditorPage implements Page { ...@@ -61,8 +46,6 @@ public class WaccEditorPage implements Page {
writer.println("</pre></div>"); writer.println("</pre></div>");
} }
// Footer // Footer
writer.println("</body>"); writer.println("</body>");
writer.println("</html>"); writer.println("</html>");
......
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