jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r684694 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/util/Text.java test/java/org/apache/jackrabbit/util/TextTest.java
Date Mon, 11 Aug 2008 09:48:36 GMT
Author: tripod
Date: Mon Aug 11 02:48:34 2008
New Revision: 684694

URL: http://svn.apache.org/viewvc?rev=684694&view=rev
Log:
JCR-1706 Fix unexpected behavior of Text.getName()

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.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=684694&r1=684693&r2=684694&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 Aug 11 02:48:34 2008
@@ -516,11 +516,7 @@
      * @return the name part or <code>null</code> if <code>path</code>
is <code>null</code>.
      */
     public static String getName(String path) {
-        if (path == null) {
-            return null;
-        } else {
-            return path.substring(path.lastIndexOf('/'));
-        }
+        return getName(path, '/');
     }
 
     /**
@@ -533,11 +529,9 @@
      * @return the name part or <code>null</code> if <code>path</code>
is <code>null</code>.
      */
     public static String getName(String path, char delim) {
-        if (path == null) {
-            return null;
-        } else {
-            return path.substring(path.lastIndexOf(delim));
-        }
+        return path == null
+                ? null 
+                : path.substring(path.lastIndexOf(delim) + 1);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java?rev=684694&r1=684693&r2=684694&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
Mon Aug 11 02:48:34 2008
@@ -103,4 +103,44 @@
             assertFalse(nonDesc + " isn't a descendant of " + parent, Text.isDescendant(parent,
nonDesc));
         }
     }
+
+    public void testGetName() {
+        List l = new ArrayList();
+        l.add(new String[] {"/a/b/c", "c"});
+        l.add(new String[] {"c", "c"});
+        l.add(new String[] {null, null});
+        l.add(new String[] {"", ""});
+        l.add(new String[] {"/", ""});
+        l.add(new String[] {"http://jackrabbit.apache.org/jackrabbit", "jackrabbit"});
+        l.add(new String[] {"http://jackrabbit.apache.org/jackrabbit/", ""});
+
+        for (Iterator it = l.iterator(); it.hasNext();) {
+            String[] strs = (String[]) it.next();
+            assertEquals(strs[1], Text.getName(strs[0]));
+        }
+
+        // Text.getName(String path, boolean ignoreTrailingSlash)
+        l = new ArrayList();
+        l.add(new String[] {"http://jackrabbit.apache.org/jackrabbit", "jackrabbit"});
+        l.add(new String[] {"http://jackrabbit.apache.org/jackrabbit/", "jackrabbit"});
+
+        for (Iterator it = l.iterator(); it.hasNext();) {
+            String[] strs = (String[]) it.next();
+            assertEquals(strs[1], Text.getName(strs[0], true));
+        }
+
+        // Text.getName(String path, char delim)
+        l = new ArrayList();
+        l.add(new String[] {"/a=b/c", "b/c"});
+        l.add(new String[] {"c", "c"});
+        l.add(new String[] {null, null});
+        l.add(new String[] {"", ""});
+        l.add(new String[] {"http:/=jackrabbit.apache.org/jackrabbit", "jackrabbit.apache.org/jackrabbit"});
+        l.add(new String[] {"http:=//jackrabbit.apache.org/jackrabbit/", "//jackrabbit.apache.org/jackrabbit/"});
+
+        for (Iterator it = l.iterator(); it.hasNext();) {
+            String[] strs = (String[]) it.next();
+            assertEquals(strs[1], Text.getName(strs[0], '='));
+        }
+    }
 }



Mime
View raw message