001: package com.sun.portal.proxylet.client.applet;
002:
003: import com.sun.portal.proxylet.client.common.Param;
004: import com.sun.portal.proxylet.client.common.ValidateSession;
005: import com.sun.portal.proxylet.client.common.Log;
006: import com.sun.portal.proxylet.client.common.ui.ProxyletUI;
007: import com.sun.portal.proxylet.client.common.ui.AbstractEventHandler;
008: import com.sun.portal.proxylet.client.common.browser.BrowserType;
009: import com.sun.portal.proxylet.client.common.browser.RegistryEventHandler;
010: import com.sun.portal.proxylet.client.common.browser.MozillaEventHandler;
011:
012: import java.awt.Graphics;
013: import java.lang.reflect.InvocationTargetException;
014:
015: import javax.swing.JApplet;
016:
017: public class ProxyletApplet extends JApplet {
018:
019: AbstractEventHandler ahandler;
020:
021: public void init() {
022:
023: Param.cleanupPreviousSessionsProxyletFiles();
024:
025: // Set the log level first
026: String temp = this .getParameter("DEBUGLEVEL");
027: Log
028: .setloglevel_JavaConsole((temp != null && temp
029: .equals("1")) ? true : false);
030:
031: // Intialize Param from applet parameters
032: Param.readParameters(this );
033:
034: // Check if Proxylet is already running.. if so quit this session
035: if (Param.isProxyletRunning()) {
036: try {
037: Param.sendMsgtoServlet("?command=setAppletLoaded",
038: false, false, null);
039: } catch (Exception e) {
040: Log
041: .debugu("Unable to update session with status of applet"
042: + e.getMessage());
043: }
044: Log
045: .info(Param
046: .getString("pinfo.7",
047: "Detected another instance of proxylet on this machine \\n Quitting"));
048:
049: try {
050: // Wait for few seconds for user to read the message
051: Thread.sleep(5 * 1000);
052: } catch (Exception e) {
053: }
054: System.exit(1);
055: }
056:
057: // if proxylet rules is not defined , load pac content
058: if (Param.getRules() != null
059: && Param.getRules().equals("$RULES")) {
060: Param.loadPacContent();
061: }
062:
063: System.out.println(" b4 setAppletLoaded ");
064: // update the servlet with status of applet
065: try {
066: Param.sendMsgtoServlet("?command=setAppletLoaded", true,
067: false, null);
068: } catch (Exception e) {
069: Log.debugu("Unable to update session with applet status "
070: + e.getMessage());
071: return;
072: }
073:
074: System.out.println(" b4 loadResourcebundle ");
075:
076: // Load resource bundle
077: try {
078: Param.loadResourceBundle(true);
079: } catch (Exception ignore) {
080: Log
081: .info(Param
082: .getString("pexcp.1",
083: "Failed to get resource bundle for locale. Defaulting to en_US"));
084: }
085:
086: // Display UI
087: ahandler = null;
088: if (Param.getBrowserType().equals(BrowserType.IE))
089: ahandler = new RegistryEventHandler();
090: else if (Param.getBrowserType().equals(BrowserType.Netscape)) {
091: System.out.println("MozillaEventHandler invoked");
092: ahandler = new MozillaEventHandler();
093: } else {
094: Log.debugu(Param.getString("pinfo.11",
095: "Unsupported Browser Version"));
096: return;
097: }
098:
099: final AbstractEventHandler mainobj = ahandler;
100: final ProxyletApplet parent = this ;
101: try {
102: javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
103: public void run() {
104: ProxyletUI.createAndShowGUIInJApplet(parent,
105: mainobj);
106: }
107: });
108: } catch (InterruptedException e) {
109: Log.debug(Param.getString("perr.9",
110: "ERR: Problem in displaying UI. Unknown error."));
111: return;
112: } catch (InvocationTargetException e) {
113: Log.debug(Param.getString("perr.9",
114: "ERR: Problem in displaying UI. Unknown error."));
115: return;
116: }
117:
118: mainobj.handleStart(true);
119:
120: //Start timer thread
121: ValidateSession v = new ValidateSession(mainobj);
122:
123: // Added for netlet proxylet seperation
124: System.setProperty("com.sun.portal.proxylet.proxyletMode",
125: "true");
126: if (Param.getClientProxyHost() != null) {
127: System.setProperty("com.sun.portal.proxylet.proxyHost",
128: Param.getClientProxyHost());
129: System.setProperty("com.sun.portal.proxylet.proxyPort",
130: Integer.toString(Param.getClientProxyPort()));
131: }
132:
133: Param.setProxyletFilesForCleanup();
134: }
135:
136: public void start() {
137:
138: }
139:
140: public void stop() {
141: try {
142: super .stop();
143: //
144: // The window handle was getting invalidated by this time.
145: // So, the script onclose function will take care of this
146: //
147: //browser.restoreDefaultPref(this, pref);
148: } catch (Exception e) {
149: e.printStackTrace();
150: }
151: }
152:
153: public void addItem(String newWord) {
154: repaint();
155: }
156:
157: public void paint(Graphics g) {
158: super .paint(g);
159: }
160:
161: public void sweetCleanUp() {
162: System.out.println("In sweetcleanup");
163: ahandler.handleStop();
164: stop();
165: destroy();
166: }
167: }
|