1 9 package org.jboss.portal.common.net; 10 11 import org.jboss.portal.common.net.file.FileURLNavigationProvider; 12 import org.jboss.portal.common.net.jar.JarURLNavigationProvider; 13 14 import java.net.URL ; 15 import java.io.IOException ; 16 import java.util.Iterator ; 17 18 24 public class URLNavigator 25 { 26 27 private static final URLNavigationProvider fileNav = new FileURLNavigationProvider(); 28 29 private static final URLNavigationProvider jarNav = new JarURLNavigationProvider(); 30 31 public static boolean isDir(URL url) throws IllegalArgumentException , IOException 32 { 33 URLNavigationProvider provider = getProvider(url); 34 return provider.isDir(url); 35 } 36 37 public static Iterator getChildren(URL url) throws IllegalArgumentException , IOException 38 { 39 URLNavigationProvider provider = getProvider(url); 40 return provider.getChildren(url); 41 } 42 43 public static void visit(URL url, URLVisitor visitor) throws IllegalArgumentException , IOException 44 { 45 URLNavigationProvider provider = getProvider(url); 46 provider.visit(url, visitor); 47 } 48 49 56 private static URLNavigationProvider getProvider(URL url) throws IllegalArgumentException 57 { 58 if (url == null) 59 { 60 throw new IllegalArgumentException ("Null not accepted"); 61 } 62 String protocol = url.getProtocol(); 63 if ("file".equals(protocol)) 64 { 65 return fileNav; 66 } 67 else if ("jar".equals(protocol)) 68 { 69 return jarNav; 70 } 71 else 72 { 73 throw new IllegalArgumentException ("Not recognized " + protocol); 74 } 75 } 76 77 } 78 | Popular Tags |