KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > common > net > file > FileURLNavigationProvider


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.common.net.file;
10
11 import org.jboss.portal.common.net.URLNavigationProvider;
12 import org.jboss.portal.common.net.URLVisitor;
13 import org.apache.log4j.Logger;
14
15 import java.util.Iterator JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.io.File JavaDoc;
19
20 /**
21  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
22  * @version $Revision: 1.2 $
23  */

24 public class FileURLNavigationProvider implements URLNavigationProvider
25 {
26
27    /** The logger. */
28    private Logger log = Logger.getLogger(FileURLNavigationProvider.class);
29
30    public boolean isDir(URL JavaDoc url) throws IllegalArgumentException JavaDoc
31    {
32       throw new UnsupportedOperationException JavaDoc("todo");
33    }
34
35    public Iterator JavaDoc getChildren(URL JavaDoc url)
36    {
37       throw new UnsupportedOperationException JavaDoc("todo");
38    }
39
40    public void visit(URL JavaDoc url, URLVisitor visitor) throws IllegalArgumentException JavaDoc, IOException JavaDoc
41    {
42       File JavaDoc file = new File JavaDoc(url.getFile());
43       String JavaDoc name = file.getName();
44       if (file.isDirectory())
45       {
46          visitor.startDir(name);
47          File JavaDoc[] childrenFiles = file.listFiles();
48          for (int i = 0; i < childrenFiles.length; i++)
49          {
50             File JavaDoc childFile = childrenFiles[i];
51             URL JavaDoc childURL = childFile.toURL();
52             visit(childURL, visitor);
53          }
54          visitor.endDir(name);
55       }
56       else
57       {
58          visitor.file(name, url);
59       }
60    }
61 }
62
Popular Tags