1 |
/* ContentHandler.java -- Abstract class for handling content from URL's |
/* ContentHandler.java -- Abstract class for handling content from URL's |
2 |
Copyright (C) 1998, 1999 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
59 |
*/ |
*/ |
60 |
public abstract class ContentHandler |
public abstract class ContentHandler |
61 |
{ |
{ |
62 |
|
/* |
63 |
|
* Constructors |
64 |
|
*/ |
65 |
|
|
66 |
|
/** |
67 |
|
* Default, no-argument constructor. |
68 |
|
*/ |
69 |
|
public ContentHandler() |
70 |
|
{ |
71 |
|
} |
72 |
|
|
73 |
|
/* |
74 |
|
* Instance Methods |
75 |
|
*/ |
76 |
|
|
77 |
|
/** |
78 |
|
* This method reads from the <code>InputStream</code> of the passed in URL |
79 |
|
* connection and uses the data downloaded to create an <code>Object</code> |
80 |
|
* represening the content. For example, if the URL is pointing to a GIF |
81 |
|
* file, this method might return an <code>Image</code> object. This method |
82 |
|
* must be implemented by subclasses. |
83 |
|
* |
84 |
|
* @param urlc A <code>URLConnection</code> object to read data from. |
85 |
|
* |
86 |
|
* @return An object representing the data read |
87 |
|
* |
88 |
|
* @exception IOException If an error occurs |
89 |
|
*/ |
90 |
|
public abstract Object getContent(URLConnection urlc) |
91 |
|
throws IOException; |
92 |
|
|
93 |
|
/** |
94 |
|
* This method reads from the <code>InputStream</code> of the passed in URL |
95 |
|
* connection and uses the data downloaded to create an <code>Object</code> |
96 |
|
* represening the content. For example, if the URL is pointing to a GIF |
97 |
|
* file, this method might return an <code>Image</code> object. This method |
98 |
|
* must be implemented by subclasses. This method uses the list of |
99 |
|
* supplied classes as candidate types. If the data read doesn't match |
100 |
|
* any of the supplied type, <code>null</code> is returned. |
101 |
|
* |
102 |
|
* @param urlc A <code>URLConnection</code> object to read data from. |
103 |
|
* @param classes An array of types of objects that are candidate types |
104 |
|
* for the data to be read. |
105 |
|
* |
106 |
|
* @return An object representing the data read, or <code>null</code> |
107 |
|
* if the data does not match any of the candidate types. |
108 |
|
* |
109 |
|
* @exception IOException If an error occurs |
110 |
|
* |
111 |
|
* @since 1.3 |
112 |
|
*/ |
113 |
|
public Object getContent(URLConnection urlc, Class[] classes) |
114 |
|
throws IOException |
115 |
|
{ |
116 |
|
Object obj = getContent (urlc); |
117 |
|
|
118 |
|
for (int i = 0; i < classes.length; i++) |
119 |
|
{ |
120 |
|
if (classes [i].isInstance (obj)) |
121 |
|
return obj; |
122 |
|
} |
123 |
|
|
124 |
/*************************************************************************/ |
return null; |
125 |
|
} |
|
/* |
|
|
* Constructors |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* Default, no-argument constructor. |
|
|
*/ |
|
|
public ContentHandler() { } |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method reads from the <code>InputStream</code> of the passed in URL |
|
|
* connection and uses the data downloaded to create an <code>Object</code> |
|
|
* represening the content. For example, if the URL is pointing to a GIF |
|
|
* file, this method might return an <code>Image</code> object. This method |
|
|
* must be implemented by subclasses. |
|
|
* |
|
|
* @param urlc A <code>URLConnection</code> object to read data from. |
|
|
* |
|
|
* @return An object representing the data read |
|
|
* |
|
|
* @exception IOException If an error occurs |
|
|
*/ |
|
|
public abstract Object getContent(URLConnection urlc) throws IOException; |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method reads from the <code>InputStream</code> of the passed in URL |
|
|
* connection and uses the data downloaded to create an <code>Object</code> |
|
|
* represening the content. For example, if the URL is pointing to a GIF |
|
|
* file, this method might return an <code>Image</code> object. This method |
|
|
* must be implemented by subclasses. If the object doesnt match any type in |
|
|
* classes it returns null. |
|
|
* |
|
|
* @param urlc A <code>URLConnection</code> object to read data from. |
|
|
* |
|
|
* @return An object representing the data read |
|
|
* |
|
|
* @exception IOException If an error occurs |
|
|
* |
|
|
* @since 1.3 |
|
|
*/ |
|
|
public Object getContent(URLConnection urlc, Class[] classes) |
|
|
throws IOException |
|
|
{ |
|
|
Object obj = getContent (urlc); |
|
|
|
|
|
for (int i = 0; i < classes.length; i++) |
|
|
{ |
|
|
if (classes [i].isInstance (obj)) |
|
|
return obj; |
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
126 |
|
|
127 |
} // class ContentHandler |
} // class ContentHandler |