/** * Prelozi adresar reprezentovany cestou na objekt typu Directory * * @param fs Souborovy system, ktery se ma pro preklad pouzit * @param path Cesta pro preklad * @return Vysledny adresar * @throws FileSystemException Pokud neni adresar nalezen */ public static Directory parseDirectory(FileSystem fs, String path) throws FileSystemException { Directory workDir; if (path.charAt(0) == Path.PATH_SEPARATOR.charAt(0)) { workDir = fs.getRootDirectory(); } else workDir = fs.getCurrentDirectory(); StringTokenizer st = new StringTokenizer(path, Path.PATH_SEPARATOR); start: while (st.hasMoreTokens()) { String nextDir = st.nextToken(); if (nextDir.equals("..") && (workDir.getParent() != null)) { workDir = workDir.getParent(); continue; } Iterator i = workDir.getIterator(); while (i.hasNext()) { FileSystemItem fsi = (FileSystemItem) i.next(); if ((fsi.getName().equals(nextDir))) { if (fsi instanceof Directory) { workDir = (Directory) fsi; continue start; } else if (fsi instanceof Link && (((Link) fsi).getTarget() instanceof Directory)) { workDir = (Directory) ((Link) fsi).getTarget(); continue start; } } } throw new FileSystemException("Directory not found"); } return workDir; }