Add serving of static files
Change-Id: I0cf257f7e74f05b903a45b84105a229161966541
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
index 96fe926..1d09d8a 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
@@ -5,8 +5,13 @@
import java.io.InputStream;
import java.util.Properties;
+import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
@@ -31,7 +36,8 @@
else {
in = new FileInputStream(f);
}
-
+
+
properties.load(in);
in.close();
@@ -46,8 +52,24 @@
connector.setHost(host);
connector.setIdleTimeout(60000);
jettyServer.addConnector(connector);
+
+ ResourceHandler resourceHandler= new ResourceHandler();
+ String resourceBase ="templates";
+ //If server is started as jar-file in target directory
+ if(!new File("templates").exists()) {
+ resourceBase = "../" + resourceBase;
+ }
- jettyServer.setHandler(contextHandler);
+ resourceHandler.setResourceBase(resourceBase);
+ //enable directory listing
+ resourceHandler.setDirectoriesListed(true);
+ ContextHandler contextHandRes= new ContextHandler("/res");
+ contextHandRes.setHandler(resourceHandler);
+
+ HandlerList handlers = new HandlerList();
+ handlers.setHandlers(new Handler[] { contextHandRes, contextHandler, new DefaultHandler()});
+ jettyServer.setHandler(handlers);
+
ServletHolder servletHolder = contextHandler.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
servletHolder.setInitOrder(0);
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
index 57dd9ec..00a69ef 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
@@ -14,7 +14,10 @@
import de.ids_mannheim.korap.plkexport.IdsExportService;
-//TODO Find a way to test efficiently the starting of the PluginServer with host and port of the config-file
+/*
+ * TODO Find a way to test efficiently the starting of the PluginServer with host and port of the config-file
+ * + serving static files
+ */
public class IdsExportServiceTest extends JerseyTest {
@@ -31,7 +34,8 @@
assertEquals("Http Content-Type should be: ", MediaType.TEXT_HTML, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
String content = response.readEntity(String.class);
assertEquals("Content of response is: ", "Export Web Service under construction", content);
+
}
-
+
}
diff --git a/plugin/templates/export.html b/plugin/templates/export.html
new file mode 100644
index 0000000..257310e
--- /dev/null
+++ b/plugin/templates/export.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Export Template</title>
+<script src="https://korap.ids-mannheim.de/js/korap-plugin-0.2.js"></script>
+</head>
+
+<body>
+<form>
+ <label for="fname">Dateiname: </label>
+ <input type="text" id="fname" name="fname"> <br>
+ Dateiformat:
+ <input type="radio" id="formatjson" name="format">
+ <label for="formatjson">JSON</label>
+ <input type="radio" id="formatrtf" name="rtf">
+ <label for="formatrtf">RTF</label><br>
+ <button> Exportieren </button>
+</form>
+</body>
+</html>
\ No newline at end of file