KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > workbench > Context


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx.workbench;
34
35 import websphinx.Access;
36 import java.applet.Applet JavaDoc;
37 import java.applet.AppletContext JavaDoc;
38
39 public abstract class Context {
40
41     static Applet JavaDoc applet;
42     static String JavaDoc target;
43     static AppletContext JavaDoc 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 JavaDoc _applet) {
56         applet = _applet;
57         internalSetApplet ();
58     }
59
60     public static void setApplet (Applet JavaDoc _applet, String JavaDoc _target) {
61         applet = _applet;
62         target = _target;
63         internalSetApplet ();
64     }
65
66     private static void internalSetApplet () {
67         context = applet.getAppletContext ();
68
69         String JavaDoc browserName;
70         try {
71             browserName = System.getProperty ("browser");
72         } catch (Throwable JavaDoc t) {
73             browserName = null;
74         }
75
76         if (browserName == null) {
77             // appletviewer
78
browser = null;
79             interpreter = null;
80         }
81         else if (browserName.startsWith ("Netscape")) {
82             // Netscape
83
Netscape ns = target != null ? new Netscape (context, target) : new Netscape(context, target);
84             browser = ns;
85             interpreter = ns.getScriptInterpreter ();
86
87             String JavaDoc browserVersion;
88             try {
89                 browserVersion = System.getProperty ("browser.version");
90             } catch (Throwable JavaDoc 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 JavaDoc t2) {
100                     t2.printStackTrace ();
101                 }
102         }
103         // NIY: Internet Explorer
104
else {
105             // generic browser
106
browser = target != null ? new Browser (context, target) : new Browser (context);
107             interpreter = null;
108         }
109     }
110
111     public static Applet JavaDoc getApplet () {
112         return applet;
113     }
114
115     public static AppletContext JavaDoc 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