public static String getParentFolder(String resource) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(resource) || "/".equals(resource)) {
            return null;
        }
        // remove the last char, for a folder this will be "/", for a file it does not matter
        String parent = (resource.substring(0, resource.length() - 1));
        // now as the name does not end with "/", check for the last "/" which is the parent folder name
        return parent.substring(0, parent.lastIndexOf('/') + 1);
    }
public static String getParentFolder ( String resource ) { if ( CmsStringUtil . isEmptyOrWhitespaceOnly ( resource ) || "/" . equals ( resource ) ) { return null ; } String parent = ( resource . substring ( 0 , resource . length ( ) - 1 ) ) ; return parent . substring ( 0 , parent . lastIndexOf ( '/' ) + 1 ) ; }
Returns the absolute parent folder name of a resource.<p>

The parent resource of a file is the folder of the file.
The parent resource of a folder is the parent folder.
The parent resource of the root folder is <code>null</code>.<p>

Example: <code>/system/workplace/</code> has the parent <code>/system/</code>.

@param resource the resource to find the parent folder for
@return the calculated parent absolute folder path, or <code>null</code> for the root folder