1 32 33 package websphinx.workbench; 34 35 import websphinx.Access; 36 import java.applet.Applet ; 37 import java.applet.AppletContext ; 38 39 public abstract class Context { 40 41 static Applet applet; 42 static String target; 43 static AppletContext context; 44 static Browser browser; 45 static ScriptInterpreter interpreter; 46 47 public static boolean isApplet () { 48 return applet != null; 49 } 50 51 public static boolean isApplication () { 52 return applet == null; 53 } 54 55 public static void setApplet (Applet _applet) { 56 applet = _applet; 57 internalSetApplet (); 58 } 59 60 public static void setApplet (Applet _applet, String _target) { 61 applet = _applet; 62 target = _target; 63 internalSetApplet (); 64 } 65 66 private static void internalSetApplet () { 67 context = applet.getAppletContext (); 68 69 String browserName; 70 try { 71 browserName = System.getProperty ("browser"); 72 } catch (Throwable t) { 73 browserName = null; 74 } 75 76 if (browserName == null) { 77 browser = null; 79 interpreter = null; 80 } 81 else if (browserName.startsWith ("Netscape")) { 82 Netscape ns = target != null ? new Netscape (context, target) : new Netscape(context, target); 84 browser = ns; 85 interpreter = ns.getScriptInterpreter (); 86 87 String browserVersion; 88 try { 89 browserVersion = System.getProperty ("browser.version"); 90 } catch (Throwable e) { 91 browserVersion = null; 92 } 93 if (browserVersion == null) 94 browserVersion = ""; 95 96 if (browserVersion.startsWith ("4.")) 97 try { 98 Access.setAccess (new Netscape4Access ()); 99 } catch (Throwable t2) { 100 t2.printStackTrace (); 101 } 102 } 103 else { 105 browser = target != null ? new Browser (context, target) : new Browser (context); 107 interpreter = null; 108 } 109 } 110 111 public static Applet getApplet () { 112 return applet; 113 } 114 115 public static AppletContext getAppletContext () { 116 return context; 117 } 118 119 public static Browser getBrowser () { 120 return browser; 121 } 122 123 public static ScriptInterpreter getScriptInterpreter () { 124 return interpreter; 125 } 126 } 127 | Popular Tags |