28 |
package gnu.inet.gopher; |
package gnu.inet.gopher; |
29 |
|
|
30 |
import java.io.IOException; |
import java.io.IOException; |
31 |
|
import java.net.ContentHandler; |
32 |
import java.net.UnknownServiceException; |
import java.net.UnknownServiceException; |
33 |
import java.net.URL; |
import java.net.URL; |
34 |
import java.net.URLConnection; |
import java.net.URLConnection; |
40 |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
41 |
* @version $Revision$ $Date$ |
* @version $Revision$ $Date$ |
42 |
*/ |
*/ |
43 |
public class GopherURLStreamHandler extends URLStreamHandler |
public class GopherContentHandler extends ContentHandler |
44 |
{ |
{ |
45 |
|
|
46 |
public Object getContent(URLConnection urlc) |
public Object getContent(URLConnection urlc) throws IOException |
47 |
throws IOException |
{ |
48 |
{ |
if (urlc instanceof GopherURLConnection) |
49 |
if (urlc instanceof GopherURLConnection) |
{ |
50 |
{ |
GopherURLConnection gurlc = (GopherURLConnection) urlc; |
51 |
GopherURLConnection gurlc = (GopherURLConnection)urlc; |
GopherConnection connection = gurlc.connection; |
52 |
GopherConnection connection = gurlc.connection; |
URL url = gurlc.getURL(); |
53 |
URL url = gurlc.getURL(); |
String dir = url.getPath(); |
54 |
String dir = url.getPath(); |
String filename = url.getPath(); |
55 |
String filename = url.getPath(); |
if (dir == null && filename == null) |
56 |
if (dir==null && filename==null) |
return connection.list(); |
57 |
return connection.list(); |
else |
58 |
else |
return gurlc.getInputStream(); |
59 |
return gurlc.getInputStream(); |
} |
60 |
} |
else |
61 |
else |
throw new UnknownServiceException(); |
62 |
throw new UnknownServiceException(); |
} |
|
} |
|
63 |
|
|
64 |
} |
} |