001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * Functionality :
014: * Reads the Proxy information from Java Plugin.
015: * Works for Java plugin 1.3.1_02 and 1.4 versions.
016: * Singleton class, multithreding is not taken care of.
017: *
018: * @ created 04/02/2002
019: * @ Author Deepak
020: */package com.sun.portal.netlet.client.applet;
021:
022: import com.sun.portal.netlet.client.common.*;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.awt.*;
026:
027: public class AppletProxyInfo implements ProxyInfo, ActionListener {
028:
029: private boolean proxyMode = false;
030: private String proxySSL = ""; // SSL proxy host
031: private int proxySSLPort = 0; // SSL proxy port
032:
033: private ProxyWarning pw = null;
034: private ProxyPortDialog ppd;
035:
036: /*
037: * Default constructor - reads the proxy information ( Proxy mode,
038: * SSL proxy host, SSL proxy port, Proxy Bypass list).
039: */
040: public AppletProxyInfo() {
041:
042: ppd = new ProxyPortDialog(new Frame(), this );
043:
044: BrowserType browser = BrowserType.getInstance();
045:
046: if (browser.getNetscapeBrowser()
047: && browser.getJavaVMVersion() == 1) {
048: BrowserProxyInfo bInfo = new BrowserProxyInfo(this );
049: if (bInfo.getProxyType() == 3) {
050: // not using proxies
051: System.out.println("Netlet not using proxy (Netscape)");
052: } else {
053: bInfo.setLocalhostNoProxy();
054: proxySSL = bInfo.getProxySSL();
055: proxySSLPort = bInfo.getProxySSLPort();
056: proxyMode = true;
057: System.out
058: .println("Netlet using proxy (Netscape): host:"
059: + proxySSL + " port:" + proxySSLPort);
060: if ((bInfo.getProxyType() == 2)
061: && (proxySSL.equals("") || (proxySSLPort == 0))) {
062: pw.setVisible(true);
063: return;
064: }
065: }
066: } else if (browser.getAppleBrowser()
067: && browser.getJavaVMVersion() == 1) {
068: AppleBrowserProxyInfo aInfo = new AppleBrowserProxyInfo();
069: if (aInfo.getProxyMode()) {
070: proxyMode = true;
071: proxySSL = aInfo.getProxyHost();
072: proxySSLPort = aInfo.getProxyPort();
073: if (proxySSLPort == 0) {
074: // get pport from user
075: ppd.showWarning();
076: ppd.waitForAction();
077: }
078: pw.setVisible(aInfo.needProxyWarning());
079: }
080: } else if (browser.getJavaVMVersion() == 2) {
081: PluginProxyInfo pInfo = new PluginProxyInfo();
082: if (pInfo.getProxyMode()) {
083: proxyMode = true;
084: proxySSL = pInfo.getProxySSL();
085: proxySSLPort = pInfo.getProxySSLPort();
086: System.out.println("Netlet using proxy : host: "
087: + proxySSL + " port: " + proxySSLPort);
088: } else {
089: proxySSL = null;
090: proxySSLPort = 0;
091: proxyMode = false;
092: System.out.println("Netlet not using proxy");
093: }
094: } else {
095: Win32Reg regApp = new Win32Reg(this );
096: regApp.startWin32Reg(false);
097: proxySSL = regApp.getProxyHost(); //System.getProperty("http.proxyHost");
098: if ((proxySSL == null) || (proxySSL.equals(""))) {
099: proxyMode = false;
100: proxySSL = "";
101: proxySSLPort = 0;
102: System.out.println("Netlet not using proxy (IE)");
103: if (regApp.autoConfig()) {
104: pw.setVisible(true);
105: return;
106: }
107: } else {
108: proxyMode = true;
109: proxySSLPort = regApp.getProxyPort();
110: if (proxySSLPort == 0) {
111: proxySSL = "";
112: }
113: System.out.println("Netlet using proxy (IE): host:"
114: + proxySSL + " port:" + proxySSLPort);
115: }
116: }
117: }
118:
119: /*
120: * Returns SSL proxy host
121: */
122:
123: public String getProxySSL() {
124: return proxySSL;
125: }
126:
127: /*
128: * Returns SSL proxy port
129: */
130:
131: public int getProxySSLPort() {
132: return proxySSLPort;
133: }
134:
135: /*
136: * Returns false if direct connection to the internet, true otherwise
137: */
138:
139: public boolean getProxyMode() {
140: return proxyMode;
141: }
142:
143: /*
144: * Process the proxy information entered by user.
145: */
146: public void actionPerformed(ActionEvent evt) {
147: Object obj = evt.getSource();
148: if ("OK".equals(evt.getActionCommand())) {
149: if (obj == pw.okButton) {
150: pw.setVisible(false);
151: } else if (obj == ppd.ok) {
152: try {
153: proxySSLPort = Integer.parseInt(ppd.getPortText());
154: } catch (NumberFormatException n) {
155: proxySSLPort = 0;
156: }
157: System.out.println("Netlet resetting Proxy Port to "
158: + proxySSLPort);
159: ppd.notifyAction();
160: ppd.setVisible(false);
161: }
162: }
163: }
164:
165: public ProxyWarning getProxyWarning() {
166: if (pw == null) {
167: pw = new ProxyWarning(new Frame(), this, BrowserType
168: .getInstance().getBrowserName());
169: }
170: return pw;
171: }
172: }
|