public static String pathName(String path) { String[] split = componentsFromPathString(path); if (split.length > 0) { return split[split.length - 1]; } return null; }
/** * @param path path * @return path components */ public static String[] componentsFromPath(final Path path) { return componentsFromPathString(path.getPath()); }
/** * Return the string representing the parent of the given path * @param path path string * @return parent path string */ public static String parentPathString(String path) { String[] split = componentsFromPathString(path); if (split.length > 1) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < split.length - 1; i++) { if (i > 0) { stringBuilder.append(SEPARATOR); } stringBuilder.append(split[i]); } return stringBuilder.toString(); } return ""; }
/** * List all treeHandlers as directories which have the given path as a parent * @param path path * @return */ private Set<Resource<T>> listStackDirectory(Path path) { HashSet<Resource<T>> merge = new HashSet<Resource<T>>(); if (treeHandlerList.size() > 0) { for (SelectiveTree<T> treeHandler : treeHandlerList) { if (PathUtil.hasRoot(treeHandler.getSubPath(), path) && !PathUtil.equals( treeHandler.getSubPath(), path )) { String relativePath = PathUtil.removePrefix(path.getPath(), treeHandler.getSubPath().getPath()); String[] components = PathUtil.componentsFromPathString(relativePath); Path subpath = PathUtil.appendPath(path, components[0]); merge.add(new ResourceBase<T>(subpath, null, true)); } } } return merge; }