/** * Initialize the TokenizedPath by parsing it. * @param path The path to tokenize. Must not be * <code>null</code>. */ public TokenizedPath(String path) { this(path, SelectorUtils.tokenizePathAsArray(path)); }
/** * Initialize the PathPattern by parsing it. * @param pattern The pattern to match against. Must not be * <code>null</code>. */ public TokenizedPattern(String pattern) { this(pattern, SelectorUtils.tokenizePathAsArray(pattern)); }
/** * Tests whether or not a given path matches a given pattern. * * If you need to call this method multiple times with the same * pattern you should rather use TokenizedPath * * @see TokenizedPath * * @param pattern The pattern to match against. Must not be * <code>null</code>. * @param str The path to match, as a String. Must not be * <code>null</code>. * * @return <code>true</code> if the pattern matches against the string, * or <code>false</code> otherwise. */ public static boolean matchPath(String pattern, String str) { String[] patDirs = tokenizePathAsArray(pattern); return matchPath(patDirs, tokenizePathAsArray(str), true); }
/** * Tests whether or not a given path matches a given pattern. * * If you need to call this method multiple times with the same * pattern you should rather use TokenizedPattern * * @see TokenizedPattern * * @param pattern The pattern to match against. Must not be * <code>null</code>. * @param str The path to match, as a String. Must not be * <code>null</code>. * @param isCaseSensitive Whether or not matching should be performed * case sensitively. * * @return <code>true</code> if the pattern matches against the string, * or <code>false</code> otherwise. */ public static boolean matchPath(String pattern, String str, boolean isCaseSensitive) { String[] patDirs = tokenizePathAsArray(pattern); return matchPath(patDirs, tokenizePathAsArray(str), isCaseSensitive); }
String[] patDirs = tokenizePathAsArray(pattern); String[] strDirs = tokenizePathAsArray(str); return matchPatternStart(patDirs, strDirs, isCaseSensitive);
/** * From <code>base</code> traverse the filesystem in order to find * a file that matches the given name. * * @param base base File (dir). * @param cs whether to scan case-sensitively. * @return File object that points to the file in question or null. */ public File findFile(File base, final boolean cs) { String[] tokens = tokenizedPath; if (FileUtils.isAbsolutePath(path)) { if (base == null) { String[] s = FILE_UTILS.dissect(path); base = new File(s[0]); tokens = SelectorUtils.tokenizePathAsArray(s[1]); } else { File f = FILE_UTILS.normalize(path); String s = FILE_UTILS.removeLeadingPath(base, f); if (s.equals(f.getAbsolutePath())) { //removing base from path yields no change; path //not child of base return null; } tokens = SelectorUtils.tokenizePathAsArray(s); } } return findFile(base, tokens, cs); }