jdk/src/share/classes/java/net/ContentHandler.java
author juh
Tue, 30 Jul 2013 11:04:19 -0700
changeset 19069 1d9cb0d080e3
parent 14342 8435a30053c1
child 20754 3d7b2fafc34b
permissions -rw-r--r--
8021833: javadoc cleanup in java.net Summary: <code> and <tt> converted to {@code }; package.html to package-info.java Reviewed-by: darcy, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
     2
 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    31
 * The abstract class {@code ContentHandler} is the superclass
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    32
 * of all classes that read an {@code Object} from a
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    33
 * {@code URLConnection}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * An application does not generally call the
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    36
 * {@code getContent} method in this class directly. Instead, an
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    37
 * application calls the {@code getContent} method in class
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    38
 * {@code URL} or in {@code URLConnection}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The application's content handler factory (an instance of a class that
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    40
 * implements the interface {@code ContentHandlerFactory} set
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    41
 * up by a call to {@code setContentHandler}) is
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    42
 * called with a {@code String} giving the MIME type of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * object being received on the socket. The factory returns an
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    44
 * instance of a subclass of {@code ContentHandler}, and its
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    45
 * {@code getContent} method is called to create the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * If no content handler could be found, URLConnection will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * look for a content handler in a user-defineable set of places.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * By default it looks in sun.net.www.content, but users can define a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * vertical-bar delimited set of class prefixes to search through in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * addition by defining the java.content.handler.pkgs property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The class name must be of the form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     {package-prefix}.{major}.{minor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     YoyoDyne.experimental.text.plain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * If the loading of the content handler class would be performed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * a classloader that is outside of the delegation chain of the caller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the JVM will need the RuntimePermission "getClassLoader".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @author  James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see     java.net.ContentHandler#getContent(java.net.URLConnection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see     java.net.ContentHandlerFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see     java.net.URL#getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see     java.net.URLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see     java.net.URLConnection#getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see     java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
abstract public class ContentHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Given a URL connect stream positioned at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * representation of an object, this method reads that stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * creates an object from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param      urlc   a URL connection.
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    78
     * @return     the object read by the {@code ContentHandler}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @exception  IOException  if an I/O error occurs while reading the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    abstract public Object getContent(URLConnection urlc) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Given a URL connect stream positioned at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * representation of an object, this method reads that stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * creates an object that matches one of the types specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * The default implementation of this method should call getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * and screen the return type for a match of the suggested types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param      urlc   a URL connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param      classes      an array of types requested
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    93
     * @return     the object read by the {@code ContentHandler} that is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *                 the first match of the suggested types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *                 null if none of the requested  are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @exception  IOException  if an I/O error occurs while reading the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
11362
02eae572563e 7125055: ContentHandler.getContent API changed in error
chegar
parents: 10596
diff changeset
    99
    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Object obj = getContent(urlc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          if (classes[i].isInstance(obj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}