Commit f1f90ae0 by Bryce McKinlay Committed by Bryce McKinlay

Makefile.am (ordinary_java_source_files): Add DefaultContentHandlerFactory.java.

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.

From-SVN: r85069
parent ef453534
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.
2004-07-21 Michael Koch <konqueror@gmx.de> 2004-07-21 Michael Koch <konqueror@gmx.de>
* javax/swing/JTextArea.java * javax/swing/JTextArea.java
...@@ -650,8 +675,6 @@ ...@@ -650,8 +675,6 @@
(BasicPopupMenuUI.PopupMenuHandler): Implemented. (BasicPopupMenuUI.PopupMenuHandler): Implemented.
(BasicPopupMenuUI.TopWindowListener): New ComponentListener. (BasicPopupMenuUI.TopWindowListener): New ComponentListener.
Implemented. Implemented.
2004-07-21 Michael Koch <konqueror@gmx.de> 2004-07-21 Michael Koch <konqueror@gmx.de>
......
...@@ -2436,6 +2436,7 @@ gnu/java/locale/LocaleInformation_zh_HK.java \ ...@@ -2436,6 +2436,7 @@ gnu/java/locale/LocaleInformation_zh_HK.java \
gnu/java/locale/LocaleInformation_zh_SG.java \ gnu/java/locale/LocaleInformation_zh_SG.java \
gnu/java/locale/LocaleInformation_zh_TW.java \ gnu/java/locale/LocaleInformation_zh_TW.java \
gnu/java/math/MPN.java \ gnu/java/math/MPN.java \
gnu/java/net/DefaultContentHandlerFactory.java \
gnu/java/net/HeaderFieldHelper.java \ gnu/java/net/HeaderFieldHelper.java \
gnu/java/net/PlainDatagramSocketImpl.java \ gnu/java/net/PlainDatagramSocketImpl.java \
gnu/java/net/PlainSocketImpl.java \ gnu/java/net/PlainSocketImpl.java \
......
...@@ -2119,6 +2119,7 @@ gnu/java/locale/LocaleInformation_zh_HK.java \ ...@@ -2119,6 +2119,7 @@ gnu/java/locale/LocaleInformation_zh_HK.java \
gnu/java/locale/LocaleInformation_zh_SG.java \ gnu/java/locale/LocaleInformation_zh_SG.java \
gnu/java/locale/LocaleInformation_zh_TW.java \ gnu/java/locale/LocaleInformation_zh_TW.java \
gnu/java/math/MPN.java \ gnu/java/math/MPN.java \
gnu/java/net/DefaultContentHandlerFactory.java \
gnu/java/net/HeaderFieldHelper.java \ gnu/java/net/HeaderFieldHelper.java \
gnu/java/net/PlainDatagramSocketImpl.java \ gnu/java/net/PlainDatagramSocketImpl.java \
gnu/java/net/PlainSocketImpl.java \ gnu/java/net/PlainSocketImpl.java \
...@@ -3089,7 +3090,7 @@ libgcj-test.spec.in libgcj.pc.in libgcj.spec.in ...@@ -3089,7 +3090,7 @@ libgcj-test.spec.in libgcj.pc.in libgcj.spec.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar TAR = gtar
GZIP_ENV = --best GZIP_ENV = --best
DIST_SUBDIRS = @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include DIST_SUBDIRS = @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include
DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
...@@ -3389,7 +3390,9 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ ...@@ -3389,7 +3390,9 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/gnu/java/locale/LocaleInformation_zh_HK.P \ .deps/gnu/java/locale/LocaleInformation_zh_HK.P \
.deps/gnu/java/locale/LocaleInformation_zh_SG.P \ .deps/gnu/java/locale/LocaleInformation_zh_SG.P \
.deps/gnu/java/locale/LocaleInformation_zh_TW.P \ .deps/gnu/java/locale/LocaleInformation_zh_TW.P \
.deps/gnu/java/math/MPN.P .deps/gnu/java/net/HeaderFieldHelper.P \ .deps/gnu/java/math/MPN.P \
.deps/gnu/java/net/DefaultContentHandlerFactory.P \
.deps/gnu/java/net/HeaderFieldHelper.P \
.deps/gnu/java/net/PlainDatagramSocketImpl.P \ .deps/gnu/java/net/PlainDatagramSocketImpl.P \
.deps/gnu/java/net/PlainSocketImpl.P .deps/gnu/java/net/URLParseError.P \ .deps/gnu/java/net/PlainSocketImpl.P .deps/gnu/java/net/URLParseError.P \
.deps/gnu/java/net/natPlainDatagramSocketImpl.P \ .deps/gnu/java/net/natPlainDatagramSocketImpl.P \
......
...@@ -48,6 +48,7 @@ import java.awt.GraphicsEnvironment; ...@@ -48,6 +48,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.image.ColorModel; import java.awt.image.ColorModel;
import java.awt.image.ImageProducer;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
...@@ -331,4 +332,17 @@ public abstract class ClasspathToolkit ...@@ -331,4 +332,17 @@ public abstract class ClasspathToolkit
.initCause(muex); .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;
}
} }
...@@ -278,6 +278,17 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit ...@@ -278,6 +278,17 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
return image; 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 () public ColorModel getColorModel ()
{ {
......
...@@ -50,6 +50,9 @@ import java.net.ProtocolException; ...@@ -50,6 +50,9 @@ import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.security.Permission; 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 * This subclass of java.net.URLConnection models a URLConnection via
...@@ -62,9 +65,11 @@ import java.security.Permission; ...@@ -62,9 +65,11 @@ import java.security.Permission;
public class Connection extends URLConnection 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 * This is a File object for this connection
...@@ -82,18 +87,11 @@ public class Connection extends URLConnection ...@@ -82,18 +87,11 @@ public class Connection extends URLConnection
private OutputStream outputStream; private OutputStream outputStream;
/** /**
* FilePermission to read the file
*/
private FilePermission permission;
/**
* Calls superclass constructor to initialize. * Calls superclass constructor to initialize.
*/ */
public Connection(URL url) public Connection(URL url)
{ {
super (url); super (url);
permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
} }
/** /**
...@@ -156,45 +154,73 @@ public class Connection extends URLConnection ...@@ -156,45 +154,73 @@ public class Connection extends URLConnection
} }
/** /**
* Get the last modified time of the resource. * Get an http-style header field. Just handle a few common ones.
*
* @return the time since epoch that the resource was modified.
*/ */
public long getLastModified() public String getHeaderField(String field)
{ {
try try
{ {
if (!connected) if (!connected)
connect(); 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) catch (IOException e)
{ {
return -1; // Fall through.
} }
return null;
} }
/** /**
* Get the length of content. * Get the length of content.
*
* @return the length of the content. * @return the length of the content.
*/ */
public int getContentLength() public int getContentLength()
{ {
try 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) if (!connected)
connect(); connect();
return (int) file.length(); return file.lastModified();
} }
catch (IOException e) catch (IOException e)
{ {
return -1; return -1;
} }
} }
/** /**
* This method returns a <code>Permission</code> object representing the * This method returns a <code>Permission</code> object representing the
* permissions required to access this URL. This method returns a * permissions required to access this URL. This method returns a
...@@ -205,6 +231,6 @@ public class Connection extends URLConnection ...@@ -205,6 +231,6 @@ public class Connection extends URLConnection
*/ */
public Permission getPermission() throws IOException public Permission getPermission() throws IOException
{ {
return permission; return new FilePermission(getURL().getFile(), "read");
} }
} }
...@@ -61,4 +61,23 @@ class Connection extends URLConnection ...@@ -61,4 +61,23 @@ class Connection extends URLConnection
connect(); connect();
return new CoreInputStream(core); 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;
}
} }
...@@ -49,8 +49,11 @@ import java.net.MalformedURLException; ...@@ -49,8 +49,11 @@ import java.net.MalformedURLException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
...@@ -66,6 +69,14 @@ import java.util.zip.ZipFile; ...@@ -66,6 +69,14 @@ import java.util.zip.ZipFile;
public final class Connection extends JarURLConnection public final class Connection extends JarURLConnection
{ {
private static Hashtable file_cache = new Hashtable(); 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; private JarFile jar_file;
/** /**
...@@ -219,6 +230,32 @@ public final class Connection extends JarURLConnection ...@@ -219,6 +230,32 @@ public final class Connection extends JarURLConnection
return jar_file; 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() public int getContentLength()
{ {
if (!connected) if (!connected)
...@@ -233,4 +270,19 @@ public final class Connection extends JarURLConnection ...@@ -233,4 +270,19 @@ public final class Connection extends JarURLConnection
return -1; return -1;
} }
} }
public long getLastModified()
{
if (!connected)
return -1;
try
{
return getJarEntry().getTime();
}
catch (IOException e)
{
return -1;
}
}
} }
...@@ -116,6 +116,9 @@ public abstract class URLConnection ...@@ -116,6 +116,9 @@ public abstract class URLConnection
*/ */
private static boolean defaultUseCaches = true; private static boolean defaultUseCaches = true;
private static ContentHandlerFactory defaultFactory
= new gnu.java.net.DefaultContentHandlerFactory();
/** /**
* This variable determines whether or not interaction is allowed with * This variable determines whether or not interaction is allowed with
* the user. For example, to prompt for a username and password. * the user. For example, to prompt for a username and password.
...@@ -436,7 +439,7 @@ public abstract class URLConnection ...@@ -436,7 +439,7 @@ public abstract class URLConnection
// guessContentTypeFromName() and guessContentTypeFromStream methods // guessContentTypeFromName() and guessContentTypeFromStream methods
// as well as FileNameMap class & fileNameMap field & get/set methods. // as well as FileNameMap class & fileNameMap field & get/set methods.
String type = getContentType(); String type = getContentType();
ContentHandler ch = setContentHandler(type); ContentHandler ch = getContentHandler(type);
if (ch == null) if (ch == null)
return getInputStream(); return getInputStream();
...@@ -963,7 +966,7 @@ public abstract class URLConnection ...@@ -963,7 +966,7 @@ public abstract class URLConnection
fileNameMap = map; fileNameMap = map;
} }
private ContentHandler setContentHandler(String contentType) private ContentHandler getContentHandler(String contentType)
{ {
ContentHandler handler; ContentHandler handler;
...@@ -981,12 +984,17 @@ public abstract class URLConnection ...@@ -981,12 +984,17 @@ public abstract class URLConnection
else else
return null; return null;
// If a non-default factory has been set, use it to find the content type. // If a non-default factory has been set, use it.
if (factory != null) if (factory != null)
handler = factory.createContentHandler(contentType); handler = factory.createContentHandler(contentType);
// Non-default factory may have returned null or a factory wasn't set. // Now try default factory. Using this factory to instantiate built-in
// Use the default search algorithm to find a handler for this content type. // content handlers is preferable
if (handler == null)
handler = defaultFactory.createContentHandler(contentType);
// User-set factory has not returned a handler. Use the default search
// algorithm.
if (handler == null) if (handler == null)
{ {
// Get the list of packages to check and append our default handler // Get the list of packages to check and append our default handler
...@@ -995,7 +1003,7 @@ public abstract class URLConnection ...@@ -995,7 +1003,7 @@ public abstract class URLConnection
// ever be needed (or available). // ever be needed (or available).
String propVal = System.getProperty("java.content.handler.pkgs"); String propVal = System.getProperty("java.content.handler.pkgs");
propVal = (propVal == null) ? "" : (propVal + "|"); propVal = (propVal == null) ? "" : (propVal + "|");
propVal = propVal + "gnu.gcj.content|sun.net.www.content"; propVal = propVal + "gnu.java.net.content|sun.net.www.content";
// Replace the '/' character in the content type with '.' and // Replace the '/' character in the content type with '.' and
// all other non-alphabetic, non-numeric characters with '_'. // all other non-alphabetic, non-numeric characters with '_'.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment