1 17 18 package org.apache.geronimo.system.url.file; 19 20 import java.io.File ; 21 import java.io.FileNotFoundException ; 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.net.URLConnection ; 25 import java.net.URLStreamHandler ; 26 27 import sun.net.www.ParseUtil; 28 29 34 public class Handler extends URLStreamHandler { 35 protected void parseURL(final URL url, final String s, final int i, final int j) { 36 super.parseURL(url, s.replace(File.separatorChar, '/'), i, j); 37 } 38 39 45 public URLConnection openConnection(final URL url) throws IOException { 46 String path = ParseUtil.decode(url.getPath()); 47 path = path.replace('/', File.separatorChar).replace('|', ':'); 48 File file = new File (path); 49 if (!file.exists()) { 50 throw new FileNotFoundException (file.toString()); 51 } 52 53 String hostname = url.getHost(); 55 if (hostname == null || 56 hostname.equals("") || 57 hostname.equals("~") || 58 hostname.equals("localhost") || 59 file.exists()) { 60 return new FileURLConnection(url, file); 61 } 62 63 throw new FileNotFoundException ("Invalid host specification: " + url); 64 } 65 } 66 | Popular Tags |