@return A Path selector that matches the given root path and any resource below it.

@param rootPath path to match
160367
public static PathSelector subpathSelector(final Path rootPath) {
        return new PathSelector() {
            @Override
            public boolean matchesPath(Path path) {
                return path.equals(rootPath) || PathUtil.hasRoot(path, rootPath);
            }
        };
    }
873148
public static boolean isPluginResoucePath(String resourcePath) {

		Matcher matcher = PLUGIN_RESOURCE_PATTERN.matcher(resourcePath);
		return matcher.find();
	}
167599
public String getRootPath(Resource resource) {
    int rootLevel = urlHandlerConfig.getSiteRootLevel(resource);
    if (rootLevel > 0) {
      return Path.getAbsoluteParent(resource.getPath(), rootLevel, resource.getResourceResolver());
    }
    return null;
  }
1304832
protected String getRelativePath(String ancestor, String rootPath) {

        String result = rootPath.substring(ancestor.length());
        result = CmsStringUtil.joinPaths("/", result, "/");
        return result;
    }
1003208
public static String getParentFolderTokens(String rootPath) {

        if (CmsStringUtil.isEmpty(rootPath)) {
            return "/";
        }
        StringBuffer result = new StringBuffer(128);
        String folderName = CmsResource.getFolderPath(rootPath);
        for (int i = 0; i < folderName.length(); i++) {
            char c = folderName.charAt(i);
            if (c == '/') {
                if (result.length() > 0) {
                    result.append(' ');
                }
                result.append(folderName.substring(0, i + 1));
            }
        }
        return result.toString();
    }
