42 * called with a {@code String} giving the MIME type of the |
42 * called with a {@code String} giving the MIME type of the |
43 * object being received on the socket. The factory returns an |
43 * object being received on the socket. The factory returns an |
44 * instance of a subclass of {@code ContentHandler}, and its |
44 * instance of a subclass of {@code ContentHandler}, and its |
45 * {@code getContent} method is called to create the object. |
45 * {@code getContent} method is called to create the object. |
46 * <p> |
46 * <p> |
47 * If no content handler could be found, URLConnection will |
47 * If no content handler could be {@linkplain URLConnection#getContent() found}, |
48 * look for a content handler in a user-defineable set of places. |
48 * URLConnection will look for a content handler in a user-definable set of places. |
49 * Users can define a vertical-bar delimited set of class prefixes |
49 * Users can define a vertical-bar delimited set of class prefixes |
50 * to search through by defining the <i>java.content.handler.pkgs</i> |
50 * to search through by defining the <i>{@value java.net.URLConnection#contentPathProp}</i> |
51 * property. The class name must be of the form: |
51 * property. The class name must be of the form: |
52 * <blockquote> |
52 * <blockquote> |
53 * <i>{package-prefix}.{major}.{minor}</i> |
53 * <i>{package-prefix}.{major}.{minor}</i> |
54 * <P> |
54 * <p> |
55 * where <i>{major}.{minor}</i> is formed by taking the |
55 * where <i>{major}.{minor}</i> is formed by taking the |
56 * content-type string, replacing all slash characters with a |
56 * content-type string, replacing all slash characters with a |
57 * {@code period} ('.'), and all other non-alphanumeric characters |
57 * {@code period} ('.'), and all other non-alphanumeric characters |
58 * with the underscore character '{@code _}'. The alphanumeric |
58 * with the underscore character '{@code _}'. The alphanumeric |
59 * characters are specifically the 26 uppercase ASCII letters |
59 * characters are specifically the 26 uppercase ASCII letters |
80 * @see java.net.URLConnection#getContent() |
80 * @see java.net.URLConnection#getContent() |
81 * @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory) |
81 * @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory) |
82 * @since 1.0 |
82 * @since 1.0 |
83 */ |
83 */ |
84 abstract public class ContentHandler { |
84 abstract public class ContentHandler { |
|
85 |
85 /** |
86 /** |
86 * Given a URL connect stream positioned at the beginning of the |
87 * Given a URL connect stream positioned at the beginning of the |
87 * representation of an object, this method reads that stream and |
88 * representation of an object, this method reads that stream and |
88 * creates an object from it. |
89 * creates an object from it. |
89 * |
90 * |
102 * and screen the return type for a match of the suggested types. |
103 * and screen the return type for a match of the suggested types. |
103 * |
104 * |
104 * @param urlc a URL connection. |
105 * @param urlc a URL connection. |
105 * @param classes an array of types requested |
106 * @param classes an array of types requested |
106 * @return the object read by the {@code ContentHandler} that is |
107 * @return the object read by the {@code ContentHandler} that is |
107 * the first match of the suggested types. |
108 * the first match of the suggested types or |
108 * null if none of the requested are supported. |
109 * {@code null} if none of the requested are supported. |
109 * @exception IOException if an I/O error occurs while reading the object. |
110 * @exception IOException if an I/O error occurs while reading the object. |
110 * @since 1.3 |
111 * @since 1.3 |
111 */ |
112 */ |
112 @SuppressWarnings("rawtypes") |
113 @SuppressWarnings("rawtypes") |
113 public Object getContent(URLConnection urlc, Class[] classes) throws IOException { |
114 public Object getContent(URLConnection urlc, Class[] classes) throws IOException { |
114 Object obj = getContent(urlc); |
115 Object obj = getContent(urlc); |
115 |
116 |
116 for (int i = 0; i < classes.length; i++) { |
117 for (Class<?> c : classes) { |
117 if (classes[i].isInstance(obj)) { |
118 if (c.isInstance(obj)) { |
118 return obj; |
119 return obj; |
119 } |
120 } |
120 } |
121 } |
121 return null; |
122 return null; |
122 } |
123 } |
123 |
|
124 } |
124 } |