1 22 package org.jboss.net.protocol.http; 23 24 import java.io.IOException ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.List ; 30 31 import org.apache.commons.httpclient.HttpException; 32 import org.apache.commons.httpclient.HttpURL; 33 import org.apache.webdav.lib.WebdavResource; 34 import org.jboss.net.protocol.URLListerBase; 35 36 public class DavURLLister extends URLListerBase 37 { 38 public Collection listMembers (URL baseUrl, URLFilter filter) throws IOException 39 { 40 return listMembers (baseUrl, filter, false); 41 } 42 43 public Collection listMembers (URL baseUrl, URLFilter filter, boolean scanNonDottedSubDirs) throws IOException 44 { 45 WebdavResource resource = null; 46 try 47 { 48 resource = new WebdavResource (baseUrl.toString ()); 49 WebdavResource[] resources = resource.listWebdavResources (); 50 List urls = new ArrayList (resources.length); 51 for (int i = 0; i < resources.length; i++) 52 { 53 WebdavResource member = resources[i]; 54 HttpURL httpURL = member.getHttpURL (); 55 if (filter.accept (baseUrl, httpURL.getName ())) 56 { 57 String uri = httpURL.getURI(); 58 if (member.isCollection ()) 59 { 60 if (! uri.endsWith ("/")) 61 uri += "/"; 62 63 String path = httpURL.getPath(); 65 if (scanNonDottedSubDirs && getFilePartFromUrl(path).indexOf (".") == -1) 66 { 67 URL subUrl = new URL (uri) ; 68 urls.addAll (listMembers (subUrl, filter, scanNonDottedSubDirs)); 69 } 70 else 71 { 72 urls.add (new URL (uri)); 73 } 74 } 75 else 76 { 77 urls.add (new URL (uri)); 78 } 79 80 } 81 } 82 return urls; 83 } catch (HttpException e) 84 { 85 throw new IOException (e.getMessage ()); 86 } catch (MalformedURLException e) 87 { 88 throw new IllegalStateException (e.getMessage ()); 90 } finally 91 { 92 if (resource != null) 93 { 94 resource.close (); 95 } 96 } 97 } 98 99 protected static final String getFilePartFromUrl (String name) 100 { 101 int length = name.length (); 102 103 if (name.charAt (length - 1) == '/') 104 { 105 int start = name.lastIndexOf ("/", length - 2); 106 return name.substring (start, length -2); 107 } 108 else 109 { 110 int start = name.lastIndexOf ("/"); 111 return name.substring (start); 112 } 113 } 114 } 115 | Popular Tags |