summaryrefslogtreecommitdiff
path: root/libjava/gnu
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-23 01:21:40 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-23 01:21:40 +0000
commit27813db22493a7f381f372428a86091b99cb54a8 (patch)
treed02b2df079e500b6c08b6fc1f2a09b28c804beca /libjava/gnu
parent266329b8efb72cad0d48a77285fb6db7560499e2 (diff)
downloadgcc-27813db22493a7f381f372428a86091b99cb54a8.tar.gz
2004-07-22 Bryce McKinlay <mckinlay@redhat.com>
* Makefile.am (ordinary_java_source_files): Add DefaultContentHandlerFactory.java. * Makefile.in: Rebuilt. * java/net/URLConnection.java (defaultFactory): New field. (getContent): (getContentHandler): Renamed from 'setContentHandler'. Try defaultFactory after user-set factory, if any. Search for content handler implementations in gnu.java.net.content, not gnu.gcj.content. * gnu/java/net/protocol/file/Connection.java (getHeaderField): Implemented. (getLastModified): Implemented. (getPermission): Create file permission here, instead of in constructor. * gnu/java/net/protocol/gcjlib/Connection.java (getHeaderField): Implemented. * gnu/java/net/protocol/jar/Connection.java (getHeaderField): Implemented. (getLastModified): Implemented. * gnu/java/awt/ClasspathToolkit.java (createImageProducer): New. Default implementation. * gnu/java/awt/peer/gtk/GtkToolkit.java (createImageProducer): New. Implement using GdkPixbufDecoder. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85069 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu')
-rw-r--r--libjava/gnu/java/awt/ClasspathToolkit.java14
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkToolkit.java11
-rw-r--r--libjava/gnu/java/net/protocol/file/Connection.java66
-rw-r--r--libjava/gnu/java/net/protocol/gcjlib/Connection.java19
-rw-r--r--libjava/gnu/java/net/protocol/jar/Connection.java52
5 files changed, 142 insertions, 20 deletions
diff --git a/libjava/gnu/java/awt/ClasspathToolkit.java b/libjava/gnu/java/awt/ClasspathToolkit.java
index 91401f4d5a2..92934593d39 100644
--- a/libjava/gnu/java/awt/ClasspathToolkit.java
+++ b/libjava/gnu/java/awt/ClasspathToolkit.java
@@ -48,6 +48,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.image.ColorModel;
+import java.awt.image.ImageProducer;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
@@ -331,4 +332,17 @@ public abstract class ClasspathToolkit
.initCause(muex);
}
}
+
+ /**
+ * Creates an ImageProducer from the specified URL. The image is assumed
+ * to be in a recognised format. If the toolkit does not implement the
+ * image format or the image format is not recognised, null is returned.
+ * This default implementation is overriden by the Toolkit implementations.
+ *
+ * @param url URL to read image data from.
+ */
+ public ImageProducer createImageProducer(URL url)
+ {
+ return null;
+ }
}
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
index 9cc29b4b3a4..3f82159c3ab 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -278,6 +278,17 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
return image;
}
}
+
+ /**
+ * Creates an ImageProducer from the specified URL. The image is assumed
+ * to be in a recognised format.
+ *
+ * @param url URL to read image data from.
+ */
+ public ImageProducer createImageProducer(URL url)
+ {
+ return new GdkPixbufDecoder(url);
+ }
public ColorModel getColorModel ()
{
diff --git a/libjava/gnu/java/net/protocol/file/Connection.java b/libjava/gnu/java/net/protocol/file/Connection.java
index 650d9f21853..4da6e882c00 100644
--- a/libjava/gnu/java/net/protocol/file/Connection.java
+++ b/libjava/gnu/java/net/protocol/file/Connection.java
@@ -50,6 +50,9 @@ import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
/**
* This subclass of java.net.URLConnection models a URLConnection via
@@ -62,9 +65,11 @@ import java.security.Permission;
public class Connection extends URLConnection
{
/**
- * Default permission for a file
+ * HTTP-style DateFormat, used to format the last-modified header.
*/
- private static final String DEFAULT_PERMISSION = "read";
+ private static SimpleDateFormat dateFormat
+ = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
+ new Locale ("En", "Us", "Unix"));
/**
* This is a File object for this connection
@@ -82,18 +87,11 @@ public class Connection extends URLConnection
private OutputStream outputStream;
/**
- * FilePermission to read the file
- */
- private FilePermission permission;
-
- /**
* Calls superclass constructor to initialize.
*/
public Connection(URL url)
{
super (url);
-
- permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
}
/**
@@ -156,45 +154,73 @@ public class Connection extends URLConnection
}
/**
- * Get the last modified time of the resource.
- *
- * @return the time since epoch that the resource was modified.
+ * Get an http-style header field. Just handle a few common ones.
*/
- public long getLastModified()
+ public String getHeaderField(String field)
{
try
{
if (!connected)
connect();
- return file.lastModified();
+ if (field.equals("content-type"))
+ return guessContentTypeFromName(file.getName());
+ else if (field.equals("content-length"))
+ return Long.toString(file.length());
+ else if (field.equals("last-modified"))
+ {
+ synchronized (dateFormat)
+ {
+ return dateFormat.format(new Date(file.lastModified()));
+ }
+ }
}
catch (IOException e)
{
- return -1;
+ // Fall through.
}
+ return null;
}
/**
* Get the length of content.
- *
* @return the length of the content.
*/
public int getContentLength()
{
try
{
+ if (!connected)
+ connect();
+
+ return (int) file.length();
+ }
+ catch (IOException e)
+ {
+ return -1;
+ }
+ }
+
+ /**
+ * Get the last modified time of the resource.
+ *
+ * @return the time since epoch that the resource was modified.
+ */
+ public long getLastModified()
+ {
+ try
+ {
if (!connected)
connect();
-
- return (int) file.length();
+
+ return file.lastModified();
}
catch (IOException e)
{
return -1;
}
}
-
+
/**
* This method returns a <code>Permission</code> object representing the
* permissions required to access this URL. This method returns a
@@ -205,6 +231,6 @@ public class Connection extends URLConnection
*/
public Permission getPermission() throws IOException
{
- return permission;
+ return new FilePermission(getURL().getFile(), "read");
}
}
diff --git a/libjava/gnu/java/net/protocol/gcjlib/Connection.java b/libjava/gnu/java/net/protocol/gcjlib/Connection.java
index b31db565776..4e6e462f26e 100644
--- a/libjava/gnu/java/net/protocol/gcjlib/Connection.java
+++ b/libjava/gnu/java/net/protocol/gcjlib/Connection.java
@@ -61,4 +61,23 @@ class Connection extends URLConnection
connect();
return new CoreInputStream(core);
}
+
+ public String getHeaderField(String field)
+ {
+ try
+ {
+ if (!connected)
+ connect();
+
+ if (field.equals("content-type"))
+ return guessContentTypeFromName(name);
+ else if (field.equals("content-length"))
+ return Long.toString(core.length);
+ }
+ catch (IOException e)
+ {
+ // Fall through.
+ }
+ return null;
+ }
}
diff --git a/libjava/gnu/java/net/protocol/jar/Connection.java b/libjava/gnu/java/net/protocol/jar/Connection.java
index 04eb3fe3715..9ba2e3fd1ff 100644
--- a/libjava/gnu/java/net/protocol/jar/Connection.java
+++ b/libjava/gnu/java/net/protocol/jar/Connection.java
@@ -49,8 +49,11 @@ import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Locale;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
@@ -66,6 +69,14 @@ import java.util.zip.ZipFile;
public final class Connection extends JarURLConnection
{
private static Hashtable file_cache = new Hashtable();
+
+ /**
+ * HTTP-style DateFormat, used to format the last-modified header.
+ */
+ private static SimpleDateFormat dateFormat
+ = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
+ new Locale ("En", "Us", "Unix"));
+
private JarFile jar_file;
/**
@@ -219,6 +230,32 @@ public final class Connection extends JarURLConnection
return jar_file;
}
+ public String getHeaderField(String field)
+ {
+ try
+ {
+ if (!connected)
+ connect();
+
+ if (field.equals("content-type"))
+ return guessContentTypeFromName(getJarEntry().getName());
+ else if (field.equals("content-length"))
+ return Long.toString(getJarEntry().getSize());
+ else if (field.equals("last-modified"))
+ {
+ synchronized (dateFormat)
+ {
+ return dateFormat.format(new Date(getJarEntry().getTime()));
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // Fall through.
+ }
+ return null;
+ }
+
public int getContentLength()
{
if (!connected)
@@ -233,4 +270,19 @@ public final class Connection extends JarURLConnection
return -1;
}
}
+
+ public long getLastModified()
+ {
+ if (!connected)
+ return -1;
+
+ try
+ {
+ return getJarEntry().getTime();
+ }
+ catch (IOException e)
+ {
+ return -1;
+ }
+ }
}