diff options
Diffstat (limited to 'libjava/classpath/java/net')
-rw-r--r-- | libjava/classpath/java/net/InetSocketAddress.java | 59 | ||||
-rw-r--r-- | libjava/classpath/java/net/MimeTypeMapper.java | 360 | ||||
-rw-r--r-- | libjava/classpath/java/net/URI.java | 14 | ||||
-rw-r--r-- | libjava/classpath/java/net/URLClassLoader.java | 110 | ||||
-rw-r--r-- | libjava/classpath/java/net/URLConnection.java | 151 | ||||
-rw-r--r-- | libjava/classpath/java/net/class-dependencies.conf | 122 |
6 files changed, 498 insertions, 318 deletions
diff --git a/libjava/classpath/java/net/InetSocketAddress.java b/libjava/classpath/java/net/InetSocketAddress.java index edeaf27753c..91254575265 100644 --- a/libjava/classpath/java/net/InetSocketAddress.java +++ b/libjava/classpath/java/net/InetSocketAddress.java @@ -1,5 +1,5 @@ /* InetSocketAddress.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -107,10 +107,26 @@ public class InetSocketAddress extends SocketAddress * @param hostname The hostname for the socket address * @param port The port for the socket address * - * @exception IllegalArgumentException If the port number is illegal + * @exception IllegalArgumentException If the port number is illegal or + * the hostname argument is null */ public InetSocketAddress(String hostname, int port) - throws IllegalArgumentException + { + this(hostname, port, true); + } + + /** + * Constructs an InetSocketAddress instance. + * + * @param hostname The hostname for the socket address + * @param port The port for the socket address + * @param resolve <code>true</code> if the address has to be resolved, + * <code>false</code> otherwise + * + * @exception IllegalArgumentException If the port number is illegal or + * the hostname argument is null + */ + private InetSocketAddress(String hostname, int port, boolean resolve) { if (hostname == null) throw new IllegalArgumentException("Null host name value"); @@ -120,15 +136,36 @@ public class InetSocketAddress extends SocketAddress this.port = port; this.hostname = hostname; + this.addr = null; - try - { - this.addr = InetAddress.getByName(hostname); - } - catch (Exception e) // UnknownHostException, SecurityException - { - this.addr = null; - } + if (resolve) + { + try + { + this.addr = InetAddress.getByName(hostname); + } + catch (Exception e) // UnknownHostException, SecurityException + { + // Do nothing here. this.addr is already set to null. + } + } + + } + + /** + * Creates an unresolved <code>InetSocketAddress</code> object. + * + * @param hostname The hostname for the socket address + * @param port The port for the socket address + * + * @exception IllegalArgumentException If the port number is illegal or + * the hostname argument is null + * + * @since 1.5 + */ + public static InetSocketAddress createUnresolved(String hostname, int port) + { + return new InetSocketAddress(hostname, port, false); } /** diff --git a/libjava/classpath/java/net/MimeTypeMapper.java b/libjava/classpath/java/net/MimeTypeMapper.java index 1747f4d5685..8153694b483 100644 --- a/libjava/classpath/java/net/MimeTypeMapper.java +++ b/libjava/classpath/java/net/MimeTypeMapper.java @@ -37,7 +37,17 @@ exception statement from your version. */ package java.net; +import gnu.classpath.SystemProperties; + +import java.io.FileReader; +import java.io.IOException; +import java.io.LineNumberReader; import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.StringTokenizer; +import java.util.TreeMap; /** @@ -56,131 +66,230 @@ class MimeTypeMapper implements FileNameMap */ protected static final String[][] mime_strings = { - { "application/mac-binhex40", "hqx" }, - { "application/mac-compactpro", "cpt" }, - { "application/msword", "doc" }, - { "application/octet-stream", "bin" }, - { "application/octet-stream", "dms" }, - { "application/octet-stream", "lha" }, - { "application/octet-stream", "lzh" }, - { "application/octet-stream", "exe" }, - { "application/octet-stream", "class" }, - { "application/oda", "oda" }, - { "application/pdf", "pdf" }, - { "application/postscript", "ai" }, - { "application/postscript", "eps" }, - { "application/postscript", "ps" }, - { "application/powerpoint", "ppt" }, - { "application/rtf", "rtf" }, - { "application/x-bcpio", "bcpio" }, - { "application/x-cdlink", "vcd" }, - { "application/x-compress", "Z" }, - { "application/x-cpio", "cpio" }, - { "application/x-csh", "csh" }, - { "application/x-director", "dcr" }, - { "application/x-director", "dir" }, - { "application/x-director", "dxr" }, - { "application/x-dvi", "dvi" }, - { "application/x-gtar", "gtar" }, - { "application/x-gzip", "gz" }, - { "application/x-hdf", "hdf" }, - { "application/x-httpd-cgi", "cgi" }, - { "application/x-koan", "skp" }, - { "application/x-koan", "skd" }, - { "application/x-koan", "skt" }, - { "application/x-koan", "skm" }, - { "application/x-latex", "latex" }, - { "application/x-mif", "mif" }, - { "application/x-netcdf", "nc" }, - { "application/x-netcdf", "cdf" }, - { "application/x-sh", "sh" }, - { "application/x-shar", "shar" }, - { "application/x-stuffit", "sit" }, - { "application/x-sv4cpio", "sv4cpio" }, - { "application/x-sv4crc", "sv4crc" }, - { "application/x-tar", "tar" }, - { "application/x-tcl", "tcl" }, - { "application/x-tex", "tex" }, - { "application/x-texinfo", "texinfo" }, - { "application/x-texinfo", "texi" }, - { "application/x-troff", "t" }, - { "application/x-troff", "tr" }, - { "application/x-troff", "roff" }, - { "application/x-troff-man", "man" }, - { "application/x-troff-me", "me" }, - { "application/x-troff-ms", "ms" }, - { "application/x-ustar", "ustar" }, - { "application/x-wais-source", "src" }, - { "application/zip", "zip" }, - { "audio/basic", "au" }, - { "audio/basic", "snd" }, - { "audio/mpeg", "mpga" }, - { "audio/mpeg", "mp2" }, - { "audio/mpeg", "mp3" }, - { "audio/x-aiff", "aif" }, - { "audio/x-aiff", "aiff" }, - { "audio/x-aiff", "aifc" }, - { "audio/x-pn-realaudio", "ram" }, - { "audio/x-pn-realaudio-plugin", "rpm" }, - { "audio/x-realaudio", "ra" }, - { "audio/x-wav", "wav" }, - { "chemical/x-pdb", "pdb" }, - { "chemical/x-pdb", "xyz" }, - { "image/gif", "gif" }, - { "image/ief", "ief" }, - { "image/jpeg", "jpeg" }, - { "image/jpeg", "jpg" }, - { "image/jpeg", "jpe" }, - { "image/png", "png" }, - { "image/tiff", "tiff" }, - { "image/tiff", "tif" }, - { "image/x-cmu-raster", "ras" }, - { "image/x-portable-anymap", "pnm" }, - { "image/x-portable-bitmap", "pbm" }, - { "image/x-portable-graymap", "pgm" }, - { "image/x-portable-pixmap", "ppm" }, - { "image/x-rgb", "rgb" }, - { "image/x-xbitmap", "xbm" }, - { "image/x-xpixmap", "xpm" }, - { "image/x-xwindowdump", "xwd" }, - { "text/html", "html" }, - { "text/html", "htm" }, - { "text/plain", "txt" }, - { "text/richtext", "rtx" }, - { "text/tab-separated-values", "tsv" }, - { "text/x-setext", "etx" }, - { "text/x-sgml", "sgml" }, - { "text/x-sgml", "sgm" }, - { "video/mpeg", "mpeg" }, - { "video/mpeg", "mpg" }, - { "video/mpeg", "mpe" }, - { "video/quicktime", "qt" }, - { "video/quicktime", "mov" }, - { "video/x-msvideo", "avi" }, - { "video/x-sgi-movie", "movie" }, - { "x-conference/x-cooltalk", "ice" }, - { "x-world/x-vrml", "wrl" }, - { "x-world/x-vrml", "vrml" } + { "ai", "application/postscript" } + , { "aif", "audio/x-aiff" } + , { "aifc", "audio/x-aiff" } + , { "aiff", "audio/x-aiff" } + , { "asc", "text/plain" } + , { "au", "audio/basic" } + , { "avi", "video/x-msvideo" } + , { "bcpio", "application/x-bcpio" } + , { "bin", "application/octet-stream" } + , { "bmp", "image/bmp" } + , { "bz2", "application/x-bzip2" } + , { "cdf", "application/x-netcdf" } + , { "chrt", "application/x-kchart" } + , { "class", "application/octet-stream" } + , { "cpio", "application/x-cpio" } + , { "cpt", "application/mac-compactpro" } + , { "csh", "application/x-csh" } + , { "css", "text/css" } + , { "dcr", "application/x-director" } + , { "dir", "application/x-director" } + , { "djv", "image/vnd.djvu" } + , { "djvu", "image/vnd.djvu" } + , { "dll", "application/octet-stream" } + , { "dms", "application/octet-stream" } + , { "doc", "application/msword" } + , { "dvi", "application/x-dvi" } + , { "dxr", "application/x-director" } + , { "eps", "application/postscript" } + , { "etx", "text/x-setext" } + , { "exe", "application/octet-stream" } + , { "ez", "application/andrew-inset" } + , { "gif", "image/gif" } + , { "gtar", "application/x-gtar" } + , { "gz", "application/x-gzip" } + , { "hdf", "application/x-hdf" } + , { "hqx", "application/mac-binhex40" } + , { "htm", "text/html" } + , { "html", "text/html" } + , { "ice", "x-conference/x-cooltalk" } + , { "ief", "image/ief" } + , { "iges", "model/iges" } + , { "igs", "model/iges" } + , { "img", "application/octet-stream" } + , { "iso", "application/octet-stream" } + , { "jpe", "image/jpeg" } + , { "jpeg", "image/jpeg" } + , { "jpg", "image/jpeg" } + , { "js", "application/x-javascript" } + , { "kar", "audio/midi" } + , { "kil", "application/x-killustrator" } + , { "kpr", "application/x-kpresenter" } + , { "kpt", "application/x-kpresenter" } + , { "ksp", "application/x-kspread" } + , { "kwd", "application/x-kword" } + , { "kwt", "application/x-kword" } + , { "latex", "application/x-latex" } + , { "lha", "application/octet-stream" } + , { "lzh", "application/octet-stream" } + , { "m3u", "audio/x-mpegurl" } + , { "man", "application/x-troff-man" } + , { "me", "application/x-troff-me" } + , { "mesh", "model/mesh" } + , { "mid", "audio/midi" } + , { "midi", "audio/midi" } + , { "mif", "application/vnd.mif" } + , { "mov", "video/quicktime" } + , { "movie", "video/x-sgi-movie" } + , { "mp2", "audio/mpeg" } + , { "mp3", "audio/mpeg" } + , { "mpe", "video/mpeg" } + , { "mpeg", "video/mpeg" } + , { "mpg", "video/mpeg" } + , { "mpga", "audio/mpeg" } + , { "ms", "application/x-troff-ms" } + , { "msh", "model/mesh" } + , { "mxu", "video/vnd.mpegurl" } + , { "nc", "application/x-netcdf" } + , { "ogg", "application/ogg" } + , { "pbm", "image/x-portable-bitmap" } + , { "pdb", "chemical/x-pdb" } + , { "pdf", "application/pdf" } + , { "pgm", "image/x-portable-graymap" } + , { "pgn", "application/x-chess-pgn" } + , { "png", "image/png" } + , { "pnm", "image/x-portable-anymap" } + , { "ppm", "image/x-portable-pixmap" } + , { "ppt", "application/vnd.ms-powerpoint" } + , { "ps", "application/postscript" } + , { "qt", "video/quicktime" } + , { "ra", "audio/x-realaudio" } + , { "ram", "audio/x-pn-realaudio" } + , { "ras", "image/x-cmu-raster" } + , { "rgb", "image/x-rgb" } + , { "rm", "audio/x-pn-realaudio" } + , { "roff", "application/x-troff" } + , { "rpm", "application/x-rpm" } + , { "rtf", "text/rtf" } + , { "rtx", "text/richtext" } + , { "sgm", "text/sgml" } + , { "sgml", "text/sgml" } + , { "sh", "application/x-sh" } + , { "shar", "application/x-shar" } + , { "silo", "model/mesh" } + , { "sit", "application/x-stuffit" } + , { "skd", "application/x-koan" } + , { "skm", "application/x-koan" } + , { "skp", "application/x-koan" } + , { "skt", "application/x-koan" } + , { "smi", "application/smil" } + , { "smil", "application/smil" } + , { "snd", "audio/basic" } + , { "so", "application/octet-stream" } + , { "spl", "application/x-futuresplash" } + , { "src", "application/x-wais-source" } + , { "stc", "application/vnd.sun.xml.calc.template" } + , { "std", "application/vnd.sun.xml.draw.template" } + , { "sti", "application/vnd.sun.xml.impress.template" } + , { "stw", "application/vnd.sun.xml.writer.template" } + , { "sv4cpio", "application/x-sv4cpio" } + , { "sv4crc", "application/x-sv4crc" } + , { "swf", "application/x-shockwave-flash" } + , { "sxc", "application/vnd.sun.xml.calc" } + , { "sxd", "application/vnd.sun.xml.draw" } + , { "sxg", "application/vnd.sun.xml.writer.global" } + , { "sxi", "application/vnd.sun.xml.impress" } + , { "sxm", "application/vnd.sun.xml.math" } + , { "sxw", "application/vnd.sun.xml.writer" } + , { "t", "application/x-troff" } + , { "tar", "application/x-tar" } + , { "tcl", "application/x-tcl" } + , { "tex", "application/x-tex" } + , { "texi", "application/x-texinfo" } + , { "texinfo", "application/x-texinfo" } + , { "tgz", "application/x-gzip" } + , { "tif", "image/tiff" } + , { "tiff", "image/tiff" } + , { "torrent", "application/x-bittorrent" } + , { "tr", "application/x-troff" } + , { "tsv", "text/tab-separated-values" } + , { "txt", "text/plain" } + , { "ustar", "application/x-ustar" } + , { "vcd", "application/x-cdlink" } + , { "vrml", "model/vrml" } + , { "wav", "audio/x-wav" } + , { "wbmp", "image/vnd.wap.wbmp" } + , { "wbxml", "application/vnd.wap.wbxml" } + , { "wml", "text/vnd.wap.wml" } + , { "wmlc", "application/vnd.wap.wmlc" } + , { "wmls", "text/vnd.wap.wmlscript" } + , { "wmlsc", "application/vnd.wap.wmlscriptc" } + , { "wrl", "model/vrml" } + , { "xbm", "image/x-xbitmap" } + , { "xht", "application/xhtml+xml" } + , { "xhtml", "application/xhtml+xml" } + , { "xls", "application/vnd.ms-excel" } + , { "xml", "text/xml" } + , { "xpm", "image/x-xpixmap" } + , { "xsl", "text/xml" } + , { "xwd", "image/x-xwindowdump" } + , { "xyz", "chemical/x-xyz" } + , { "zip", "application/zip" } }; /** * The MIME types above are put into this Hashtable for faster lookup. */ - private static Hashtable mime_types = new Hashtable(150); - - // Static initializer to load MIME types into Hashtable - static - { - for (int i = 0; i < mime_strings.length; i++) - mime_types.put(mime_strings[i][1], mime_strings[i][0]); - } + private Hashtable mime_types = new Hashtable(150); /** * Create a new <code>MimeTypeMapper</code> object. */ public MimeTypeMapper() { - // Do nothing here. + for (int i = 0; i < mime_strings.length; i++) + mime_types.put(mime_strings[i][0], mime_strings[i][1]); + + // Now read from the system mime database, if it exists. Entries found + // here override our internal ones. + try + { + // On Linux this usually means /etc/mime.types. + String file + = SystemProperties.getProperty("gnu.classpath.mime.types.file"); + if (file != null) + fillFromFile(mime_types, file); + } + catch (IOException ignore) + { + } + } + + public static void fillFromFile (Map table, String fname) + throws IOException + { + LineNumberReader reader = + new LineNumberReader (new FileReader (fname)); + + while (reader.ready ()) + { + StringTokenizer tokenizer = + new StringTokenizer (reader.readLine ()); + + try + { + String t = tokenizer.nextToken (); + + if (! t.startsWith ("#")) + { + while (true) + { + // Read the next extension + String e = tokenizer.nextToken (); + if ((e != null) && (! e.startsWith ("#"))) + table.put (e, t); + else + break; + } + } + } + catch (NoSuchElementException ex) + { + // Do nothing. + } + } } /** @@ -210,4 +319,27 @@ class MimeTypeMapper implements FileNameMap else return type; } + + /** + * Run this class as a program to create a new mime_strings table. + */ + public static void main(String[] args) throws IOException + { + TreeMap map = new TreeMap(); + // It is fine to hard-code the name here. This is only ever + // used by maintainers, who can hack it if they need to re-run + // it. + fillFromFile(map, "/etc/mime.types"); + Iterator it = map.keySet().iterator(); + boolean first = true; + while (it.hasNext()) + { + String key = (String) it.next(); + String value = (String) map.get(key); + // Put the "," first since it is easier to make correct syntax this way. + System.out.println(" " + (first ? " " : ", ") + + "{ \"" + key + "\", \"" + value + "\" }"); + first = false; + } + } } diff --git a/libjava/classpath/java/net/URI.java b/libjava/classpath/java/net/URI.java index 39e8dadfc10..401352fcf3c 100644 --- a/libjava/classpath/java/net/URI.java +++ b/libjava/classpath/java/net/URI.java @@ -487,16 +487,14 @@ public final class URI for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); - if (legalCharacters.indexOf(c) == -1) + if ((legalCharacters.indexOf(c) == -1) + && (c <= 127)) { - if (c <= 127) - { - sb.append('%'); - sb.append(HEX.charAt(c / 16)); - sb.append(HEX.charAt(c % 16)); - } + sb.append('%'); + sb.append(HEX.charAt(c / 16)); + sb.append(HEX.charAt(c % 16)); } - else + else sb.append(c); } return sb.toString(); diff --git a/libjava/classpath/java/net/URLClassLoader.java b/libjava/classpath/java/net/URLClassLoader.java index 9e489db533f..183e645c85f 100644 --- a/libjava/classpath/java/net/URLClassLoader.java +++ b/libjava/classpath/java/net/URLClassLoader.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.net; +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.EOFException; import java.io.File; @@ -46,6 +47,7 @@ import java.io.FileInputStream; import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.security.AccessControlContext; import java.security.AccessController; import java.security.CodeSource; @@ -315,27 +317,51 @@ public class URLClassLoader extends SecureClassLoader jarfile = ((JarURLConnection) baseJarURL.openConnection()).getJarFile(); - + Manifest manifest; Attributes attributes; String classPathString; - if ((manifest = jarfile.getManifest()) != null + this.classPath = new Vector(); + + // This goes through the cached jar files listed + // in the INDEX.LIST file. All the jars found are added + // to the classPath vector so they can be loaded. + String dir = "META-INF/INDEX.LIST"; + if (jarfile.getEntry(dir) != null) + { + BufferedReader br = new BufferedReader(new InputStreamReader(new URL(baseJarURL, + dir).openStream())); + String line = br.readLine(); + while (line != null) + { + if (line.endsWith(".jar")) + { + try + { + this.classPath.add(new URL(baseURL, line)); + } + catch (java.net.MalformedURLException xx) + { + // Give up + } + } + line = br.readLine(); + } + } + else if ((manifest = jarfile.getManifest()) != null && (attributes = manifest.getMainAttributes()) != null && ((classPathString = attributes.getValue(Attributes.Name.CLASS_PATH)) != null)) - { - this.classPath = new Vector(); - + { StringTokenizer st = new StringTokenizer(classPathString, " "); while (st.hasMoreElements ()) { String e = st.nextToken (); try { - URL url = new URL(baseURL, e); - this.classPath.add(url); + this.classPath.add(new URL(baseURL, e)); } catch (java.net.MalformedURLException xx) { @@ -538,9 +564,14 @@ public class URLClassLoader extends SecureClassLoader { try { - File file = new File(dir, name).getCanonicalFile(); - if (file.exists() && !file.isDirectory()) - return new FileResource(this, file); + // Make sure that all components in name are valid by walking through + // them + File file = walkPathComponents(name); + + if (file == null) + return null; + + return new FileResource(this, file); } catch (IOException e) { @@ -548,6 +579,65 @@ public class URLClassLoader extends SecureClassLoader } return null; } + + /** + * Walk all path tokens and check them for validity. At no moment, we are + * allowed to reach a directory located "above" the root directory, stored + * in "dir" property. We are also not allowed to enter a non existing + * directory or a non directory component (plain file, symbolic link, ...). + * An empty or null path is valid. Pathnames components are separated by + * <code>File.separatorChar</code> + * + * @param resourceFileName the name to be checked for validity. + * @return the canonical file pointed by the resourceFileName or null if the + * walking failed + * @throws IOException in case of issue when creating the canonical + * resulting file + * @see File#separatorChar + */ + private File walkPathComponents(String resourceFileName) throws IOException + { + StringTokenizer stringTokenizer = new StringTokenizer(resourceFileName, File.separator); + File currentFile = dir; + int tokenCount = stringTokenizer.countTokens(); + + for (int i = 0; i < tokenCount - 1; i++) + { + String currentToken = stringTokenizer.nextToken(); + + // If we are at the root directory and trying to go up, the walking is + // finished with an error + if ("..".equals(currentToken) && currentFile.equals(dir)) + return null; + + currentFile = new File(currentFile, currentToken); + + // If the current file doesn't exist or is not a directory, the walking is + // finished with an error + if (! (currentFile.exists() && currentFile.isDirectory())) + return null; + + } + + // Treat the last token differently, if it exists, because it does not need + // to be a directory + if (tokenCount > 0) + { + String currentToken = stringTokenizer.nextToken(); + + if ("..".equals(currentToken) && currentFile.equals(dir)) + return null; + + currentFile = new File(currentFile, currentToken); + + // If the current file doesn't exist, the walking is + // finished with an error + if (! currentFile.exists()) + return null; + } + + return currentFile.getCanonicalFile(); + } } static final class FileResource extends Resource diff --git a/libjava/classpath/java/net/URLConnection.java b/libjava/classpath/java/net/URLConnection.java index b4a55a01a34..1f78dd8e8dd 100644 --- a/libjava/classpath/java/net/URLConnection.java +++ b/libjava/classpath/java/net/URLConnection.java @@ -1,5 +1,5 @@ /* URLConnection.java -- Abstract superclass for reading from URL's - Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,9 @@ exception statement from your version. */ package java.net; +import gnu.classpath.NotImplementedException; +import gnu.classpath.SystemProperties; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -49,6 +52,7 @@ import java.util.Collections; import java.util.Date; import java.util.Locale; import java.util.Map; +import java.util.StringTokenizer; /** * Written using on-line Java Platform 1.2 API Specification, as well @@ -114,6 +118,12 @@ public abstract class URLConnection private static boolean defaultUseCaches = true; /** + * Default internal content handler factory. + */ + private static ContentHandlerFactory defaultFactory + = new gnu.java.net.DefaultContentHandlerFactory(); + + /** * This variable determines whether or not interaction is allowed with * the user. For example, to prompt for a username and password. */ @@ -160,6 +170,7 @@ public abstract class URLConnection * This is the URL associated with this connection */ protected URL url; + private static SimpleDateFormat[] dateFormats; private static boolean dateformats_initialized; @@ -168,7 +179,7 @@ public abstract class URLConnection /** * Creates a URL connection to a given URL. A real connection is not made. - * Use #connect to do this. + * Use <code>connect()</code> to do this. * * @param url The Object to create the URL connection to * @@ -277,8 +288,8 @@ public abstract class URLConnection /** * Return a String representing the header value at the specified index. * This allows the caller to walk the list of header fields. The analogous - * getHeaderFieldKey(int) method allows access to the corresponding key - * for this header field + * {@link #getHeaderField(int)} method allows access to the corresponding + * key for this header field * * @param index The index into the header field list to retrieve the value for * @@ -305,9 +316,10 @@ public abstract class URLConnection } /** - * Returns a map of all sent header fields - * - * @return all header fields + * Returns an unmodifiable Map containing all sent header fields. + * + * @return The map of header fields. The map consists of String keys with + * an unmodifiable List of String objects as value. * * @since 1.4 */ @@ -355,7 +367,7 @@ public abstract class URLConnection * @param defaultValue The default date if the header field is not found * or can't be converted. * - * @return Returns the date value of the header filed or the default value + * @return The date value of the header filed or the default value * if the field is missing or malformed */ public long getHeaderFieldDate(String name, long defaultValue) @@ -388,8 +400,8 @@ public abstract class URLConnection /** * Returns a String representing the header key at the specified index. * This allows the caller to walk the list of header fields. The analogous - * getHeaderField(int) method allows access to the corresponding value for - * this tag. + * {@link #getHeaderField(int)} method allows access to the corresponding + * value for this tag. * * @param index The index into the header field list to retrieve the key for. * @@ -458,10 +470,16 @@ public abstract class URLConnection * @exception UnknownServiceException If the protocol does not support the * content type */ - public Object getContent(Class[] classes) throws IOException + public Object getContent(Class[] classes) + throws IOException { - // FIXME: implement this - return getContent(); + if (! connected) + connect(); + String type = getContentType(); + ContentHandler ch = getContentHandler(type); + if (ch != null) + return ch.getContent(this, classes); + throw new UnknownServiceException("protocol does not support the content type"); } /** @@ -722,7 +740,9 @@ public abstract class URLConnection } /** - * Sets the value of the named request property + * Sets the value of the named request property. + * This method does overwrite the value of existing properties with + * the new value. * * @param key The name of the property * @param value The value of the property @@ -757,8 +777,8 @@ public abstract class URLConnection * @exception IllegalStateException If already connected * @exception NullPointerException If key is null * - * @see URLConnection#getRequestProperty(String key) - * @see URLConnection#setRequestProperty(String key, String value) + * @see URLConnection#getRequestProperty(String) + * @see URLConnection#setRequestProperty(String, String) * * @since 1.4 */ @@ -783,8 +803,8 @@ public abstract class URLConnection * * @exception IllegalStateException If already connected * - * @see URLConnection#setRequestProperty(String key, String value) - * @see URLConnection#addRequestProperty(String key, String value) + * @see URLConnection#setRequestProperty(String, String) + * @see URLConnection#addRequestProperty(String, String) */ public String getRequestProperty(String key) { @@ -798,8 +818,9 @@ public abstract class URLConnection /** * Returns an unmodifiable Map containing the request properties. - * - * @return The map of properties + * + * @return The map of properties. The map consists of String keys with an + * unmodifiable List of String objects as value. * * @exception IllegalStateException If already connected * @@ -826,7 +847,7 @@ public abstract class URLConnection * @deprecated 1.3 The method setRequestProperty should be used instead. * This method does nothing now. * - * @see URLConnection#setRequestProperty(String key, String value) + * @see URLConnection#setRequestProperty(String, String) */ public static void setDefaultRequestProperty(String key, String value) { @@ -845,7 +866,7 @@ public abstract class URLConnection * @deprecated 1.3 The method getRequestProperty should be used instead. * This method does nothing now. * - * @see URLConnection#getRequestProperty(String key) + * @see URLConnection#getRequestProperty(String) */ public static String getDefaultRequestProperty(String key) { @@ -913,8 +934,10 @@ public abstract class URLConnection * @exception IOException If an error occurs */ public static String guessContentTypeFromStream(InputStream is) - throws IOException + throws IOException, NotImplementedException { + // See /etc/gnome-vfs-mime-magic or /etc/mime-magic for a reasonable + // idea of how to handle this. return "application/octet-stream"; } @@ -969,44 +992,66 @@ public abstract class URLConnection if (factory != null) handler = factory.createContentHandler(contentType); - // Then try our default class. - try - { - String typeClass = contentType.replace('/', '.'); + // Now try default factory. Using this factory to instantiate built-in + // content handlers is preferable + if (handler == null) + handler = defaultFactory.createContentHandler(contentType); - // 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) + // User-set factory has not returned a handler. Use the default search + // algorithm. + if (handler == null) { - // Ignore. + // Get the list of packages to check and append our default handler + // to it, along with the JDK specified default as a last resort. + // Except in very unusual environments the JDK specified one shouldn't + // ever be needed (or available). + String propVal = SystemProperties.getProperty("java.content.handler.pkgs"); + propVal = (((propVal == null) ? "" : (propVal + "|")) + + "gnu.java.net.content|sun.net.www.content"); + + // Deal with "Content-Type: text/html; charset=ISO-8859-1". + int parameterBegin = contentType.indexOf(';'); + if (parameterBegin >= 1) + contentType = contentType.substring(0, parameterBegin); + contentType = contentType.trim(); + + // Replace the '/' character in the content type with '.' and + // all other non-alphabetic, non-numeric characters with '_'. + char[] cArray = contentType.toCharArray(); + for (int i = 0; i < cArray.length; i++) + { + if (cArray[i] == '/') + cArray[i] = '.'; + else if (! ((cArray[i] >= 'A' && cArray[i] <= 'Z') || + (cArray[i] >= 'a' && cArray[i] <= 'z') || + (cArray[i] >= '0' && cArray[i] <= '9'))) + cArray[i] = '_'; + } + String contentClass = new String(cArray); + + // See if a class of this content type exists in any of the packages. + StringTokenizer pkgPrefix = new StringTokenizer(propVal, "|"); + do + { + String facName = pkgPrefix.nextToken() + "." + contentClass; + try + { + handler = + (ContentHandler) Class.forName(facName).newInstance(); + } + catch (Exception e) + { + // Can't instantiate; handler still null, go on to next element. + } + } while (handler == null && pkgPrefix.hasMoreTokens()); } 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). + // with initializer co-dependency: SimpleDateFormat's constructors + // eventually depend on URLConnection (via the java.text.*Symbols classes). private static synchronized void initializeDateFormats() { if (dateformats_initialized) diff --git a/libjava/classpath/java/net/class-dependencies.conf b/libjava/classpath/java/net/class-dependencies.conf deleted file mode 100644 index 8b130f53684..00000000000 --- a/libjava/classpath/java/net/class-dependencies.conf +++ /dev/null @@ -1,122 +0,0 @@ -# This property file contains dependencies of classes, methods, and -# field on other methods or classes. -# -# Syntax: -# -# <used>: <needed 1> [... <needed N>] -# -# means that when <used> is included, <needed 1> (... <needed N>) must -# be included as well. -# -# <needed X> and <used> are of the form -# -# <class.methodOrField(signature)> -# -# or just -# -# <class> -# -# Within dependencies, variables can be used. A variable is defined as -# follows: -# -# {variable}: value1 value2 ... value<n> -# -# variables can be used on the right side of dependencies as follows: -# -# <used>: com.bla.blu.{variable}.Class.m()V -# -# The use of the variable will expand to <n> dependencies of the form -# -# <used>: com.bla.blu.value1.Class.m()V -# <used>: com.bla.blu.value2.Class.m()V -# ... -# <used>: com.bla.blu.value<n>.Class.m()V -# -# Variables can be redefined when building a system to select the -# required support for features like encodings, protocols, etc. -# -# Hints: -# -# - For methods and fields, the signature is mandatory. For -# specification, please see the Java Virtual Machine Specification by -# SUN. Unlike in the spec, field signatures (types) are in brackets. -# -# - Package names must be separated by '/' (and not '.'). E.g., -# java/lang/Class (this is necessary, because the '.' is used to -# separate method or field names from classes) -# -# - In case <needed> refers to a class, only the class itself will be -# included in the resulting binary, NOT necessarily all its methods -# and fields. If you want to refer to all methods and fields, you can -# write class.* as an abbreviation. -# -# - Abbreviations for packages are also possible: my/package/* means all -# methods and fields of all classes in my/package. -# -# - A line with a trailing '\' continues in the next line. - -java/net/InetAddress: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/net/UnknownHostException.<init>(Ljava/lang/String;)V - -java/net/DatagramSocketImpl: \ - java/net/DatagramSocketImpl.fd(Ljava/io/FileDescriptor;) \ - java/net/DatagramSocketImpl.localPort(I) - -java/net/PlainDatagramSocketImpl: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V \ - java/io/FileDescriptor.<init>()V \ - java/lang/Boolean.<init>(Z)V \ - java/lang/Integer.<init>(I)V \ - java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \ - java/net/InetAddress.getAddress()[B \ - java/lang/Boolean.booleanValue()Z \ - java/lang/Integer.intValue()I \ - java/net/SocketException.<init>(Ljava/lang/String;)V \ - java/net/DatagramPacket.getData()[B \ - java/net/SocketImpl.address(Ljava/net/InetAddress;) \ - java/net/PlainSocketImpl.native_fd(I) \ - java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \ - java/net/SocketImpl.address(Ljava/net/InetAddress;) \ - java/net/PlainDatagramSocketImpl.native_fd(I) \ - java/net/SocketImpl.localport(I) \ - java/net/SocketImpl.port(I) - -java/net/PlainSocketImpl: \ - java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \ - java/lang/InternalError.<init>(Ljava/lang/String;)V \ - java/io/IOException.<init>(Ljava/lang/String;)V \ - java/io/FileDescriptor.<init>()V \ - java/lang/Boolean.<init>(Z)V \ - java/lang/Integer.<init>(I)V \ - java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \ - java/net/InetAddress.getAddress()[B \ - java/lang/Boolean.booleanValue()Z \ - java/lang/Integer.intValue()I \ - java/net/SocketException.<init>(Ljava/lang/String;)V \ - java/net/DatagramPacket.getData()[B \ - java/net/SocketImpl.address(Ljava/net/InetAddress;) \ - java/net/PlainSocketImpl.native_fd(I) \ - java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \ - java/net/SocketImpl.address(Ljava/net/InetAddress;) \ - java/net/PlainDatagramSocketImpl.native_fd(I) \ - java/net/SocketImpl.localport(I) \ - java/net/SocketImpl.port(I) - -# All protocols supported are loaded via URL.getURLStreamHandler from -# class gnu.java.net.protocol.<protocol>.Handler. -# -# This introduces a dependency for all protocols. To allow an easy selection -# and addition of protocols, the library variable {protocols} can be set to -# the set of supported protocols. -# -{protocols}: http file jar - -java/net/URL.getURLStreamHandler(Ljava/lang/String;)Ljava/net/URLStreamHandler;: \ - gnu/java/net/protocol/{protocols}/Handler.* \ - com/aicas/java/net/protocol/rom/Handler.* - -# end of file |