Support for compound limit expressions
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 17 Dec 2013 03:00:07 +0000 (22:00 -0500)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 17 Dec 2013 03:00:07 +0000 (22:00 -0500)
Limits with multiple comma-separated expressions were not
properly tokenized due to the existance of literal commas
in the individual expressions as well.

Now literal commas most be escaped by the client of the
mkjsf library, as in 'steinbeck\, john'

ie: limit=author=steinbeck\, john,date=1947

src/main/java/com/indexdata/mkjsf/pazpar2/commands/FilterParameter.java
src/main/java/com/indexdata/mkjsf/pazpar2/commands/LimitParameter.java
src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java

index 4bafeb8..e10edb6 100644 (file)
@@ -31,7 +31,7 @@ public class FilterParameter extends CommandParameter {
         completeValue.append(",");\r
       else \r
         first=false;      \r
-      completeValue.append(pz2escape(expr.toString()));\r
+      completeValue.append(expr.toString());\r
     }\r
     return completeValue.toString();    \r
   }  \r
index 0b98956..93a26fc 100644 (file)
@@ -31,7 +31,7 @@ public class LimitParameter extends CommandParameter {
         completeValue.append(",");\r
       else \r
         first=false;      \r
-      completeValue.append(pz2escape(expr.toString()));\r
+      completeValue.append(expr.toString());\r
       logger.trace("valueWithExpressions so far: [" + completeValue + "]");\r
     }\r
     return completeValue.toString();    \r
index dcbb323..f9f76a2 100644 (file)
@@ -1,9 +1,7 @@
 package com.indexdata.mkjsf.pazpar2.commands;\r
 \r
-import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
-import java.util.StringTokenizer;\r
 \r
 import javax.enterprise.context.SessionScoped;\r
 import javax.inject.Named;\r
@@ -74,7 +72,8 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
    */  \r
   public void setFilter(String compoundExpression) {\r
     if (compoundExpression != null && compoundExpression.length()>0) {\r
-      String[] subExpressions = compoundExpression.split(",");\r
+      // Split expression by commas that are not escaped (with backslash)\r
+      String[] subExpressions = compoundExpression.split("(?<!\\\\),");\r
       for (int i=0; i<subExpressions.length; i++) {\r
         if (subExpressions[i].split("[=~]").length==1) {\r
           removeFilters(subExpressions[i].split("[=~]")[0]);\r
@@ -229,7 +228,8 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
    */  \r
   public void setLimit (String compoundExpression) {   \r
     if (compoundExpression != null && compoundExpression.length()>0) {\r
-      String[] subExpressions = compoundExpression.split(",");\r
+      // Split expression by commas that are not escaped (with backslash)\r
+      String[] subExpressions = compoundExpression.split("(?<!\\\\),");\r
       for (int i=0; i<subExpressions.length; i++) {\r
         if (subExpressions[i].split("[=~]").length==1) {\r
           removeLimits(subExpressions[i].split("[=~]")[0]);\r