0N/A/*
2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.net;
0N/A
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * The abstract class <code>ContentHandler</code> is the superclass
0N/A * of all classes that read an <code>Object</code> from a
0N/A * <code>URLConnection</code>.
0N/A * <p>
0N/A * An application does not generally call the
0N/A * <code>getContent</code> method in this class directly. Instead, an
0N/A * application calls the <code>getContent</code> method in class
0N/A * <code>URL</code> or in <code>URLConnection</code>.
0N/A * The application's content handler factory (an instance of a class that
0N/A * implements the interface <code>ContentHandlerFactory</code> set
0N/A * up by a call to <code>setContentHandler</code>) is
0N/A * called with a <code>String</code> giving the MIME type of the
0N/A * object being received on the socket. The factory returns an
0N/A * instance of a subclass of <code>ContentHandler</code>, and its
0N/A * <code>getContent</code> method is called to create the object.
0N/A * <p>
0N/A * If no content handler could be found, URLConnection will
0N/A * look for a content handler in a user-defineable set of places.
0N/A * By default it looks in sun.net.www.content, but users can define a
0N/A * vertical-bar delimited set of class prefixes to search through in
0N/A * addition by defining the java.content.handler.pkgs property.
0N/A * The class name must be of the form:
0N/A * <pre>
0N/A * {package-prefix}.{major}.{minor}
0N/A * e.g.
0N/A * YoyoDyne.experimental.text.plain
0N/A * </pre>
0N/A * If the loading of the content handler class would be performed by
0N/A * a classloader that is outside of the delegation chain of the caller,
0N/A * the JVM will need the RuntimePermission "getClassLoader".
0N/A *
0N/A * @author James Gosling
0N/A * @see java.net.ContentHandler#getContent(java.net.URLConnection)
0N/A * @see java.net.ContentHandlerFactory
0N/A * @see java.net.URL#getContent()
0N/A * @see java.net.URLConnection
0N/A * @see java.net.URLConnection#getContent()
0N/A * @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory)
0N/A * @since JDK1.0
0N/A */
0N/Aabstract public class ContentHandler {
0N/A /**
0N/A * Given a URL connect stream positioned at the beginning of the
0N/A * representation of an object, this method reads that stream and
0N/A * creates an object from it.
0N/A *
0N/A * @param urlc a URL connection.
0N/A * @return the object read by the <code>ContentHandler</code>.
0N/A * @exception IOException if an I/O error occurs while reading the object.
0N/A */
0N/A abstract public Object getContent(URLConnection urlc) throws IOException;
0N/A
0N/A /**
0N/A * Given a URL connect stream positioned at the beginning of the
0N/A * representation of an object, this method reads that stream and
0N/A * creates an object that matches one of the types specified.
0N/A *
0N/A * The default implementation of this method should call getContent()
0N/A * and screen the return type for a match of the suggested types.
0N/A *
0N/A * @param urlc a URL connection.
0N/A * @param classes an array of types requested
0N/A * @return the object read by the <code>ContentHandler</code> that is
0N/A * the first match of the suggested types.
0N/A * null if none of the requested are supported.
0N/A * @exception IOException if an I/O error occurs while reading the object.
0N/A * @since 1.3
0N/A */
0N/A public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
0N/A Object obj = getContent(urlc);
0N/A
0N/A for (int i = 0; i < classes.length; i++) {
0N/A if (classes[i].isInstance(obj)) {
0N/A return obj;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A}