[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] Patch: fix for explicit mime types and text/html
From: |
Mark Wielaard |
Subject: |
Re: [cp-patches] Patch: fix for explicit mime types and text/html |
Date: |
Thu, 09 Sep 2004 23:32:05 +0200 |
Hi,
On Thu, 2004-08-05 at 02:44, jrandom wrote:
> > The URLConnection change looks fine to me. Care to write a
> > ChangeLog entry?
> >
> > I think text/html.java isn't really neccessary, and text/plain.java
> > should also be removed. Instead, I think URLConnection.getContent()
> > should just fall back to returning an InputStream when it gets a
> > MIME type that it doesn't recognise. This should be fixed when we
> > merge again with libgcj's URLConnection implementation.
>
> Ok, here's a revised patch w/ changelog entry. The
> GenericHandler.java is plain renaming of the old plain.java, but
> is referenced explicitly from the URLConnection (which now never
> throws UnknownServiceException - it either has an explicit
> handler at gnu.java.net.content.* or it uses the GenericHandler).
Thanks. I finally looked at the patch and decided to simplify it a bit.
Instead of creating an instance of a GenericHandler which then calls
back into the URLConnection.getInputStream() I just call getInputStream
directly.
Note that it is still possible to get a UnknownServiceException since
either the found content handler throws it after all or getInputStream()
throws it (it is the default implementation).
Hope this helps i2p work better. I unfortunately didn't have time to
check it out. My other tests indicate that it works fine though (it
fixes 3 mauve tests!). Your test in bug #8991 also works with this.
2004-09-09 Mark Wielaard <address@hidden>
Fixes bug #8991.
* java/net/URLConnection.java (getContent): Add support for
explicit mime types. Call getInputStream() if no handler found.
* gnu/java/net/content/text/plain.java: Removed
Committed.
Cheers,
Mark
Index: java/net/URLConnection.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLConnection.java,v
retrieving revision 1.29
diff -u -r1.29 URLConnection.java
--- java/net/URLConnection.java 22 Jul 2004 01:34:55 -0000 1.29
+++ java/net/URLConnection.java 9 Sep 2004 21:26:02 -0000
@@ -404,23 +404,31 @@
}
/**
- * This method returns the content of the document pointed to by the URL
- * as an Object. The type of object depends on the MIME type of the
- * object and particular content hander loaded. Most text type content
- * handlers will return a subclass of InputStream. Images usually return
- * a class that implements ImageProducer. There is not guarantee what
- * type of object will be returned, however.
- * <p>
- * This class first determines the MIME type of the content, then creates
- * a ContentHandler object to process the input. If the
ContentHandlerFactory
- * is set, then that object is called to load a content handler, otherwise
- * a class called gnu.java.net.content.<content_type> is tried.
- * The default class will also be used if the content handler factory returns
- * a null content handler.
+ * This method returns the content of the document pointed to by the
+ * URL as an Object. The type of object depends on the MIME type of
+ * the object and particular content hander loaded. Most text type
+ * content handlers will return a subclass of
+ * <code>InputStream</code>. Images usually return a class that
+ * implements <code>ImageProducer<code>. There is not guarantee
+ * what type of object will be returned, however.
+
+<p>
+
+ * This class first determines the MIME type of the content, then
+ * creates a ContentHandler object to process the input. If the
+ * <code>ContentHandlerFactory</code> is set, then that object is
+ * called to load a content handler, otherwise a class called
+ * gnu.java.net.content.<content_type> is tried. If this
+ * handler does not exist, the method will simple return the
+ * <code>InputStream</code> returned by
+ * <code>getInputStream()</code>. Note that the default
+ * implementation of <code>getInputStream()</code> throws a
+ * <code>UnknownServiceException</code> so subclasses are encouraged
+ * to override this method.
*
- * @exception IOException If an error occurs
+ * @exception IOException If an error with the connection occurs.
* @exception UnknownServiceException If the protocol does not support the
- * content type
+ * content type at all.
*/
public Object getContent() throws IOException
{
@@ -439,16 +447,22 @@
// Then try our default class
try
{
- Class cls =
- Class.forName("gnu.java.net.content." + type.replace('/', '.'));
+ String typeClass = type.replace('/', '.');
+
+ // deal with "Content-Type: text/html; charset=ISO-8859-1"
+ int parameterBegin = typeClass.indexOf(';');
+ if (parameterBegin >= 1)
+ typeClass = typeClass.substring(0, parameterBegin);
- Object obj = cls.newInstance();
+ Class cls = Class.forName("gnu.java.net.content." + typeClass);
- if (! (obj instanceof ContentHandler))
- throw new UnknownServiceException(type);
+ Object obj = cls.newInstance();
- ch = (ContentHandler) obj;
- return ch.getContent(this);
+ if (obj instanceof ContentHandler)
+ {
+ ch = (ContentHandler) obj;
+ return ch.getContent(this);
+ }
}
catch (ClassNotFoundException e)
{
@@ -460,7 +474,7 @@
{
}
- throw new UnknownServiceException(type);
+ return getInputStream();
}
/**
Index: gnu/java/net/content/text/plain.java
===================================================================
RCS file: gnu/java/net/content/text/plain.java
diff -N gnu/java/net/content/text/plain.java
--- gnu/java/net/content/text/plain.java 22 Jan 2002 22:26:57 -0000
1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,89 +0,0 @@
-/* plain.java -- Content Handler for text/plain type
- Copyright (C) 1998 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.net.content.text;
-
-import java.net.ContentHandler;
-import java.net.URLConnection;
-import java.io.IOException;
-
-/**
- * This class is the ContentHandler for the text/plain MIME type. It
- * simply returns an InputStream object of the text being read.
- *
- * @version 0.1
- *
- * @author Aaron M. Renn (address@hidden)
- */
-public class plain extends ContentHandler
-{
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-/**
- * Default do nothing constructor
- */
-public
-plain()
-{
- ;
-}
-
-/*************************************************************************/
-
-/**
- * Returns an InputStream as the content for this object
- *
- * @param url_con The URLConnection to get the content of
- *
- * @return An InputStream for that connection
- *
- * @exception IOException If an error occurs
- */
-public Object
-getContent(URLConnection url_con) throws IOException
-{
- return(url_con.getInputStream());
-}
-
-} // class plain
-
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [cp-patches] Patch: fix for explicit mime types and text/html,
Mark Wielaard <=