/** * Get a child virtual file. The child may or may not exist in the virtual filesystem. * * @param path the path * @return the child * @throws IllegalArgumentException if the path is null */ public VirtualFile getChild(String path) { if (path == null) { throw VFSMessages.MESSAGES.nullArgument("path"); } final List<String> pathParts = PathTokenizer.getTokens(path); VirtualFile current = this; for (String part : pathParts) { if (PathTokenizer.isReverseToken(part)) { final VirtualFile parent = current.parent; current = parent == null ? current : parent; } else if (PathTokenizer.isCurrentToken(part) == false) { current = new VirtualFile(part, current); } } return current; }
/** * Apply any . or .. paths in the path param. * * @param path the path * @return simple path, containing no . or .. paths */ public static String applySpecialPaths(String path) throws IllegalArgumentException { List<String> tokens = getTokens(path); if (tokens == null) { return null; } int i = 0; for (int j = 0; j < tokens.size(); j++) { String token = tokens.get(j); if (isCurrentToken(token)) { continue; } else if (isReverseToken(token)) { i--; } else { tokens.set(i++, token); } if (i < 0) { throw VFSMessages.MESSAGES.onRootPath(); } } return getRemainingPath(tokens, 0, i); }
/** * Apply any . or .. paths in the pathTokens parameter, returning the minimal token list. * * @param pathTokens the path tokens * @return the simple path tokens * @throws IllegalArgumentException if reverse path goes over the top path */ public static List<String> applySpecialPaths(List<String> pathTokens) throws IllegalArgumentException { final ArrayList<String> newTokens = new ArrayList<String>(); for (String pathToken : pathTokens) { if (isCurrentToken(pathToken)) { continue; } else if (isReverseToken(pathToken)) { final int size = newTokens.size(); if (size == 0) { throw VFSMessages.MESSAGES.onRootPath(); } newTokens.remove(size - 1); } else { newTokens.add(pathToken); } } return newTokens; }
private Path(String path) { parts = new LinkedList<String>(); List<String> tokens = PathTokenizer.getTokens(path); parts.addAll(tokens); }
/** * Get the remaining path from some tokens * * @param tokens the tokens * @param i the current location * @return the remaining path * @throws IllegalArgumentException for null tokens or i is out of range */ public static String getRemainingPath(List<String> tokens, int i) { if (tokens == null) { throw MESSAGES.nullArgument("tokens"); } return getRemainingPath(tokens, i, tokens.size()); }
private File buildFile(File contentsDir, String name) { List<String> tokens = PathTokenizer.getTokens(name); File currentFile = contentsDir; for(String token : tokens) { currentFile = new File(currentFile, token); } currentFile.getParentFile().mkdirs(); return currentFile; }
final String name = entry.getName(); final boolean isDirectory = entry.isDirectory(); final List<String> tokens = PathTokenizer.getTokens(name); ZipNode node = rootNode; final Iterator<String> it = tokens.iterator(); while (it.hasNext()) { String token = it.next(); if (PathTokenizer.isCurrentToken(token) || PathTokenizer.isReverseToken(token)) {
private Path(String path) { parts = new LinkedList<String>(); List<String> tokens = PathTokenizer.getTokens(path); parts.addAll(tokens); }
final ZipEntry zipEntry = entries.nextElement(); final String name = zipEntry.getName(); final List<String> tokens = PathTokenizer.getTokens(name); final Iterator<String> it = tokens.iterator(); File current = destDir; while (it.hasNext()) { String token = it.next(); if (PathTokenizer.isCurrentToken(token) || PathTokenizer.isReverseToken(token)) {
private File buildFile(File contentsDir, String name) { List<String> tokens = PathTokenizer.getTokens(name); File currentFile = contentsDir; for(String token : tokens) { currentFile = new File(currentFile, token); } currentFile.getParentFile().mkdirs(); return currentFile; }
final String name = entry.getName(); final boolean isDirectory = entry.isDirectory(); final List<String> tokens = PathTokenizer.getTokens(name); ZipNode node = rootNode; final Iterator<String> it = tokens.iterator(); while (it.hasNext()) { String token = it.next(); if (PathTokenizer.isCurrentToken(token) || PathTokenizer.isReverseToken(token)) {
private File buildFile(File contentsDir, String name) { List<String> tokens = PathTokenizer.getTokens(name); File currentFile = contentsDir; for (String token : tokens) { currentFile = new File(currentFile, token); } currentFile.getParentFile().mkdirs(); return currentFile; }
final String name = entry.getName(); final boolean isDirectory = entry.isDirectory(); final List<String> tokens = PathTokenizer.getTokens(name); ZipNode node = rootNode; final Iterator<String> it = tokens.iterator(); while (it.hasNext()) { String token = it.next(); if (PathTokenizer.isCurrentToken(token) || PathTokenizer.isReverseToken(token)) {
private File buildFile(File contentsDir, String name) { List<String> tokens = PathTokenizer.getTokens(name); File currentFile = contentsDir; for(String token : tokens) { currentFile = new File(currentFile, token); } currentFile.getParentFile().mkdirs(); return currentFile; }
final String name = entry.getName(); final boolean isDirectory = entry.isDirectory(); final List<String> tokens = PathTokenizer.getTokens(name); ZipNode node = rootNode; final Iterator<String> it = tokens.iterator(); while (it.hasNext()) { String token = it.next(); if (PathTokenizer.isCurrentToken(token) || PathTokenizer.isReverseToken(token)) {
/** * Get the tokens that comprise this path. * * @param path the path * @return the tokens or null if the path is empty * @throws IllegalArgumentException if the path is null */ public static List<String> getTokens(String path) { if (path == null) { throw MESSAGES.nullArgument("path"); } List<String> list = new ArrayList<String>(); getTokens(list, path); return list; }
private RegistryEntry find(VirtualFile file) { return find(PathTokenizer.getTokens(file.getPathName())); }
List<String> tokens = PathTokenizer.getTokens(resourceName); Node current = rootNode;
public void removeCache(VirtualFile root, String path) { Node<T> node = getNode(root); if (node != null) { List<String> tokens = PathTokenizer.getTokens(path); Node<T> child = findNode(0, tokens, node); if (child != null) { Node<T> parent = child.getParent(); if (parent != null) parent.removeChild(node); else // clear root flush(); } } }