001: /*
002: * WebSphinx web-crawling toolkit
003: *
004: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
020: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
022: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
023: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: *
031: */
032:
033: package websphinx.workbench;
034:
035: import websphinx.Access;
036: import java.applet.Applet;
037: import java.applet.AppletContext;
038:
039: public abstract class Context {
040:
041: static Applet applet;
042: static String target;
043: static AppletContext context;
044: static Browser browser;
045: static ScriptInterpreter interpreter;
046:
047: public static boolean isApplet() {
048: return applet != null;
049: }
050:
051: public static boolean isApplication() {
052: return applet == null;
053: }
054:
055: public static void setApplet(Applet _applet) {
056: applet = _applet;
057: internalSetApplet();
058: }
059:
060: public static void setApplet(Applet _applet, String _target) {
061: applet = _applet;
062: target = _target;
063: internalSetApplet();
064: }
065:
066: private static void internalSetApplet() {
067: context = applet.getAppletContext();
068:
069: String browserName;
070: try {
071: browserName = System.getProperty("browser");
072: } catch (Throwable t) {
073: browserName = null;
074: }
075:
076: if (browserName == null) {
077: // appletviewer
078: browser = null;
079: interpreter = null;
080: } else if (browserName.startsWith("Netscape")) {
081: // Netscape
082: Netscape ns = target != null ? new Netscape(context, target)
083: : new Netscape(context, target);
084: browser = ns;
085: interpreter = ns.getScriptInterpreter();
086:
087: String browserVersion;
088: try {
089: browserVersion = System.getProperty("browser.version");
090: } catch (Throwable e) {
091: browserVersion = null;
092: }
093: if (browserVersion == null)
094: browserVersion = "";
095:
096: if (browserVersion.startsWith("4."))
097: try {
098: Access.setAccess(new Netscape4Access());
099: } catch (Throwable t2) {
100: t2.printStackTrace();
101: }
102: }
103: // NIY: Internet Explorer
104: else {
105: // generic browser
106: browser = target != null ? new Browser(context, target)
107: : new Browser(context);
108: interpreter = null;
109: }
110: }
111:
112: public static Applet getApplet() {
113: return applet;
114: }
115:
116: public static AppletContext getAppletContext() {
117: return context;
118: }
119:
120: public static Browser getBrowser() {
121: return browser;
122: }
123:
124: public static ScriptInterpreter getScriptInterpreter() {
125: return interpreter;
126: }
127: }
|