jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r706242 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Date Mon, 20 Oct 2008 11:37:21 GMT
Author: ckoell
Date: Mon Oct 20 04:37:20 2008
New Revision: 706242

URL: http://svn.apache.org/viewvc?rev=706242&view=rev
Log:
JCR-1248: Helper Method to escape illegal XPath Search Term

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java?rev=706242&r1=706241&r2=706242&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Mon Oct 20 04:37:20 2008
@@ -477,7 +477,28 @@
         }
         return buffer.toString();
     }
-
+    
+    /** Escapes all illegal XPath search characters of a string.
+    * <p>Example:<br>
+    * A search string like 'test?' will run into a ParseException
+    * documented in http://issues.apache.org/jira/browse/JCR-1248
+    * 
+    * @param string the string to encode
+    * @return the escaped string    
+    */
+   public static String escapeIllegalXpathSearchChars(String s) {
+       StringBuffer sb = new StringBuffer();
+       sb.append(s.substring(0, (s.length() - 1)));
+       char c = s.charAt(s.length() - 1);
+       // NOTE: keep this in sync with _ESCAPED_CHAR below!
+       if (c == '!' || c == '(' || c == ':' || c == '^' 
+           || c == '[' || c == ']' || c == '\"' || c == '{' 
+           || c == '}' || c == '?') {
+           sb.append('\\');
+       }
+       sb.append(c);
+       return sb.toString();
+   }
     /**
      * Unescapes previously escaped jcr chars.
      * <p/>



Mime
View raw message