home *** CD-ROM | disk | FTP | other *** search
- package netscape.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.net.UnknownServiceException;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import netscape.applet.AppletSecurity;
-
- public class URLConnection extends java.net.URLConnection {
- static final String EOL = "\r\n";
- int pStreamData;
- URLInputStream currentInputStream;
- URLOutputStream currentOutputStream;
- String postHeaders;
- Hashtable properties;
- static Hashtable defaultProperties;
-
- protected URLConnection(URL url) {
- super(url);
- String hostAddress = null;
-
- try {
- hostAddress = url.getHostAddress();
- } catch (UnknownHostException var3) {
- } catch (SecurityException var4) {
- }
-
- this.pCreate(url.toExternalForm(), hostAddress);
- }
-
- private native void pCreate(String var1, String var2);
-
- protected native void finalize();
-
- public void connect() throws IOException {
- if (!super.connected) {
- SecurityManager security = System.getSecurityManager();
- if (security != null && security instanceof AppletSecurity) {
- ((AppletSecurity)security).checkURLConnect(super.url);
- }
-
- super.connected = true;
- StringBuffer propString = new StringBuffer();
- if (this.postHeaders != null) {
- propString.append(this.postHeaders);
- }
-
- boolean contentTypeSet = false;
- Hashtable props = this.properties;
- if (props == null) {
- props = defaultProperties;
- }
-
- if (props != null) {
- Enumeration keys = props.keys();
-
- while(keys.hasMoreElements()) {
- String key = (String)keys.nextElement();
- if (!key.equalsIgnoreCase("Content-length")) {
- if (key.equalsIgnoreCase("Content-type")) {
- contentTypeSet = true;
- }
-
- String value = (String)props.get(key);
- propString.append(key);
- propString.append(":");
- propString.append(value);
- propString.append("\r\n");
- }
- }
- }
-
- if (!contentTypeSet) {
- propString.append("Content-type: multipart/form-data");
- propString.append("\r\n");
- }
-
- this.postHeaders = propString.toString();
- this.properties = null;
- if (this.currentOutputStream != null) {
- this.currentOutputStream.close();
- }
-
- URLInputStream in = (URLInputStream)this.getInputStream();
- in.open();
- }
- }
-
- public int getContentLength() {
- try {
- this.getInputStream();
- } catch (Exception var1) {
- return -1;
- }
-
- return this.getContentLength0();
- }
-
- public native int getContentLength0();
-
- public String getContentType() {
- try {
- this.getInputStream();
- } catch (Exception var1) {
- return null;
- }
-
- return this.getContentType0();
- }
-
- public native String getContentType0();
-
- public String getHeaderField(String name) {
- try {
- this.getInputStream();
- } catch (Exception var2) {
- return null;
- }
-
- return this.getHeaderField0(name);
- }
-
- public native String getHeaderField0(String var1);
-
- public String getHeaderFieldKey(int n) {
- try {
- this.getInputStream();
- } catch (Exception var2) {
- return null;
- }
-
- return this.getHeaderFieldKey0(n);
- }
-
- public native String getHeaderFieldKey0(int var1);
-
- public InputStream getInputStream() throws IOException {
- if (!super.connected) {
- this.connect();
- }
-
- if (!super.doInput) {
- throw new UnknownServiceException("protocol doesn't support input");
- } else {
- if (this.currentInputStream == null) {
- this.currentInputStream = new URLInputStream(this);
- }
-
- return this.currentInputStream;
- }
- }
-
- public OutputStream getOutputStream() throws IOException {
- if (super.connected) {
- throw new IllegalAccessError("Already connected");
- } else if (!super.doOutput) {
- throw new UnknownServiceException("protocol doesn't support output");
- } else {
- if (this.currentOutputStream == null) {
- this.currentOutputStream = new URLOutputStream(this);
- this.currentOutputStream.open();
- }
-
- return this.currentOutputStream;
- }
- }
-
- public void setRequestProperty(String key, String value) {
- if (super.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- if (this.properties == null) {
- this.properties = new Hashtable();
- }
-
- if (value != null) {
- this.properties.put(key, value);
- } else {
- this.properties.remove(key);
- }
- }
- }
-
- public String getRequestProperty(String key) {
- if (super.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- return this.properties == null ? null : (String)this.properties.get(key);
- }
- }
-
- public static void setDefaultRequestProperty(String key, String value) {
- if (defaultProperties == null) {
- defaultProperties = new Hashtable();
- }
-
- if (value != null) {
- defaultProperties.put(key, value);
- } else {
- defaultProperties.remove(key);
- }
- }
-
- public static String getDefaultRequestProperty(String key) {
- return defaultProperties == null ? null : (String)defaultProperties.get(key);
- }
-
- native void close() throws IOException;
- }
-