Make filename parameter optional
Change-Id: Ie957dc5549be47ec55d28b1432b774ffa44bde21
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
index c597354..f4f919e 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
@@ -65,7 +65,6 @@
String[][] params = {
- { "fname", fname },
{ "format", format },
{ "q", q },
{ "ql", ql }
@@ -112,14 +111,15 @@
String resp = resource.request(MediaType.APPLICATION_JSON)
.get(String.class);
+ if (fname == null) {
+ fname = q;
+ }
+
//format == json
if (format.equals("json")) {
builder = Response.ok(resp);
- builder.header("Content-Disposition",
- "attachment; filename=" + fname + ".json");
builder.type(MediaType.APPLICATION_JSON);
- Response response = builder.build();
- return response;
+ fname = fname + ".json";
}
// format == rtf / else
@@ -143,11 +143,15 @@
String rtfresp = writeRTF(listMatches);
builder = Response.ok(rtfresp);
- builder.header("Content-Disposition",
- "attachment; filename=" + fname + ".rtf");
- Response response = builder.build();
- return response;
+ fname = fname + ".rtf";
}
+
+ // TODO:
+ // Sanitize file name (i.e. replace extra characters)
+ builder.header("Content-Disposition",
+ "attachment; filename=" + fname);
+ Response response = builder.build();
+ return response;
}
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 e2660a1..22c02d6 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
@@ -216,6 +216,7 @@
Response resp;
String fvalue;
+ frmap.remove("fname");
MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
map.putAll(frmap);
diff --git a/plugin/templates/export.html b/plugin/templates/export.html
index 404a7cf..b6979db 100644
--- a/plugin/templates/export.html
+++ b/plugin/templates/export.html
@@ -21,8 +21,10 @@
<br/>
<br/>
<br/>
+ <!--
<label for="fname">Dateiname:</label>
<input type="text" id="fname" name="fname" required> <br/>
+-->
Dateiformat:
<input type="radio" id="formatjson" name="format" value="json">
<label for="formatjson">JSON</label>
@@ -43,4 +45,4 @@
<button> Exportieren </button>
</form>
</body>
-</html>
\ No newline at end of file
+</html>