Added Query string information to Exporter objects
Change-Id: I1ea4de85de956b2f6622198dccdc83aca00182d4
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Exporter.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Exporter.java
index 8ed9007..c76ffb1 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Exporter.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Exporter.java
@@ -16,8 +16,10 @@
public JsonNode getQuery();
public JsonNode getCollection();
public void appendMatches (String s) throws IOException;
- public String getFname ();
- public void setFname (String s);
+ public String getFileName ();
+ public void setFileName (String s);
+ public String getQueryString ();
+ public void setQueryString (String s);
// Implemented by Exporter
public ResponseBuilder serve();
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 3add327..9f6f1ed 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
@@ -211,12 +211,11 @@
exp = new RtfExporter();
};
+ exp.setQueryString(q);
+
// set filename based on query (if not already set)
if (fname != null) {
- exp.setFname(fname);
- }
- else {
- exp.setFname(q);
+ exp.setFileName(fname);
};
// Initialize exporter (with meta data and first matches)
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
index 6767680..3d2ab87 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
@@ -40,7 +40,7 @@
private File file;
public JsonNode meta, query, collection;
- private String fname;
+ private String fname, queryString;
public String getMimeType() {
return "text/plain";
@@ -50,16 +50,27 @@
return "txt";
};
- public void setFname (String fname) {
+ public void setFileName (String fname) {
this.fname = fname;
};
- public String getFname () {
- if (this.fname == null)
- return "unknown";
- return sanitizeFileName(this.fname);
+ public String getFileName () {
+ String s = this.fname;
+ if (s == null)
+ s = this.queryString;
+ if (s == null)
+ return "export";
+ return sanitizeFileName(s);
};
+ public void setQueryString (String query) {
+ this.queryString = query;
+ };
+
+ public String getQueryString () {
+ return this.queryString;
+ };
+
public void setMeta (JsonNode meta) {
this.meta = meta;
};
@@ -195,7 +206,7 @@
.header(
"Content-Disposition",
"attachment; filename=" +
- this.getFname() +
+ this.getFileName() +
'.' +
this.getSuffix()
);
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/JsonExportTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/JsonExportTest.java
index 3784f2f..73bd736 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/JsonExportTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/JsonExportTest.java
@@ -55,8 +55,8 @@
@Test
public void testAttributes () throws IOException {
JsonExporter json = new JsonExporter();
- json.setFname("Beispiel");
- assertEquals(json.getFname(),"Beispiel");
+ json.setFileName("Beispiel");
+ assertEquals(json.getFileName(),"Beispiel");
assertEquals(json.getMimeType(),"application/json");
assertEquals(json.getSuffix(),"json");
};
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/MatchAggregatorTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/MatchAggregatorTest.java
index af21fd9..b19ce21 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/MatchAggregatorTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/MatchAggregatorTest.java
@@ -49,11 +49,28 @@
@Test
public void testAttributes () throws IOException {
MatchAggregator m = new MatchAggregator();
- m.setFname("Beispiel");
- assertEquals(m.getFname(),"Beispiel");
- m.setFname("contains(<s name=\"okay\">,[orth='Test'])");
- assertEquals(m.getFname(),"contains(s-name-okay-orth-Test)");
+ m.setFileName("Beispiel");
+ assertEquals(m.getFileName(),"Beispiel");
+ m.setFileName("contains(<s name=\"okay\">,[orth='Test'])");
+ assertEquals(m.getFileName(),"contains(s-name-okay-orth-Test)");
assertEquals(m.getMimeType(),"text/plain");
assertEquals(m.getSuffix(),"txt");
};
+
+ @Test
+ public void testFileName () throws IOException {
+ MatchAggregator m = new MatchAggregator();
+ assertEquals(m.getFileName(),"export");
+
+ m = new MatchAggregator();
+ m.setFileName("Beispiel");
+ assertEquals(m.getFileName(),"Beispiel");
+
+ m = new MatchAggregator();
+ m.setQueryString("contains(<s name=\"okay\">,[orth='Test'])");
+ assertEquals(m.getQueryString(),"contains(<s name=\"okay\">,[orth='Test'])");
+ assertEquals(m.getFileName(),"contains(s-name-okay-orth-Test)");
+ m.setFileName("Beispiel");
+ assertEquals(m.getFileName(),"Beispiel");
+ };
};
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/RtfExportTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/RtfExportTest.java
index 6192b5a..d9f0486 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/RtfExportTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/RtfExportTest.java
@@ -64,8 +64,8 @@
@Test
public void testAttributes () throws IOException {
RtfExporter rtf = new RtfExporter();
- rtf.setFname("Beispiel");
- assertEquals(rtf.getFname(),"Beispiel");
+ rtf.setFileName("Beispiel");
+ assertEquals(rtf.getFileName(),"Beispiel");
assertEquals(rtf.getMimeType(),"application/rtf");
assertEquals(rtf.getSuffix(),"rtf");
};