src/java.base/share/classes/java/net/ContentHandler.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 54199 40296a51aeb0
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54199
diff changeset
     2
 * Copyright (c) 1995, 2019, 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
44601
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
    40
 * implements the interface {@code ContentHandlerFactory} set up by a call to
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
    41
 * {@link URLConnection#setContentHandlerFactory(ContentHandlerFactory)
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
    42
 * setContentHandlerFactory} is called with a {@code String} giving the
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
    43
 * MIME type of the 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>
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
    47
 * If no content handler could be {@linkplain URLConnection#getContent() found},
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
    48
 * URLConnection will look for a content handler in a user-definable set of places.
24260
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    49
 * Users can define a vertical-bar delimited set of class prefixes
54199
40296a51aeb0 8153508: ContentHandler API contains link to private contentPathProp
chegar
parents: 47216
diff changeset
    50
 * to search through by defining the <i>{@value java.net.URLConnection#contentPathProp}</i>
24260
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    51
 * property. The class name must be of the form:
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    52
 * <blockquote>
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    53
 *     <i>{package-prefix}.{major}.{minor}</i>
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
    54
 *     <p>
24260
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    55
 *     where <i>{major}.{minor}</i> is formed by taking the
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    56
 *     content-type string, replacing all slash characters with a
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    57
 *     {@code period} ('.'), and all other non-alphanumeric characters
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    58
 *     with the underscore character '{@code _}'. The alphanumeric
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    59
 *     characters are specifically the 26 uppercase ASCII letters
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    60
 *     '{@code A}' through '{@code Z}', the 26 lowercase ASCII
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    61
 *     letters '{@code a}' through '{@code z}', and the 10 ASCII
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    62
 *     digits '{@code 0}' through '{@code 9}'.
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    63
 *     <p>
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    64
 *     e.g.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     YoyoDyne.experimental.text.plain
24260
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    66
 * </blockquote>
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    67
 * If no user-defined content handler is found, then the system
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    68
 * tries to load a specific <i>content-type</i> handler from one
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    69
 * of the built-in handlers, if one exists.
55a72a7e0cf9 8039470: java.net Content Handler API incorrectly specifies implementation specific location of handler classes
chegar
parents: 20754
diff changeset
    70
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * If the loading of the content handler class would be performed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * a classloader that is outside of the delegation chain of the caller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the JVM will need the RuntimePermission "getClassLoader".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author  James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see     java.net.ContentHandler#getContent(java.net.URLConnection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see     java.net.ContentHandlerFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see     java.net.URL#getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see     java.net.URLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see     java.net.URLConnection#getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see     java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24260
diff changeset
    82
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32227
diff changeset
    84
public abstract class ContentHandler {
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Given a URL connect stream positioned at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * representation of an object, this method reads that stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * creates an object from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param      urlc   a URL connection.
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
    92
     * @return     the object read by the {@code ContentHandler}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54199
diff changeset
    93
     * @throws     IOException  if an I/O error occurs while reading the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32227
diff changeset
    95
    public abstract Object getContent(URLConnection urlc) throws IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Given a URL connect stream positioned at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * representation of an object, this method reads that stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * creates an object that matches one of the types specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
44601
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
   102
     * The default implementation of this method should call
2aa0e48dae05 8177452: Syntax errors in ContentHandler class documentation
michaelm
parents: 32649
diff changeset
   103
     * {@link #getContent(URLConnection)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * and screen the return type for a match of the suggested types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param      urlc   a URL connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param      classes      an array of types requested
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 14342
diff changeset
   108
     * @return     the object read by the {@code ContentHandler} that is
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
   109
     *                 the first match of the suggested types or
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
   110
     *                 {@code null} if none of the requested  are supported.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54199
diff changeset
   111
     * @throws     IOException  if an I/O error occurs while reading the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 19069
diff changeset
   114
    @SuppressWarnings("rawtypes")
11362
02eae572563e 7125055: ContentHandler.getContent API changed in error
chegar
parents: 10596
diff changeset
   115
    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Object obj = getContent(urlc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
   118
        for (Class<?> c : classes) {
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
   119
            if (c.isInstance(obj)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                return obj;
31642
7ae76e376fcd 8064925: URLConnection::getContent needs to be updated to work with modules
prappo
parents: 25859
diff changeset
   121
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}