/** * Map containing path and name given a path * * @param path path * * @return map */ private Map<String, String> authResForPath(Path path) { HashMap<String, String> authResource = new HashMap<String, String>(); authResource.put(PATH_RES_KEY, path.getPath()); authResource.put(NAME_RES_KEY, path.getName()); return authResource; }
private String translatePathInternal(String extpath) { if (fullPath) { return extpath; } else { return PathUtil.removePrefix(rootPath.getPath(), extpath); } }
private Map<String, Resource<T>> asMap(Set<Resource<T>> matchedList) { HashMap<String, Resource<T>> map = new HashMap<>(); for (Resource<T> tResource : matchedList) { map.put(tResource.getPath().getPath(), tResource); } return map; }
/** * @param path path * @return path components */ public static String[] componentsFromPath(final Path path) { return componentsFromPathString(path.getPath()); }
/** * convert internal path to external * * @param intpath * * @return */ private String translatePathExternal(String intpath) { if (fullPath) { return intpath; } else { return PathUtil.appendPath(rootPath.getPath(), intpath); } }
private void validatePaths(final List<? extends SelectiveTree<T>> treeHandlerList) { HashSet<String> paths = new HashSet<>(); for (SelectiveTree<T> tSelectiveTree : treeHandlerList) { if (!paths.contains(tSelectiveTree.getSubPath().getPath())) { paths.add(tSelectiveTree.getSubPath().getPath()); } else { throw new IllegalArgumentException(String.format( "Cannot create TreeStack: multiple subpaths defined for: %s", tSelectiveTree.getSubPath() )); } } }
/** * Generate the environment for a path, based on the convention that /project/name/* maps to a project called * "name", and anything else is within the application environment. * * @param path path * * @return authorization environment: a project environment if the path matches /project/name/*, otherwise the * application environment */ Set<Attribute> environmentForPath(Path path) { String[] paths = path.getPath().split("/"); if (paths != null && paths.length > 2 && paths[0].equals(PROJECT_PATH_COMPONENT)) { return FrameworkProject.authorizationEnvironment(paths[1]); } else { return Framework.RUNDECK_APP_ENV; } }
/** * @return true if the given path starts with the given root * * @param path test path * @param root root */ public static boolean hasRoot(String path, String root) { String p = cleanPath(path); String r = cleanPath(root); return p.equals(r) || r.equals(cleanPath(ROOT.getPath())) || p.startsWith(r + SEPARATOR); }
private Path translatePathInternal(Path extpath) { return PathUtil.asPath(translatePathInternal(extpath.getPath())); }
/** * Append one path to another * * @param prefix prefix * @param subpath sub path * * @return sub path appended to the prefix */ public static Path appendPath(Path prefix, String subpath) { return asPath(appendPath(prefix.getPath(), subpath)); }
private DirRes<T> createParentPaths(Path path) { String[] split = path.getPath().split("/"); DirRes<T> current = root; Path currentPath = PathUtil.asPath(""); for (int i = 0; i < split.length - 1; i++) { currentPath = PathUtil.appendPath(currentPath, split[i]); if (!index.containsKey(currentPath)) { DirRes<T> newDir = new DirRes<T>(currentPath); newDir.dir = true; current.dirList.put(currentPath, newDir); index.put(currentPath, newDir); current = newDir; } else { current = index.get(currentPath); } } return current; }
private Path translatePathExternal(Path extpath) { return PathUtil.asPath(translatePathExternal(extpath.getPath())); }
public static Path parentPath(Path path) { return asPath(parentPathString(path.getPath())); }
/** * 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; }