Element getElement(PseudoPath path) { Element currentElement = fileTree; for (int i = 0; i < path.getNameCount(); i++) { currentElement = getChildByName(currentElement, path.getName(i)); if (currentElement == null) return null; } return currentElement; }
public synchronized void addFile(PseudoPath path) { if (path.equals(new PseudoPath())) { throw new IllegalArgumentException("Adding empty path does not allowed."); } PseudoPath parent = path.getParent(); Element parentElement = getElement(parent); if (parentElement == null) { throw new IllegalArgumentException("Parent directory does not exist."); } else { Element childElement = new Element(FileType.FILE.getName()); String filename = path.getName(path.getNameCount() - 1); childElement.addAttribute(new Attribute("name", filename)); parentElement.appendChild(childElement); } }