Add context marker if more context is available

Change-Id: Iac1b732da6165d473b181cc8fe9006a655b89ff9
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/RtfExporter.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/RtfExporter.java
index 888dec1..c7a3594 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/RtfExporter.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/RtfExporter.java
@@ -73,11 +73,17 @@
             // Snippet
             w.append("{\\pard ");
             w.append("\\qj ");
+            if (s.hasMoreLeft()) {
+                w.append("[...] ");
+            };
             rtfText(w, s.getLeft());
             w.append(" {\\b ");
             rtfText(w, s.getMark());
             w.append("} ");
             rtfText(w, s.getRight());
+            if (s.hasMoreRight()) {
+                w.append(" [...]");
+            };
             w.append("\\par}");
 
             // Reference
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Snippet.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Snippet.java
index 8726934..678a562 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Snippet.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/Snippet.java
@@ -1,13 +1,29 @@
 package de.ids_mannheim.korap.plkexport;
 
+import java.util.regex.Pattern;
+
 public class Snippet {
 
-    private String left;
-    private String right;
-    private String mark;
+    private String left, right, mark;
+    private boolean leftMore, rightMore;
 
+    private static Pattern leftMoreP =
+        Pattern.compile("(?i)<span[^>]*?class=\"more\".+<mark>");
+    private static Pattern rightMoreP =
+        Pattern.compile("(?i)</mark>.+<span[^>]*?class=\"more\"");
 
     public Snippet (String snippetstr) {
+
+        // Check the context
+        this.leftMore = this.rightMore = false;
+        if (leftMoreP.matcher(snippetstr).find()) {
+            this.leftMore = true;
+        };
+        if (rightMoreP.matcher(snippetstr).find()) {
+            this.rightMore = true;
+        };
+
+        // Split the match
         String[] split = snippetstr
             .replaceAll("(?i)</?span[^>]*>", "")
             .split("</?mark>");
@@ -17,7 +33,6 @@
         this.setRight(unescapeHTML(split[2].trim()));
     }
 
-
     public String getLeft () {
         return left;
     }
@@ -47,6 +62,17 @@
         this.mark = mark;
     }
 
+    
+    public boolean hasMoreLeft () {
+        return leftMore;
+    };
+
+
+    public boolean hasMoreRight () {
+        return rightMore;
+    };
+
+    
     private static String unescapeHTML (String text) {
         if (text == null)
 			return "";
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 a357dbe..956a33f 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
@@ -42,7 +42,9 @@
                   "\"title\":\"Title2\","+
                   "\"pubDate\":\"20051104\","+
                   "\"textSigle\":\"RTF/G59/34285\","+
-                  "\"snippet\":\"Simpler <mark>&quot;match2&quot;</mark> Snippet\"}"+
+                  "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+
+                  "Simpler <mark>&quot;match2&quot;</mark> Snippet"+
+                  "<span class=\\\"more\\\"></span></span>\"}"+
                   "]}");
 
         Response resp = json.serve().build();
@@ -52,5 +54,10 @@
         assertTrue(x.contains("{\\b \"match2\"}"));
         assertTrue(x.contains("{\\b Title1"));
         assertTrue(x.contains("{\\b Title2"));
+
+        assertTrue(x.contains("\\qj Simple "));
+        assertTrue(x.contains("\\qj [...] Simpler "));
+        assertTrue(x.contains("Snippet\\par}"));
+        assertTrue(x.contains("Snippet [...]\\par}"));
     };
 };
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/SnippetTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/SnippetTest.java
index 41f9144..18ded61 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/SnippetTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/SnippetTest.java
@@ -19,6 +19,8 @@
         assertEquals(s.getLeft(),"Der");
         assertEquals(s.getRight(),"ging um");
         assertEquals(s.getMark(),"Plagegeist");
+        assertFalse(s.hasMoreLeft());
+        assertFalse(s.hasMoreRight());
     };
 
     @Test
@@ -34,5 +36,7 @@
                      "im Sinne von \"");
         assertEquals(s.getRight(),"\" verwendet, folglich war 蚂蚁 ursprünglich frei übersetzt eine \"Sch...-Ameise\" ;-) -- 18:21, 30. Apr. 2007 (CEST) Hallo Allgaeuer, mag sein, dass es für dich ein Hammer ist, aber es ist Stand der aktuellen Forschung in der Sinologie. Schriften von Karlgren u.");
         assertEquals(s.getMark(),"Plagegeist");
+        assertTrue(s.hasMoreLeft());
+        assertTrue(s.hasMoreRight());
     };
 };