jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r683403 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Date Wed, 06 Aug 2008 20:56:22 GMT
Author: tripod
Date: Wed Aug  6 13:56:21 2008
New Revision: 683403

URL: http://svn.apache.org/viewvc?rev=683403&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

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=683403&r1=683402&r2=683403&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
Wed Aug  6 13:56:21 2008
@@ -509,26 +509,35 @@
     }
 
     /**
-     * Returns the name part of the path
+     * Returns the name part of the path. If the given path is already a name
+     * (i.e. contains no slashes) it is returned.
      *
      * @param path the path
-     * @return the name part
+     * @return the name part or <code>null</code> if <code>path</code>
is <code>null</code>.
      */
     public static String getName(String path) {
-        int pos = path.lastIndexOf('/');
-        return pos >= 0 ? path.substring(pos + 1) : "";
+        if (path == null) {
+            return null;
+        } else {
+            return path.substring(path.lastIndexOf('/'));
+        }
     }
 
     /**
-     * Returns the name part of the path, delimited by the given <code>delim</code>
+     * Returns the name part of the path, delimited by the given <code>delim</code>.
+     * If the given path is already a name (i.e. contains no <code>delim</code>
+     * characters) it is returned.
      *
      * @param path the path
      * @param delim the delimiter
-     * @return the name part
+     * @return the name part or <code>null</code> if <code>path</code>
is <code>null</code>.
      */
     public static String getName(String path, char delim) {
-        int pos = path.lastIndexOf(delim);
-        return pos >= 0 ? path.substring(pos + 1) : "";
+        if (path == null) {
+            return null;
+        } else {
+            return path.substring(path.lastIndexOf(delim));
+        }
     }
 
     /**
@@ -538,7 +547,7 @@
      * @see #getName(String)
      */
     public static String getName(String path, boolean ignoreTrailingSlash) {
-        if (ignoreTrailingSlash && path.endsWith("/") && path.length() >
1) {
+        if (ignoreTrailingSlash && path != null && path.endsWith("/") &&
path.length() > 1) {
             path = path.substring(0, path.length()-1);
         }
         return getName(path);



Mime
View raw message