protected AbstractFileResolver(FileSystem fileSystem, Factory<PatternSet> patternSetFactory) { this.fileSystem = fileSystem; this.fileNormaliser = new FileNormaliser(fileSystem); this.fileNotationParser = FileOrUriNotationConverter.parser(fileSystem); this.patternSetFactory = patternSetFactory; }
private File normaliseUnixPathIgnoringCase(List<String> path) throws IOException { File current = File.listRoots()[0]; for (int pos = 0; pos < path.size(); pos++) { File child = findChildIgnoringCase(current, path.get(pos)); if (child == null) { current = new File(current, CollectionUtils.join(File.separator, path.subList(pos, path.size()))); break; } current = child; } return current; }
private List<String> splitAndNormalisePath(String filePath) { String[] segments = splitPath(filePath); List<String> path = new ArrayList<String>(segments.length); for (String segment : segments) { if (segment.equals("..")) { if (!path.isEmpty()) { path.remove(path.size() - 1); } } else if (!segment.equals(".") && segment.length() > 0) { path.add(segment); } } return path; }
String filePath = file.getPath(); List<String> path = null; if (isNormalisingRequiredForAbsolutePath(filePath)) { path = splitAndNormalisePath(filePath); String resolvedPath = CollectionUtils.join(File.separator, path); boolean needLeadingSeparator = File.listRoots()[0].getPath().startsWith(File.separator); path = splitAndNormalisePath(filePath); return normaliseUnixPathIgnoringCase(path); } catch (IOException e) { throw new UncheckedIOException(String.format("Could not normalize path for file '%s'.", file), e);
public File resolve(Object path, PathValidation validation) { File file = doResolve(path); file = fileNormaliser.normalise(file); validate(file, validation); return file; }