diff --git a/src/main/java/de/uni_hamburg/corpora/server/Static.java b/src/main/java/de/uni_hamburg/corpora/server/Static.java index a2df865e07016f27a5cadf6386d7b71086a5522a..136bed488d5e5ff4018a1a2f42113f6a66ca9692 100644 --- a/src/main/java/de/uni_hamburg/corpora/server/Static.java +++ b/src/main/java/de/uni_hamburg/corpora/server/Static.java @@ -4,12 +4,15 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.core.Response; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.StringWriter; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; @@ -32,20 +35,31 @@ public class Static { @GET public Response getStatic(@PathParam("staticFile") String fileName) { logger.info("Loading file " + fileName); - // Get file from resource - URL resource = this.getClass().getClassLoader().getResource("static/"+ fileName); - if (resource == null) { - logger.info("Resource is null"); - return Response.status(404,"Invalid static file").build(); +// // Get file from resource +// URL resource = this.getClass().getClassLoader().getResource("static/"+ fileName); +// if (resource == null) { +// logger.info("Resource is null"); +// return Response.status(404,"Invalid static file").build(); +// } +// else { +// try { +// logger.info("Resource is " + resource.toURI()); +// File staticFile = new File(resource.toURI()); +// return Response.ok(new FileInputStream(staticFile),Files.probeContentType(staticFile.toPath())).build(); +// } catch (URISyntaxException | IOException e) { +// return Response.status(500, "Error loading file").build(); +// } +// } + StringWriter result = new StringWriter(); + VelocityContext context = new VelocityContext(); +// Velocity.mergeTemplate("static/" + fileName, "UTF-8",context,result) ; +// return Response.ok(result.toString()).build() ; + //return Response.ok(Velocity.getTemplate("static/" + fileName).toString()).build(); + try { + return Response.ok(this.getClass().getModule().getResourceAsStream("static/" + fileName).readAllBytes()).build(); } - else { - try { - File staticFile = new File(resource.toURI()); - logger.info("Resource is " + resource.toURI()); - return Response.ok(new FileInputStream(staticFile),Files.probeContentType(staticFile.toPath())).build(); - } catch (URISyntaxException | IOException e) { - return Response.status(500, "Error loading file").build(); - } + catch (IOException e) { + return Response.status(500, "Error loading resource").build(); } } } diff --git a/src/main/java/de/uni_hamburg/corpora/server/WebRoot.java b/src/main/java/de/uni_hamburg/corpora/server/WebRoot.java index df6c3493284293a22ad9c2e8c47777b9e20c858f..cdd7199312a2052222945d1ab57deed037150d0f 100644 --- a/src/main/java/de/uni_hamburg/corpora/server/WebRoot.java +++ b/src/main/java/de/uni_hamburg/corpora/server/WebRoot.java @@ -12,8 +12,13 @@ import org.apache.velocity.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.StringWriter; import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; /** * /** @@ -35,14 +40,28 @@ public class WebRoot { @GET @Produces(MediaType.TEXT_HTML) public Response getRoot() { - ClassLoader cl = this.getClass().getClassLoader(); - URL res = this.getClass().getClassLoader().getResource("templates/root.vm"); - if (res == null) + try { + //putStream template = this.getClass().getModule().getResourceAsStream("templates/root.vm"); +// logger.info("Test: " + new String(this.getClass().getModule().getResourceAsStream("templates/root.vm") +// .readAllBytes()) + " # "); + StringWriter result = new StringWriter(); + VelocityContext context = new VelocityContext(); + context.put("functions", new ListCorpusFunctions().listFunctions()); + Velocity.evaluate(context,result,"webroot",new String(this.getClass().getModule() + .getResourceAsStream("templates/root.vm").readAllBytes())); + return Response.ok(result.toString()).build() ; + } catch (IOException e) { + logger.info("Got exception " + e); return Response.status(500,"Template not found").build(); - StringWriter result = new StringWriter(); - VelocityContext context = new VelocityContext(); - context.put("functions", new ListCorpusFunctions().listFunctions()); - Velocity.mergeTemplate("templates/root.vm", "UTF-8",context,result) ; - return Response.ok(result.toString()).build() ; + } +// URL res = this.getClass().getClassLoader().getResource("templates/root.vm"); + //URL res = this.getClass().getResource("template/root.vm"); + //if (res == null) + // return Response.status(500,"Template not found").build(); +// StringWriter result = new StringWriter(); +// VelocityContext context = new VelocityContext(); +// context.put("functions", new ListCorpusFunctions().listFunctions()); +// Velocity.mergeTemplate("templates/root.vm", "UTF-8",context,result) ; +// return Response.ok(result.toString()).build() ; } } diff --git a/src/main/resources/templates/root.vm b/src/main/resources/templates/root.vm new file mode 100644 index 0000000000000000000000000000000000000000..137c951d3404757557b54e992d2122b90673e033 --- /dev/null +++ b/src/main/resources/templates/root.vm @@ -0,0 +1,83 @@ +<html> +<head> +<script src="static/bootstrap.js"></script> +<script src="static/jquery-3.6.0.min.js"></script> +<script src="static/main.js"></script> +<link rel="stylesheet" href="static/main.css" as="style" type="text/css"> +<link rel="stylesheet" href="static/bootstrap.css" as="style" type="text/css"> +</head> +<body> +<h1>Corpus services</h1> +<div class="col lg"> + <div class="row"> + <input type="file" class="form-control" id="corpus-files" webkitdirectory mozdirectory msdirectory odirectory + directory> + </div> + <div class="row"> + <input type="text" id="file-exts" value="txt"> + </div> + <div class="row"> + <a href="#" class="btn btn-primary" id="send-files">Send files and check data</a> + </div> + <form id="corpus_checker_form" method="post" action=""> + <div class="accordion" id="corpus_functions"> + #foreach ($function in $functions) + #if ($function.available) + <div class="accordion-item"> + <h2 class="accordion-header" id="heading_$function.name"> + <div class="row"> + <div class="col"> + <button + class="accordion-button collapsed" + type="button" + data-bs-toggle="collapse" + data-bs-target="#collapse_$function.name" + aria-expanded="false" aria-controls="collapse_$function.name"> + $function.name + </button> + </div> + <div class="col"> + <input type="checkbox" class="form-check-input" id="validator_$function.name" value="$function.name"> + </input> + </div> + </div> + </h2> + <div id="collapse_$function.name" class="accordion-collapse collapse" aria-labelledby="heading_$function.name" + data-bs-parent="#corpus_functions"> + <div class="accordion-body"> + Description: $function.description<br> + Usable for: $function.usableForString<br> + #if($function.paramsString) + Parameters:<br> + $function.paramsString + #end + </div> + </div> + </div> + #end + #end + </div> + </form> +</div> + + +<div class="modal" tabindex="-1" id="check_in_progress_dialogue"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title">Check in progress</h5> + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> + </div> + <div class="modal-body"> + <p>Check in progress. Results will soon be available here: <a href="report">Report</a></p> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> + </div> + </div> + </div> +</div> + + +</body> +</html> \ No newline at end of file