1999-04-07 16:42:40 +02:00
|
|
|
// URLConnection.java - Superclass of all communications links between
|
|
|
|
// an application and a URL.
|
|
|
|
|
2000-03-07 20:55:28 +01:00
|
|
|
/* Copyright (C) 1999, 2000 Free Software Foundation
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
package java.net;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.text.ParsePosition;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Hashtable;
|
2002-08-23 06:54:03 +02:00
|
|
|
import java.util.Map;
|
1999-04-07 16:42:40 +02:00
|
|
|
import java.util.StringTokenizer;
|
2002-09-12 08:35:51 +02:00
|
|
|
import java.security.Permission;
|
|
|
|
import java.security.AllPermission;
|
2000-02-21 06:54:29 +01:00
|
|
|
import gnu.gcj.io.MimeTypes;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Warren Levy <warrenl@cygnus.com>
|
|
|
|
* @date March 5, 1999.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Written using on-line Java Platform 1.2 API Specification, as well
|
|
|
|
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
|
2000-02-21 06:54:29 +01:00
|
|
|
* Status: One guessContentTypeFrom... methods not implemented.
|
2002-09-13 13:39:47 +02:00
|
|
|
* getContent method assumes content type from response; see comment there.
|
1999-04-07 16:42:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public abstract class URLConnection
|
|
|
|
{
|
|
|
|
protected URL url;
|
|
|
|
protected boolean doInput = true;
|
|
|
|
protected boolean doOutput = false;
|
|
|
|
protected boolean allowUserInteraction;
|
|
|
|
protected boolean useCaches;
|
|
|
|
protected long ifModifiedSince = 0L;
|
|
|
|
protected boolean connected = false;
|
|
|
|
private static boolean defaultAllowUserInteraction = false;
|
|
|
|
private static boolean defaultUseCaches = true;
|
|
|
|
private static FileNameMap fileNameMap; // Set by the URLConnection subclass.
|
|
|
|
private static ContentHandlerFactory factory;
|
|
|
|
private static ContentHandler contentHandler;
|
|
|
|
private static Hashtable handlers = new Hashtable();
|
2000-02-25 23:38:33 +01:00
|
|
|
private static Locale locale;
|
|
|
|
private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3;
|
|
|
|
private static boolean dateformats_initialized = false;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Creates a URL connection to a given URL. A real connection is not made.
|
|
|
|
* Use #connect to do this.
|
|
|
|
*
|
|
|
|
* @param url The Object to create the URL connection to
|
|
|
|
*
|
|
|
|
* @see URLConnection:connect
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
protected URLConnection(URL url)
|
|
|
|
{
|
|
|
|
this.url = url;
|
|
|
|
allowUserInteraction = defaultAllowUserInteraction;
|
|
|
|
useCaches = defaultUseCaches;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Creates a real connection to the object references by the URL given
|
|
|
|
* to the constructor
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public abstract void connect() throws IOException;
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns ths URL to the object.
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public URL getURL()
|
|
|
|
{
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the content-length header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public int getContentLength()
|
|
|
|
{
|
|
|
|
return getHeaderFieldInt("content-length", -1);
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the content-type header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public String getContentType()
|
|
|
|
{
|
|
|
|
return getHeaderField("content-type");
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the content-encoding header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public String getContentEncoding()
|
|
|
|
{
|
|
|
|
return getHeaderField("content-encoding");
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the expires header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public long getExpiration()
|
|
|
|
{
|
|
|
|
return getHeaderFieldDate("expiration", 0L);
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the date header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public long getDate()
|
|
|
|
{
|
|
|
|
return getHeaderFieldDate("date", 0L);
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the last-modified header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public long getLastModified()
|
|
|
|
{
|
|
|
|
return getHeaderFieldDate("last-modified", 0L);
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the n-th header field
|
|
|
|
*
|
|
|
|
* @param num The number of the header field
|
|
|
|
*/
|
|
|
|
public String getHeaderField(int num)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the header filed specified by name
|
|
|
|
*
|
|
|
|
* @param name The name of the header field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public String getHeaderField(String name)
|
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-08-23 06:54:03 +02:00
|
|
|
/**
|
2002-09-12 08:35:51 +02:00
|
|
|
* Returns a map of all sent header fields
|
|
|
|
*
|
2002-08-23 06:54:03 +02:00
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public Map getHeaderFields()
|
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of the header filed name as int.
|
|
|
|
*
|
|
|
|
* @param name The name of the header field
|
|
|
|
* @param val The default value
|
|
|
|
*
|
|
|
|
* @return Returns the value of the header filed or the default value
|
|
|
|
* if the field is missing or malformed
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public int getHeaderFieldInt(String name, int val)
|
|
|
|
{
|
|
|
|
String str = getHeaderField(name);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (str != null)
|
|
|
|
val = Integer.parseInt(str);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
; // Do nothing; val is the default.
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of a header field parsed as date. The result is then
|
|
|
|
* number of milliseconds since January 1st, 1970 GMT.
|
|
|
|
*
|
|
|
|
* @param name The name of the header field
|
|
|
|
* @param val The dafault date
|
|
|
|
*
|
|
|
|
* @return Returns the date value of the header filed or the default value
|
|
|
|
* if the field is missing or malformed
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public long getHeaderFieldDate(String name, long val)
|
|
|
|
{
|
2000-02-25 23:38:33 +01:00
|
|
|
if (! dateformats_initialized)
|
|
|
|
initializeDateFormats();
|
1999-04-07 16:42:40 +02:00
|
|
|
String str = getHeaderField(name);
|
|
|
|
if (str != null)
|
|
|
|
{
|
|
|
|
Date date;
|
|
|
|
if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
|
|
|
|
val = date.getTime();
|
|
|
|
else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
|
|
|
|
val = date.getTime();
|
|
|
|
else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
|
|
|
|
val = date.getTime();
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the key of the n-th header field
|
|
|
|
*
|
|
|
|
* @param num The number of the header field
|
|
|
|
*/
|
|
|
|
public String getHeaderFieldKey(int num)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the content of this URLConnection
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public Object getContent() throws IOException
|
|
|
|
{
|
|
|
|
// 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 cType = getContentType();
|
|
|
|
contentHandler = setContentHandler(cType);
|
|
|
|
if (contentHandler == null)
|
|
|
|
return getInputStream();
|
|
|
|
|
|
|
|
return contentHandler.getContent(this);
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns a permission object representing the permission necessary to make
|
|
|
|
* the connection represented by this object. This method returns null if no
|
|
|
|
* permission is required to make the connection.
|
|
|
|
*/
|
|
|
|
public Permission getPermission() throws IOException
|
|
|
|
{
|
|
|
|
// Subclasses may override this.
|
|
|
|
return new java.security.AllPermission();
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the input stream of the URL connection
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public InputStream getInputStream() throws IOException
|
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
throw new UnknownServiceException("Protocol " + url.getProtocol() +
|
|
|
|
" does not support input.");
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the output stream of the URL connection
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public OutputStream getOutputStream() throws IOException
|
|
|
|
{
|
|
|
|
// Subclasses for specific protocols override this.
|
|
|
|
throw new UnknownServiceException("Protocol " + url.getProtocol() +
|
|
|
|
" does not support output.");
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns a string representation of the URL connection object
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return this.getClass().getName() + ":" + url.toString();
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets tha value of the doInput field.
|
|
|
|
*
|
|
|
|
* @param doinput The new value of the doInput field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setDoInput(boolean doinput)
|
|
|
|
{
|
|
|
|
if (connected)
|
|
|
|
throw new IllegalAccessError("Already connected");
|
|
|
|
|
|
|
|
doInput = doinput;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the current value of the doInput field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public boolean getDoInput()
|
|
|
|
{
|
|
|
|
return doInput;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets the value of the doOutput field
|
|
|
|
*
|
|
|
|
* @param dooutput The new value of the doOutput field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setDoOutput(boolean dooutput)
|
|
|
|
{
|
|
|
|
if (connected)
|
|
|
|
throw new IllegalAccessError("Already connected");
|
|
|
|
|
|
|
|
doOutput = dooutput;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the current value of the doOutput field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public boolean getDoOutput()
|
|
|
|
{
|
|
|
|
return doOutput;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets a new value to the allowUserInteraction field
|
|
|
|
*
|
|
|
|
* @param allowed The new value
|
|
|
|
*/
|
|
|
|
public void setAllowUserInteraction(boolean allowed)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
if (connected)
|
|
|
|
throw new IllegalAccessError("Already connected");
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
allowUserInteraction = allowed;
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the current value of the allowUserInteraction field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public boolean getAllowUserInteraction()
|
|
|
|
{
|
|
|
|
return allowUserInteraction;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets the default value if the allowUserInteraction field
|
|
|
|
*
|
|
|
|
* @param allowed The new default value
|
|
|
|
*/
|
|
|
|
public static void setDefaultAllowUserInteraction(boolean allowed)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2002-09-12 08:35:51 +02:00
|
|
|
defaultAllowUserInteraction = allowed;
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the default value of the allowUserInteraction field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static boolean getDefaultAllowUserInteraction()
|
|
|
|
{
|
|
|
|
return defaultAllowUserInteraction;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets a new value to the useCaches field
|
|
|
|
*
|
|
|
|
* @param usecaches The new value
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setUseCaches(boolean usecaches)
|
|
|
|
{
|
|
|
|
if (connected)
|
|
|
|
throw new IllegalAccessError("Already connected");
|
|
|
|
|
|
|
|
useCaches = usecaches;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* The current value of the useCaches field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public boolean getUseCaches()
|
|
|
|
{
|
|
|
|
return useCaches;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets the value of the ifModifiedSince field
|
|
|
|
*
|
|
|
|
* @param ifmodifiedsince The new value in milliseconds
|
|
|
|
* since January 1, 1970 GMT
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setIfModifiedSince(long ifmodifiedsince)
|
|
|
|
{
|
|
|
|
if (connected)
|
|
|
|
throw new IllegalAccessError("Already connected");
|
|
|
|
|
|
|
|
ifModifiedSince = ifmodifiedsince;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the current value of the ifModifiedSince field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public long getIfModifiedSince()
|
|
|
|
{
|
|
|
|
return ifModifiedSince;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns the default value of the useCaches field
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public boolean getDefaultUseCaches()
|
|
|
|
{
|
|
|
|
return defaultUseCaches;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets the default value of the useCaches field
|
|
|
|
*
|
|
|
|
* @param defaultusecaches The new default value
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setDefaultUseCaches(boolean defaultusecaches)
|
|
|
|
{
|
|
|
|
defaultUseCaches = defaultusecaches;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets a property specified by key to value.
|
|
|
|
*
|
|
|
|
* @param key Key of the property to set
|
|
|
|
* @param value Value of the Property to set
|
|
|
|
*
|
|
|
|
* @see URLConnection:getRequestProperty(String key)
|
|
|
|
* @see URLConnection:addRequestProperty/String key, String value)
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public void setRequestProperty(String key, String value)
|
|
|
|
{
|
|
|
|
// Do nothing unless overridden by subclasses that support setting
|
|
|
|
// header fields in the request.
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets a property specified by key to value. If the property key already
|
|
|
|
* is assigned to a value it does nothing.
|
|
|
|
*
|
|
|
|
* @param key Key of the property to add
|
|
|
|
* @param value Value of the Property to add
|
|
|
|
*
|
|
|
|
* @see URLConnection:getRequestProperty(String key)
|
|
|
|
* @see URLConnection:setRequestProperty(String key, String value)
|
|
|
|
*
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public void addRequestProperty(String key, String value)
|
|
|
|
{
|
|
|
|
if (getRequestProperty (key) == null)
|
|
|
|
{
|
|
|
|
setRequestProperty (key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a property value specified by key.
|
|
|
|
*
|
|
|
|
* @param key Key of the property to return
|
|
|
|
*
|
|
|
|
* @see URLConnection:setRequestProperty(String key, String value)
|
|
|
|
* @see URLConnection:addRequestProperty(String key, String value)
|
|
|
|
*
|
|
|
|
* @return Value of the property.
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public String getRequestProperty(String key)
|
|
|
|
{
|
|
|
|
// Overridden by subclasses that support reading header fields from the
|
|
|
|
// request.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Returns a map that contains all properties of the request
|
|
|
|
*
|
|
|
|
* @return The map of properties
|
|
|
|
*/
|
|
|
|
public Map getRequestProperties()
|
|
|
|
{
|
|
|
|
// Overridden by subclasses that support reading header fields from the
|
|
|
|
// request.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a default request property
|
|
|
|
*
|
|
|
|
* @param key The key of the property
|
|
|
|
* @param value The value of the property
|
|
|
|
*
|
|
|
|
* @deprecated 1.3 The method setRequestProperty should be used instead
|
|
|
|
*
|
|
|
|
* @see URLConnection:setRequestProperty
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static void setDefaultRequestProperty(String key, String value)
|
|
|
|
{
|
|
|
|
// Do nothing unless overridden by subclasses that support setting
|
|
|
|
// default request properties.
|
|
|
|
}
|
|
|
|
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
/**
|
2002-09-12 08:35:51 +02:00
|
|
|
* Returns the value of a default request property
|
|
|
|
*
|
|
|
|
* @param key The key of the default property
|
|
|
|
*
|
|
|
|
* @return The value of the default property or null if not available
|
|
|
|
*
|
|
|
|
* @deprecated 1.3 The method getRequestProperty should be used instead
|
|
|
|
*
|
|
|
|
* @see URLConnection:getRequestProperty
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static String getDefaultRequestProperty(String key)
|
|
|
|
{
|
|
|
|
// Overridden by subclasses that support default request properties.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Sets a ContentHandlerFactory
|
|
|
|
*
|
|
|
|
* @param fac The ContentHandlerFactory
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static void setContentHandlerFactory(ContentHandlerFactory fac)
|
|
|
|
{
|
|
|
|
if (factory != null)
|
|
|
|
throw new Error("ContentHandlerFactory already set");
|
|
|
|
|
|
|
|
// Throw an exception if an extant security mgr precludes
|
|
|
|
// setting the factory.
|
|
|
|
SecurityManager s = System.getSecurityManager();
|
|
|
|
if (s != null)
|
|
|
|
s.checkSetFactory();
|
|
|
|
factory = fac;
|
|
|
|
}
|
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Tries to determine the content type of an object, based on the
|
|
|
|
* specified file name
|
|
|
|
*
|
|
|
|
* @param fname The filename to guess the content type from
|
|
|
|
*/
|
2000-02-21 06:54:29 +01:00
|
|
|
protected static String guessContentTypeFromName(String fname)
|
|
|
|
{
|
|
|
|
int dot = fname.lastIndexOf (".");
|
|
|
|
|
|
|
|
if (dot != -1)
|
|
|
|
{
|
|
|
|
if (dot == fname.length())
|
|
|
|
return ("application/octet-stream");
|
|
|
|
else
|
|
|
|
fname = fname.substring (dot + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
String type = MimeTypes.getMimeTypeFromExtension (fname);
|
|
|
|
|
|
|
|
if (type == null)
|
|
|
|
return("application/octet-stream");
|
|
|
|
|
|
|
|
return(type);
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2002-09-12 08:35:51 +02:00
|
|
|
/**
|
|
|
|
* Tries to guess the content type of an object, based on the characters
|
|
|
|
* at the beginning of then input stream
|
|
|
|
*
|
|
|
|
* @param is The input stream to guess from
|
|
|
|
*
|
|
|
|
* @exception IOException If an error occurs
|
|
|
|
*/
|
|
|
|
public static String guessContentTypeFromStream(InputStream is)
|
|
|
|
throws IOException
|
|
|
|
{
|
|
|
|
is.mark(1024);
|
|
|
|
// FIXME: Implement this. Use system mimetype informations (like "file").
|
|
|
|
is.reset();
|
|
|
|
return null;
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
/**
|
2002-09-12 08:35:51 +02:00
|
|
|
* Returns a filename map (a mimetable)
|
|
|
|
*
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
* @since 1.2
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static FileNameMap getFileNameMap()
|
|
|
|
{
|
|
|
|
return fileNameMap;
|
|
|
|
}
|
|
|
|
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
/**
|
2002-09-12 08:35:51 +02:00
|
|
|
* Sets a FileNameMap
|
|
|
|
*
|
|
|
|
* @param map The new FileNameMap
|
|
|
|
*
|
BindException.java, [...]: add/update of some @since/@deprecated
2002-08-27 Michael Koch <konqueror@gmx.de>
* java/net/BindException.java,
java/net/JarURLConnection.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/InetSocketAddress.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/MulticastSocket.java,
java/net/PasswordAuthentication.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java: add/update of some @since/@deprecated
From-SVN: r56608
2002-08-27 19:47:27 +02:00
|
|
|
* @since 1.2
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public static void setFileNameMap(FileNameMap map)
|
|
|
|
{
|
|
|
|
// Throw an exception if an extant security mgr precludes
|
|
|
|
// setting the factory.
|
|
|
|
SecurityManager s = System.getSecurityManager();
|
|
|
|
if (s != null)
|
|
|
|
s.checkSetFactory();
|
|
|
|
|
|
|
|
fileNameMap = map;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentHandler setContentHandler(String contentType)
|
|
|
|
{
|
|
|
|
ContentHandler handler;
|
|
|
|
|
|
|
|
// No content type so just handle it as the default.
|
|
|
|
if (contentType == null || contentType == "")
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// See if a handler has been cached for this content type.
|
|
|
|
// For efficiency, if a content type has been searched for but not
|
|
|
|
// found, it will be in the hash table but as the contentType String
|
|
|
|
// instead of a ContentHandler.
|
|
|
|
if ((handler = (ContentHandler) handlers.get(contentType)) != null)
|
|
|
|
if (handler instanceof ContentHandler)
|
|
|
|
return handler;
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// If a non-default factory has been set, use it to find the content type.
|
|
|
|
if (factory != null)
|
|
|
|
handler = factory.createContentHandler(contentType);
|
|
|
|
|
|
|
|
// Non-default factory may have returned null or a factory wasn't set.
|
|
|
|
// Use the default search algorithm to find a handler for this content type.
|
|
|
|
if (handler == null)
|
|
|
|
{
|
|
|
|
// 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 = System.getProperty("java.content.handler.pkgs");
|
|
|
|
propVal = (propVal == null) ? "" : (propVal + "|");
|
|
|
|
propVal = propVal + "gnu.gcj.content|sun.net.www.content";
|
|
|
|
|
|
|
|
// Replace the '/' character in the content type with '.' and
|
|
|
|
// all other non-alphabetic, non-numeric characters with '_'.
|
|
|
|
StringTokenizer pkgPrefix = new StringTokenizer(propVal, "|");
|
|
|
|
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.
|
|
|
|
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 ||
|
|
|
|
! (handler instanceof ContentHandler)) &&
|
|
|
|
pkgPrefix.hasMoreTokens());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the hashtable with the new content handler.
|
|
|
|
if (handler != null && handler instanceof ContentHandler)
|
|
|
|
{
|
|
|
|
handlers.put(contentType, handler);
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For efficiency on subsequent searches, put a dummy entry in the hash
|
|
|
|
// table for content types that don't have a non-default ContentHandler.
|
|
|
|
handlers.put(contentType, contentType);
|
|
|
|
return null;
|
|
|
|
}
|
2000-02-25 23:38:33 +01:00
|
|
|
|
|
|
|
// 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).
|
|
|
|
private synchronized void initializeDateFormats()
|
|
|
|
{
|
|
|
|
if (dateformats_initialized)
|
|
|
|
return;
|
|
|
|
locale = new Locale("En", "Us", "Unix");
|
|
|
|
dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
|
|
|
|
locale);
|
|
|
|
dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'",
|
|
|
|
locale);
|
|
|
|
dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
|
|
|
|
dateformats_initialized = true;
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|