001: // @(#)BrowserType.java 1.8 "@(#)BrowserType.java 1.8 01/01/30 Sun Microsystems"
002:
003: package com.sun.portal.netlet.client.common;
004:
005: import java.io.FileNotFoundException;
006: import java.lang.reflect.Method;
007:
008: public class BrowserType {
009:
010: private static BrowserType browser = null;
011: private String browserName;
012: private boolean netscapeBrowser = true;
013: private boolean appleBrowser = false;
014: private boolean ieBrowser = false;
015: private boolean privDenied;
016: private int version = 1; // Major Version only
017:
018: private BrowserType() {
019:
020: char VMVersion = System.getProperty("java.version").charAt(0);
021: if (VMVersion > '1')
022: version = 2;
023: VMVersion = System.getProperty("java.version").charAt(2);
024: if (VMVersion > '2')
025: version = 2;
026:
027: String vendor = System.getProperty("java.vendor").toUpperCase();
028:
029: if (vendor.startsWith("APPLE")) {
030: //System.out.println("Netlet found Apple MRJ JVM");
031: browserName = new String("MRJ");
032: appleBrowser = true;
033: netscapeBrowser = false;
034: } else if (vendor.startsWith("NETSCAPE")) {
035: browserName = new String("Netscape");
036: netscapeBrowser = true;
037: } else if (vendor.startsWith("MICROSOFT")) {
038: browserName = new String("IE");
039: ieBrowser = true;
040: netscapeBrowser = false;
041: } else {
042: netscapeBrowser = false;
043: if (version == 2)
044: browserName = "Java 2 Enabled browser";
045:
046: }
047: }
048:
049: public static synchronized BrowserType getInstance() {
050: if (browser == null) {
051: browser = new BrowserType();
052: }
053: return browser;
054: }
055:
056: public String getBrowserName() {
057: return (browserName);
058: }
059:
060: public boolean getNetscapeBrowser() {
061: return (netscapeBrowser);
062: }
063:
064: public boolean getAppleBrowser() {
065: return (appleBrowser);
066: }
067:
068: public boolean getIEBrowser() {
069: return (ieBrowser);
070: }
071:
072: public boolean getPrivEnabled() {
073: return (privDenied);
074: }
075:
076: public int getJavaVMVersion() {
077: return version;
078: }
079:
080: public class SecurityCall {
081: //permission required
082: private int vendor;
083: private Method method;
084: private Object[] args;
085:
086: public SecurityCall() {
087: vendor = BrowserType.OTHER;
088: method = null;
089: args = null;
090: }
091:
092: public SecurityCall(int avendor) {
093: vendor = avendor;
094: method = null;
095: args = null;
096: }
097:
098: public SecurityCall(int avendor, Method amethod, Object[] aargs) {
099: vendor = avendor;
100: method = amethod;
101: args = aargs;
102: }
103:
104: public int getVendor() {
105: return vendor;
106: }
107:
108: public Method getMethod() {
109: return method;
110: }
111:
112: public Object[] getArgs() {
113: return args;
114: }
115: } // End of Security Class
116:
117: public static final int NETSCAPE_UNIVERSAL_CONNECT = 0;
118: public static final int NETSCAPE_UNIVERSAL_LISTEN = 1;
119: public static final int NETSCAPE_UNIVERSAL_ACCEPT = 3;
120: public static final int NETSCAPE_UNIVERSAL_PREFERENCES_READ = 4;
121: public static final int NETSCAPE_UNIVERSAL_PREFERENCES_WRITE = 5;
122: public static final int NETSCAPE_UNIVERSAL_FILE_ACCESS = 6;
123:
124: public static final int NETSCAPE = 50;
125: public static final int MICROSOFT = 51;
126: public static final int OTHER = 52;
127:
128: public SecurityCall enablePermission(int perm) throws Exception {
129:
130: if (System.getProperty("os.name").toUpperCase().startsWith(
131: "MAC"))
132: return new BrowserType.SecurityCall(OTHER);
133:
134: if (version == 2) {
135: return new BrowserType.SecurityCall(OTHER);
136: }
137:
138: try {
139: Method meth = null;
140: if (getNetscapeBrowser()) {
141:
142: Class classPM = Class
143: .forName("netscape.security.PrivilegeManager");
144: meth = classPM.getMethod("enablePrivilege",
145: new Class[] { String.class });
146: String strPerm = null;
147:
148: switch (perm) {
149: case NETSCAPE_UNIVERSAL_CONNECT:
150: strPerm = "UniversalConnect";
151: break;
152: case NETSCAPE_UNIVERSAL_LISTEN:
153: strPerm = "UniversalListen";
154: break;
155: case NETSCAPE_UNIVERSAL_ACCEPT:
156: strPerm = "UniversalAccept";
157: break;
158: case NETSCAPE_UNIVERSAL_PREFERENCES_READ:
159: strPerm = "UniversalPreferencesRead";
160: break;
161: case NETSCAPE_UNIVERSAL_PREFERENCES_WRITE:
162: strPerm = "UniversalPreferencesWrite";
163: break;
164: case NETSCAPE_UNIVERSAL_FILE_ACCESS:
165: strPerm = "UniversalFileAccess";
166: break;
167: default:
168: strPerm = "UniversalConnect";
169: break;
170:
171: }
172: return new BrowserType.SecurityCall(NETSCAPE, meth,
173: new String[] { strPerm });
174: } else {
175: return new BrowserType.SecurityCall();
176: }
177: } catch (Exception e) {
178: if (!(e instanceof ClassNotFoundException)
179: && !(e instanceof FileNotFoundException))
180: throw e;
181: else
182: return new BrowserType.SecurityCall();
183: } catch (NoClassDefFoundError n) {
184: return new BrowserType.SecurityCall();
185: }
186: }
187: /////
188: }
|