Imported GNU Classpath gcj-import-20051117.
* gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r107153
This commit is contained in:
@@ -44,10 +44,6 @@ import java.awt.Rectangle;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.peer.DialogPeer;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JToolTip;
|
||||
|
||||
public class GtkDialogPeer extends GtkWindowPeer
|
||||
implements DialogPeer
|
||||
{
|
||||
@@ -87,27 +83,9 @@ public class GtkDialogPeer extends GtkWindowPeer
|
||||
void create ()
|
||||
{
|
||||
Dialog dialog = (Dialog) awtComponent;
|
||||
int type = GDK_WINDOW_TYPE_HINT_DIALOG;
|
||||
|
||||
if (dialog instanceof JDialog)
|
||||
{
|
||||
Class heavyWeightClass;
|
||||
try
|
||||
{
|
||||
heavyWeightClass = Class.forName("javax.swing.Popup$JWindowPopup");
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
if (dialog.getClass() == heavyWeightClass
|
||||
|| ((JDialog) dialog).getContentPane() instanceof JToolTip)
|
||||
type = GDK_WINDOW_TYPE_HINT_MENU;
|
||||
}
|
||||
|
||||
// Create a decorated dialog window.
|
||||
create (type, !((Dialog) awtComponent).isUndecorated ());
|
||||
create (GDK_WINDOW_TYPE_HINT_DIALOG, !((Dialog) awtComponent).isUndecorated ());
|
||||
|
||||
gtkWindowSetModal (dialog.isModal ());
|
||||
setTitle (dialog.getTitle ());
|
||||
|
||||
@@ -41,7 +41,6 @@ package gnu.java.awt.peer.gtk;
|
||||
import java.awt.Component;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.peer.WindowPeer;
|
||||
|
||||
@@ -80,12 +79,16 @@ public class GtkWindowPeer extends GtkContainerPeer
|
||||
|
||||
void create (int type, boolean decorated)
|
||||
{
|
||||
Window window = (Window) awtComponent;
|
||||
GtkWindowPeer parent_peer = null;
|
||||
Component parent = awtComponent.getParent();
|
||||
|
||||
|
||||
if (!window.isFocusableWindow())
|
||||
type = GDK_WINDOW_TYPE_HINT_MENU;
|
||||
|
||||
if (parent != null)
|
||||
parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
|
||||
|
||||
|
||||
create (type, decorated, parent_peer);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ import java.security.Permission;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* This subclass of java.net.URLConnection models a URLConnection via
|
||||
@@ -124,6 +125,54 @@ public class Connection extends URLConnection
|
||||
permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unquote "%" + hex quotes characters
|
||||
*
|
||||
* @param str The string to unquote or null.
|
||||
*
|
||||
* @return The unquoted string or null if str was null.
|
||||
*
|
||||
* @exception MalformedURLException If the given string contains invalid
|
||||
* escape sequences.
|
||||
*
|
||||
* Sadly the same as URI.unquote, but there's nothing we can do to
|
||||
* make it accessible.
|
||||
*
|
||||
*/
|
||||
public static String unquote(String str) throws MalformedURLException
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
byte[] buf = new byte[str.length()];
|
||||
int pos = 0;
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
if (c > 127)
|
||||
throw new MalformedURLException(str + " : Invalid character");
|
||||
if (c == '%')
|
||||
{
|
||||
if (i + 2 >= str.length())
|
||||
throw new MalformedURLException(str + " : Invalid quoted character");
|
||||
int hi = Character.digit(str.charAt(++i), 16);
|
||||
int lo = Character.digit(str.charAt(++i), 16);
|
||||
if (lo < 0 || hi < 0)
|
||||
throw new MalformedURLException(str + " : Invalid quoted character");
|
||||
buf[pos++] = (byte) (hi * 16 + lo);
|
||||
}
|
||||
else
|
||||
buf[pos++] = (byte) c;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new String(buf, 0, pos, "utf-8");
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException x2)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(x2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Connects" to the file by opening it.
|
||||
*/
|
||||
@@ -134,7 +183,7 @@ public class Connection extends URLConnection
|
||||
return;
|
||||
|
||||
// If not connected, then file needs to be openned.
|
||||
file = new File (getURL().getFile());
|
||||
file = new File (unquote(getURL().getFile()));
|
||||
|
||||
if (! file.isDirectory())
|
||||
{
|
||||
|
||||
@@ -47,7 +47,10 @@ 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.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipFile;
|
||||
@@ -60,6 +63,12 @@ import java.util.zip.ZipFile;
|
||||
*/
|
||||
public final class Connection extends JarURLConnection
|
||||
{
|
||||
/**
|
||||
* HTTP-style DateFormat, used to format the last-modified header.
|
||||
* Lazy initialized since jar files are used during bootstrapping.
|
||||
*/
|
||||
private static SimpleDateFormat dateFormat;
|
||||
|
||||
private JarFile jar_file;
|
||||
private JarEntry jar_entry;
|
||||
private URL jar_url;
|
||||
@@ -82,7 +91,9 @@ public final class Connection extends JarURLConnection
|
||||
|
||||
if ("file".equals (url.getProtocol()))
|
||||
{
|
||||
File f = new File (url.getFile());
|
||||
String fn = url.getFile();
|
||||
fn = gnu.java.net.protocol.file.Connection.unquote(fn);
|
||||
File f = new File (fn);
|
||||
jf = new JarFile (f, true, ZipFile.OPEN_READ);
|
||||
}
|
||||
else
|
||||
@@ -165,6 +176,38 @@ 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"))
|
||||
{
|
||||
// Both creating and manipulating dateFormat need synchronization.
|
||||
synchronized (this.getClass())
|
||||
{
|
||||
if (dateFormat == null)
|
||||
dateFormat = new SimpleDateFormat
|
||||
("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
|
||||
new Locale ("En", "Us", "Unix"));
|
||||
|
||||
return dateFormat.format(new Date(getJarEntry().getTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Fall through.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getContentLength()
|
||||
{
|
||||
if (!connected)
|
||||
@@ -172,4 +215,19 @@ public final class Connection extends JarURLConnection
|
||||
|
||||
return (int) jar_entry.getSize();
|
||||
}
|
||||
|
||||
public long getLastModified()
|
||||
{
|
||||
if (!connected)
|
||||
return -1;
|
||||
|
||||
try
|
||||
{
|
||||
return getJarEntry().getTime();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user