1 16 package scriptella.util; 17 18 import java.net.MalformedURLException ; 19 import java.net.URL ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.util.regex.Pattern ; 23 24 36 public class UrlPathTokenizer { 37 private static final Pattern SEPARATOR = Pattern.compile("\\s*(\\;|(\\:(?=[^/]{2})))\\s*"); 41 42 43 private final URL baseURL; 44 45 public UrlPathTokenizer(URL baseURL) { 46 this.baseURL = baseURL; 47 } 48 49 56 public URL [] split(String urls) throws MalformedURLException { 57 if (urls == null) { 58 throw new IllegalArgumentException ("urls cannot be null"); 59 } 60 String [] strings = SEPARATOR.split(urls); 61 List <URL > res = new ArrayList <URL >(strings.length); 62 for (String s : strings) { 63 String u = s.trim(); 64 if (u.length() > 0) { 65 res.add(new URL (baseURL, u)); 66 } 67 } 68 return res.toArray(new URL [res.size()]); 69 } 70 71 } 72 | Popular Tags |