/** Traverse a path from a parent node down, by an enumeration of names. * @param start node to start searching at * @param names enumeration of names of nodes * along the path * @return the node with such a path from the start node * @exception NodeNotFoundException if the node with such name * does not exists; the exception contains additional information * about the failure. */ public static Node findPath(Node start, Enumeration<String> names) throws NodeNotFoundException { int depth = 0; while (names.hasMoreElements()) { String name = names.nextElement(); Node next = findChild(start, name); if (next == null) { // no element in list matched the name => fail // fire exception with the last accessed node and the // name of child that does not exists throw new NodeNotFoundException(start, name, depth); } else { // go on next node start = next; } // continue on next depth depth++; } return start; }
private Node findPathPlain(FileObject fo, FileObject groupRoot, Node rootNode) { FileObject folder = fo.isFolder() ? fo : fo.getParent(); String relPath = FileUtil.getRelativePath(groupRoot, folder); List<String> path = new ArrayList<String>(); StringTokenizer strtok = new StringTokenizer(relPath, "/"); // NOI18N while (strtok.hasMoreTokens()) { String token = strtok.nextToken(); path.add(token); } try { Node folderNode = folder.equals(groupRoot) ? rootNode : NodeOp.findPath(rootNode, Collections.enumeration(path)); if (fo.isFolder()) { return folderNode; } else { Node[] childs = folderNode.getChildren().getNodes(true); for (int i = 0; i < childs.length; i++) { DataObject dobj = childs[i].getLookup().lookup(DataObject.class); if (dobj != null && dobj.getPrimaryFile().getNameExt().equals(fo.getNameExt())) { return childs[i]; } } } } catch (NodeNotFoundException e) { e.printStackTrace(); } return null; }
/** Finds node by given path */ static Node findPath(Node r, String[] path) { try { return NodeOp.findPath(r, path); } catch (NodeNotFoundException ex) { return ex.getClosestNode(); } }
System.out.println( e.getMissingChildName() );
/** Finds node by given path */ static Node findPath(Node r, String[] path) { try { return NodeOp.findPath(r, path); } catch (NodeNotFoundException ex) { return ex.getClosestNode(); } }
System.out.println( e.getMissingChildName() );
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode() throws java.io.IOException { Node parentNode = parent.getNode(); Node child = parentNode.getChildren().findChild(path); if (child != null) { return child; } else { throw new NodeNotFoundException(parentNode, path, 0); } }
/** Finds node by given path */ static Node findPath(Node r, String[] path) { try { return NodeOp.findPath(r, path); } catch (NodeNotFoundException ex) { return ex.getClosestNode(); } }
throw new NodeNotFoundException (start, name, depth); } else {
throw new NodeNotFoundException (start, name, depth); } else {
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode () throws java.io.IOException { Node parentNode = parent.getNode (); Node child = parentNode.getChildren ().findChild (path); if (child != null) return child; else throw new NodeNotFoundException (parentNode, path, 0); }
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode () throws java.io.IOException { Node parentNode = parent.getNode (); Node child = parentNode.getChildren ().findChild (path); if (child != null) return child; else throw new NodeNotFoundException (parentNode, path, 0); }