Extract last part of a path
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / ContentUtils.java
index 2e101a0d6f51b825c7d2a1bf9f19f713deb33107..facb5933bf3ebe743ce99eeed8e57c300d0cb11b 100644 (file)
@@ -128,6 +128,16 @@ public class ContentUtils {
                        throw new IllegalArgumentException("Path " + path + " contains //");
        }
 
+       /** The last element of a path. */
+       public static String lastPathElement(String path) {
+               if (path.charAt(path.length() - 1) == '/')
+                       throw new IllegalArgumentException("Path " + path + " cannot end with '/'");
+               int index = path.lastIndexOf('/');
+               if (index < 0)
+                       return path;
+               return path.substring(index + 1);
+       }
+
        /*
         * DIRECTORY
         */