[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: URLConnection and other small fixes

Kaffe CVS cvs-commits at kaffe.org
Mon Oct 4 03:17:40 PDT 2004


PatchSet 5241 
Date: 2004/10/04 10:13:43
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: URLConnection and other small fixes

2004-10-04  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/net/URLConnection.java,
        libraries/javalib/java/text/MessageFormat.java,
        libraries/javalib/javax/crypto/MacSpi.java:
        Resynced with GNU Classpath.

        2004-09-28  Tom Tromey  <tromey at redhat.com>

        * java/text/MessageFormat.java (Field): Constructor now
        protected.

        * java/net/URLConnection.java (setFileNameMap): Now synchronized.

        * javax/crypto/MacSpi.java: Fixed typo.

        2004-09-28  Michael Koch  <konqueror at gmx.de>

        * java/net/URLConnection.java:
        Reformatted.
        (getContent): Make sure we are connected. Moved code to get content
        handler to getContentHandler() method for easier merging with libgcj's
        version.
        (getContentHandler): New method.

Members: 
	ChangeLog:1.2795->1.2796 
	libraries/javalib/java/net/URLConnection.java:1.21->1.22 
	libraries/javalib/java/text/MessageFormat.java:1.29->1.30 
	libraries/javalib/javax/crypto/MacSpi.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2795 kaffe/ChangeLog:1.2796
--- kaffe/ChangeLog:1.2795	Mon Oct  4 09:37:43 2004
+++ kaffe/ChangeLog	Mon Oct  4 10:13:43 2004
@@ -1,5 +1,30 @@
 2004-10-04  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/net/URLConnection.java,
+	libraries/javalib/java/text/MessageFormat.java,
+	libraries/javalib/javax/crypto/MacSpi.java:
+        Resynced with GNU Classpath.
+
+	2004-09-28  Tom Tromey  <tromey at redhat.com>
+
+        * java/text/MessageFormat.java (Field): Constructor now
+        protected.
+
+        * java/net/URLConnection.java (setFileNameMap): Now synchronized.
+
+        * javax/crypto/MacSpi.java: Fixed typo.
+
+	2004-09-28  Michael Koch  <konqueror at gmx.de>
+
+        * java/net/URLConnection.java:
+        Reformatted.
+        (getContent): Make sure we are connected. Moved code to get content
+        handler to getContentHandler() method for easier merging with libgcj's
+        version.
+        (getContentHandler): New method.
+
+2004-10-04  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/net/URLClassLoader.java:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/java/net/URLConnection.java
diff -u kaffe/libraries/javalib/java/net/URLConnection.java:1.21 kaffe/libraries/javalib/java/net/URLConnection.java:1.22
--- kaffe/libraries/javalib/java/net/URLConnection.java:1.21	Sun Sep 12 15:11:03 2004
+++ kaffe/libraries/javalib/java/net/URLConnection.java	Mon Oct  4 10:13:46 2004
@@ -35,6 +35,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
 import java.io.IOException;
@@ -49,7 +50,6 @@
 import java.util.Locale;
 import java.util.Map;
 
-
 /**
  * Written using on-line Java Platform 1.2 API Specification, as well
  * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
@@ -84,8 +84,8 @@
  * by the actual content handlers as described in the description of that
  * method.
  *
- * @author Aaron M. Renn <arenn at urbanophile.com>
- * @author Warren Levy <warrenl at cygnus.com>
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @author Warren Levy (warrenl at cygnus.com)
  */
 public abstract class URLConnection
 {
@@ -160,13 +160,12 @@
    * This is the URL associated with this connection
    */
   protected URL url;
-
   private static SimpleDateFormat[] dateFormats;
   private static boolean dateformats_initialized;
 
   /* Cached ParsePosition, used when parsing dates. */
   private ParsePosition position;
- 
+
   /**
    * Creates a URL connection to a given URL. A real connection is not made.
    * Use #connect to do this.
@@ -363,7 +362,7 @@
   {
     if (! dateformats_initialized)
       initializeDateFormats();
-    
+
     if (position == null)
       position = new ParsePosition(0);
 
@@ -409,12 +408,10 @@
    * 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
+   * 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
+   *
+   * <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
@@ -424,7 +421,7 @@
    * <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.
+   * to override this method.</p>
    *
    * @exception IOException If an error with the connection occurs.
    * @exception UnknownServiceException If the protocol does not support the
@@ -432,48 +429,19 @@
    */
   public Object getContent() throws IOException
   {
-    //  connect();
-    String type = getContentType();
+    if (!connected)
+      connect();
 
-    // First try the factory
-    ContentHandler ch = null;
-
-    if (factory != null)
-      ch = factory.createContentHandler(type);
+    // FIXME: Doc indicates that other criteria should be applied as
+    // heuristics to determine the true content type, e.g. see 
+    // guessContentTypeFromName() and guessContentTypeFromStream methods
+    // as well as FileNameMap class & fileNameMap field & get/set methods.
+    String type = getContentType();
+    ContentHandler ch = getContentHandler(type);
 
     if (ch != null)
       return ch.getContent(this);
 
-    // Then try our default class
-    try
-      {
-	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);
-
-	Class cls = Class.forName("gnu.java.net.content." + typeClass);
-
-	Object obj = cls.newInstance();
-
-	if (obj instanceof ContentHandler)
-	  {
-	    ch = (ContentHandler) obj;
-	    return ch.getContent(this);
-	  }
-      }
-    catch (ClassNotFoundException e)
-      {
-      }
-    catch (InstantiationException e)
-      {
-      }
-    catch (IllegalAccessException e)
-      {
-      }
-
     return getInputStream();
   }
 
@@ -940,7 +908,7 @@
   public static String guessContentTypeFromStream(InputStream is)
     throws IOException
   {
-    return ("application/octet-stream");
+    return "application/octet-stream";
   }
 
   /**
@@ -971,9 +939,9 @@
    *
    * @since 1.2
    */
-  public static void setFileNameMap(FileNameMap map)
+  public static synchronized void setFileNameMap(FileNameMap map)
   {
-    // Throw an exception if an extant security mgr precludes
+    // Throw an exception if an extant security manager precludes
     // setting the factory.
     SecurityManager s = System.getSecurityManager();
     if (s != null)
@@ -982,6 +950,53 @@
     fileNameMap = map;
   }
 
+  private ContentHandler getContentHandler(String contentType)
+  {
+    // No content type so just handle it as the default.
+    if (contentType == null || contentType.equals(""))
+      return null;
+
+    ContentHandler handler = null;
+
+    // If a non-default factory has been set, use it.
+    if (factory != null)
+      handler = factory.createContentHandler(contentType);
+
+    // Then try our default class.
+    try
+      {
+	String typeClass = contentType.replace('/', '.');
+
+	// Deal with "Content-Type: text/html; charset=ISO-8859-1".
+	int parameterBegin = typeClass.indexOf(';');
+	if (parameterBegin >= 1)
+	  typeClass = typeClass.substring(0, parameterBegin);
+
+	Class cls = Class.forName("gnu.java.net.content." + typeClass);
+	Object obj = cls.newInstance();
+
+	if (obj instanceof ContentHandler)
+	  {
+	    handler = (ContentHandler) obj;
+	    return handler;
+	  }
+      }
+    catch (ClassNotFoundException e)
+      {
+	// Ignore.
+      }
+    catch (InstantiationException e)
+      {
+	// Ignore.
+      }
+    catch (IllegalAccessException e)
+      {
+	// Ignore.
+      }
+
+    return handler;
+  }
+  
   // We don't put these in a static initializer, because it creates problems
   // with initializer co-dependency: SimpleDateFormat's constructors eventually 
   // depend on URLConnection (via the java.text.*Symbols classes).
Index: kaffe/libraries/javalib/java/text/MessageFormat.java
diff -u kaffe/libraries/javalib/java/text/MessageFormat.java:1.29 kaffe/libraries/javalib/java/text/MessageFormat.java:1.30
--- kaffe/libraries/javalib/java/text/MessageFormat.java:1.29	Mon Jul 12 04:58:02 2004
+++ kaffe/libraries/javalib/java/text/MessageFormat.java	Mon Oct  4 10:13:46 2004
@@ -165,7 +165,7 @@
       super("");
     }
     
-    private Field(String s)
+    protected Field(String s)
     {
       super(s);
     }
Index: kaffe/libraries/javalib/javax/crypto/MacSpi.java
diff -u kaffe/libraries/javalib/javax/crypto/MacSpi.java:1.2 kaffe/libraries/javalib/javax/crypto/MacSpi.java:1.3
--- kaffe/libraries/javalib/javax/crypto/MacSpi.java:1.2	Tue Aug 17 17:55:04 2004
+++ kaffe/libraries/javalib/javax/crypto/MacSpi.java	Mon Oct  4 10:13:46 2004
@@ -52,7 +52,7 @@
  * then provide an entry pointing to this implementation in the master
  * {@link java.security.Provider} class.
  *
- * <p>Implemetations may optionally implement the {@link
+ * <p>Implementations may optionally implement the {@link
  * java.lang.Cloneable} interface.
  *
  * @author Casey Marshall (csm at gnu.org)




More information about the kaffe mailing list