drools-eclipse/org.guvnor.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java
public static String getLastElement(URL url) {
        String file = url.getFile();
        int len = file.length();

        if (len == 0 || len == 1 && file.charAt(0) == '/') {
            return null;
        }

        int lastSlashIndex = -1;
        for (int i = len - 2; lastSlashIndex == -1 && i >= 0; --i) {
            if (file.charAt(i) == '/') {
                lastSlashIndex = i;
            }
        }

        boolean isDirectory = file.charAt(len - 1) == '/';
        if (lastSlashIndex == -1) {
            if (isDirectory)
                return file.substring(0, len - 1);
            return file;
        }
        if (isDirectory)
            return file.substring(lastSlashIndex + 1, len - 1);
        return file.substring(lastSlashIndex + 1, len);
    }
public static String getLastElement(URL url) {
        String file = url.getFile();
        int len = file.length();

        if (len == 0 || len == 1 && file.charAt(0) == '/') {
            return null;
        }

        int lastSlashIndex = -1;
        for (int i = len - 2; lastSlashIndex == -1 && i >= 0; --i) {
            if (file.charAt(i) == '/') {
                lastSlashIndex = i;
            }
        }

        boolean isDirectory = file.charAt(len - 1) == '/';
        if (lastSlashIndex == -1) {
            if (isDirectory)
                return file.substring(0, len - 1);
            return file;
        }
        if (isDirectory)
            return file.substring(lastSlashIndex + 1, len - 1);
        return file.substring(lastSlashIndex + 1, len);
    }
Returns the last element in the given URLs path, or <code>null</code>
if the URL is the root.
<table>
<caption>Example</caption>
<tr>
<th>Given URL</th>
<th>Last Element</th>
<tr>
<td>"http://hostname/"</td>
<td>null</td>
<tr>
<td>"http://hostname/folder/</td>
<td>folder</td>
<tr>
<td>"http://hostname/folder/file</td>
<td>file</td>
</table>
@param url a URL
@return    the last element in the given URLs path, or
<code>null</code> if the URL is the root