29709
public static String subPath(String rootDir, File file) {
		try {
			return subPath(rootDir, file.getCanonicalPath());
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
416640
static public String getPathToRoot(JBakeConfiguration config, File rootPath, File sourceFile) {

        Path r = Paths.get(rootPath.toURI());
        Path s = Paths.get(sourceFile.getParentFile().toURI());
        Path relativePath = s.relativize(r);

        StringBuilder sb = new StringBuilder();

        sb.append(asPath(relativePath.toString()));

        if (config.getUriWithoutExtension()) {
            sb.append("/..");
        }
        if (sb.length() > 0) {  // added as calling logic assumes / at end.
            sb.append("/");
        }
        return sb.toString();
    }
663364
private String getCommonAncestorPath(String rootPath1, String rootPath2) {

        if (rootPath1 == null) {
            return rootPath2;
        }
        if (rootPath2 == null) {
            return rootPath1;
        }
        rootPath1 = CmsStringUtil.joinPaths("/", rootPath1, "/");
        rootPath2 = CmsStringUtil.joinPaths("/", rootPath2, "/");
        int minLength = Math.min(rootPath1.length(), rootPath2.length());
        int i;
        for (i = 0; i < minLength; i++) {
            char char1 = rootPath1.charAt(i);
            char char2 = rootPath2.charAt(i);
            if (char1 != char2) {
                break;
            }
        }
        String result = rootPath1.substring(0, i);
        if ("/".equals(result)) {
            return result;
        }
        int slashIndex = result.lastIndexOf('/');
        result = result.substring(0, slashIndex);
        return result;
    }
740081
public static FileStatus getRootFileStatus(Path rootPath) {
        return new FileStatus(0, true, 1, 1024, -1, -1, DIRECTORY_PERMISSION, null, null, rootPath);
    }
497345
public static <T> TreePath findPathFromEnclosingNodeToTopLevel(TreePath path, Class<T> klass) {
    if (path != null) {
      do {
        path = path.getParentPath();
      } while (path != null && !(klass.isInstance(path.getLeaf())));
    }
    return path;
  }
1016169
@Override
	public String getFilePath(String resourcePath) {
		return helper.getFilePath(resolver.getResourcePath(resourcePath));
	}
148860
public static String getRelativeNodePath(String basePath, String targetPath) {

		// Both paths are equal
		if (basePath.equals(targetPath)) {

			return ".";

		}

		if (basePath.equals(PATH_SEP) && (targetPath.length() > 1)) {

			// Base path is root path
			return targetPath.substring(1);
		}

		String[] baseAncestors   = FilenameUtils.normalizeNoEndSeparator(basePath).split(PATH_SEP);
		String[] targetAncestors = FilenameUtils.normalizeNoEndSeparator(targetPath).split(PATH_SEP);
		int length               = (baseAncestors.length < targetAncestors.length)
					   ? baseAncestors.length
					   : targetAncestors.length;
		int lastCommonRoot       = -1;
		int i;

		// Iterate over the shorter path
		for (i = 0; i < length; i++) {

			if (baseAncestors[i].equals(targetAncestors[i])) {

				lastCommonRoot = i;

			} else {

				break;

			}

		}

		// Last common root is the common base path
		if (lastCommonRoot != -1) {

			StringBuilder newRelativePath = new StringBuilder();

			// How often must we go back from base path to common root?
			for (i = lastCommonRoot + 1; i < baseAncestors.length; i++) {

				if (baseAncestors[i].length() > 0) {

					newRelativePath.append(".." + PATH_SEP);

				}

			}

			// How often must we go forth from common root to get to tagret path?
			for (i = lastCommonRoot + 1; i < targetAncestors.length; i++) {

				newRelativePath.append(targetAncestors[i]).append(PATH_SEP);

			}

			// newRelativePath.append(targetAncestors[targetAncestors.length - 1]);
			String result = newRelativePath.toString();

			if (result.endsWith(PATH_SEP)) {

				result = result.substring(0, result.length() - 1);

			}

			return result;

		}

		return targetPath;
	}
280827
public boolean matches(String resourcePath) {
    if (!valid) {
      return false;
    }
    if (resourcePath == null) {
      return acceptsContextPathEmpty;
    }
    if (contextPathRegex != null && !contextPathRegex.matcher(resourcePath).matches()) {
      return false;
    }
    if (contextPathBlacklistRegex != null && contextPathBlacklistRegex.matcher(resourcePath).matches()) {
      return false;
    }
    return true;
  }
1240978
public static String findRootInstancePath( String scopedInstancePath ) {

		String result;
		if( Utils.isEmptyOrWhitespaces( scopedInstancePath )) {
			// Do not return null
			result = "";

		} else if( scopedInstancePath.contains( "/" )) {
			// Be as flexible as possible with paths
			String s = scopedInstancePath.replaceFirst( "^/*", "" );
			int index = s.indexOf( '/' );
			result = index > 0 ? s.substring( 0, index ) : s;

		} else {
			// Assumed to be a root instance name
			result = scopedInstancePath;
		}

		return result;
	}
1350408
public String fixPathInfo(String path)
    {
        if (path == null)
            return null;
        if (path.startsWith("/"))
            path = path.substring(1);   // Resources already start from root/baseURL
        if (baseURL == null)
            if (properties != null)
                if (this.getProperty(BASE_PATH) != null)
                    path = this.getProperty(BASE_PATH) + path;
        return path;
    }
374358
public static String getAbsolutePath(String classPath) {
        URL configUrl = Thread.currentThread().getContextClassLoader().getResource(classPath.substring(1));
        if (configUrl == null) {
            configUrl = ResourceUtil.class.getResource(classPath);
        }
        if (configUrl == null) {
            return null;
        }
        try {
            return configUrl.toURI().getPath();
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
497919
public String getSelectPath(CmsSitemapEntryBean sitemapEntry) {

        String normalizedSiteRoot = CmsStringUtil.joinPaths(CmsCoreProvider.get().getSiteRoot(), "/");
        String rootPath = sitemapEntry.getRootPath();
        if (rootPath.startsWith(normalizedSiteRoot)) {
            return rootPath.substring(normalizedSiteRoot.length() - 1);
        }
        return sitemapEntry.getRootPath();
    }