KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > node > NodeUtil


1 package org.enhydra.kelp.jbuilder.node;
2
3 import com.borland.jbuilder.node.JBProject;
4 import com.borland.primetime.node.Node;
5 import com.borland.primetime.vfs.Url;
6 import com.borland.primetime.vfs.VFS;
7 import com.borland.primetime.vfs.Filesystem;
8 import com.borland.primetime.node.FileNode;
9 import com.borland.primetime.node.FolderNode;
10 import com.borland.primetime.node.LightweightNode;
11
12 /**
13  * <p>Title: </p>
14  * <p>Description: </p>
15  * <p>Copyright: Copyright (c) 2003</p>
16  * <p>Company: </p>
17  * @author not attributable
18  * @version 1.0
19  */

20
21 public class NodeUtil {
22   /**
23    * Add needed FileNodes
24    *
25    * This routine finds all the files in the provided directory and adds
26    * them to the given project if they are not there already.
27    *
28    * @param jbProject Project where nodes are to be added.
29    * @param url Current directory to examine for subdirectories.
30    */

31   public static void doAddFiles(JBProject jbProject,
32                           Node parent,
33                           Url url) throws Exception JavaDoc {
34     Url[] urls = VFS.getChildren(url, Filesystem.TYPE_FILE);
35     if (urls.length > 0) {
36       for (int j = 0; j < urls.length; j++) {
37         if ((jbProject.findNode(urls[j]) == null)
38           && checkIfVisibleFile(urls[j])) {
39           FileNode node = new FileNode(jbProject, parent, urls[j]);
40         }
41       }
42     }
43   }
44
45   /**
46    * Recursively add needed files
47    *
48    * This routine uses recursive logic to locate all subdirectories under
49    * the given root directory and (if not already present) add a FileNodes
50    * for each of those subdirectories
51    *
52    * @param jbProject Project where nodes are to be added.
53    * @param rootDir Root directory of the recursive search.
54    * @param url Current directory to examine for subdirectories.
55    */

56   public static void doAddFolders(JBProject jbProject,
57                             Node parent,
58                             Url url) throws Exception JavaDoc {
59     FolderNode node = null;
60     LightweightNode nodes[] = jbProject.findNodes(url.getName());
61     for (int i = 0; i < nodes.length; i++) {
62       if (nodes[i].getParent() == parent) {
63         node = (FolderNode)nodes[i];
64       }
65     }
66     if (node == null)
67       node = new FolderNode(jbProject, parent, url.getName());
68
69     doAddFiles(jbProject, node, url);
70
71     Url[] urls = VFS.getChildren(url, Filesystem.TYPE_DIRECTORY);
72     if (urls.length > 0) {
73       for (int j = 0; j < urls.length; j++) {
74         doAddFolders(jbProject, node, urls[j]);
75       }
76     }
77   }
78
79     /**
80      * Check if visible file.
81      *
82      * This routine looks at the given file to determine if it should be made
83      * visible as a FileNode. Assume everything except backup files.
84      *
85      * @param url Directory to examine for files.
86      * @return Returns true if file should be made visible.
87      */

88     private static boolean checkIfVisibleFile(Url url) {
89       return (url.getFileObject().getAbsolutePath().endsWith("~") != true);
90     }
91
92 }
Popular Tags