KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > resolver > FileURLLister


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.resolver;
7
8 import java.io.File JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.net.URL JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.List JavaDoc;
14
15
16 public class FileURLLister implements URLLister {
17     private File JavaDoc _basedir;
18
19     public FileURLLister() {
20         this(null);
21     }
22     public FileURLLister(File JavaDoc baseDir) {
23         _basedir = baseDir;
24     }
25
26     public boolean accept(String JavaDoc pattern) {
27         return pattern.startsWith("file");
28     }
29
30     public List JavaDoc listAll(URL JavaDoc url) throws IOException JavaDoc {
31         String JavaDoc path = url.getPath();
32         File JavaDoc file = _basedir == null ? new File JavaDoc(path) : new File JavaDoc(_basedir, path);
33         if (file.exists() && file.isDirectory()) {
34             String JavaDoc[] files = file.list();
35             List JavaDoc ret = new ArrayList JavaDoc(files.length);
36             URL JavaDoc context = url.getPath().endsWith("/") ? url : new URL JavaDoc(url.toExternalForm()+"/");
37             for (int i = 0; i < files.length; i++) {
38                 ret.add(new URL JavaDoc(context, files[i]));
39             }
40             return ret;
41         } else {
42             return Collections.EMPTY_LIST;
43         }
44     }
45     
46     public String JavaDoc toString() {
47         return "file lister";
48     }
49 }
50
Popular Tags