public String[] excluded = null;
/** the PAC script */
- public JS.Function proxyAutoConfigFunction = null;
+ public JS.Callable proxyAutoConfigFunction = null;
public static Proxy detectProxyViaManual() {
Proxy ret = new Proxy();
return ret;
}
- //public static JS proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
- public static JS.Function getProxyAutoConfigFunction(String url) {
- throw new Error("not implemented");
- // FIXME
- /*
+ public static JS.Scope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+ public static JS.Callable getProxyAutoConfigFunction(String url) {
try {
- Context cx = Context.enter();
- cx.setOptimizationLevel(-1);
BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
String s = null;
String script = "";
if (Log.on) Log.log(Proxy.class, "DeCARPed PAC script:");
if (Log.on) Log.log(Proxy.class, script);
}
-
- Script scr = cx.compileReader(proxyAutoConfigRootScope, new StringReader(script), "PAC script at " + url, 0, null);
- scr.exec(cx, proxyAutoConfigRootScope);
- return (JS.Function)proxyAutoConfigRootScope.get("FindProxyForURL", null);
+
+ JS.Callable scr = JS.parse("PAC script at " + url, 0, new StringReader(script), proxyAutoConfigRootScope);
+ scr.call(new org.xwt.js.Array());
+ return (JS.Callable)proxyAutoConfigRootScope.get("FindProxyForURL");
} catch (Exception e) {
if (Log.on) {
Log.log(Platform.class, "WPAD detection failed due to:");
- if (e instanceof EcmaError) Log.log(HTTP.class, ((EcmaError)e).getMessage() + " at " +
- ((EcmaError)e).getSourceName() + ":" + ((EcmaError)e).getLineNumber());
- else if (e instanceof JS.Exn) {
- try {
- XWT.recursivePrintObject.call(Context.enter(), null, null, new Object[] {
- ((JS.Exn)e).getValue() });
- } catch (Exception e2) {
- Log.log(Platform.class, e);
- }
- }
+ if (e instanceof JS.Exn) {
+ try {
+ org.xwt.js.Array arr = new org.xwt.js.Array();
+ arr.addElement(((JS.Exn)e).getObject());
+ // FIXME
+ //XWT.recursivePrintObject.call();
+ } catch (Exception e2) {
+ Log.log(Platform.class, e);
+ }
+ }
else Log.log(Platform.class, e);
}
return null;
}
- */
}
// ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
- /*
- public static class ProxyAutoConfigRootScope extends JSObject {
-
- public String getClassName() { return "ProxyAutoConfigRootScope"; }
- ProxyAutoConfigRootScope() { Context.enter().initStandardObjects(this); }
+
+ public static class ProxyAutoConfigRootScope extends JS.Scope {
+
+ public ProxyAutoConfigRootScope() { super(null); }
- public Object get(String name, JS start) {
+ // FIXME: needs "standard objects"
+
+ public Object get(Object name) {
if (name.equals("isPlainHostName")) return isPlainHostName;
else if (name.equals("dnsDomainIs")) return dnsDomainIs;
else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs;
else if (name.equals("dateRange")) return dateRange;
else if (name.equals("timeRange")) return timeRange;
else if (name.equals("ProxyConfig")) return ProxyConfig;
- else return super.get(name, start);
+ else return super.get(name);
}
- private static final JS.Object proxyConfigBindings = new JS.Object();
- private static final JS.Object ProxyConfig = new JS.Object() {
- public Object get(String name, JS start) {
+ private static final JS.Obj proxyConfigBindings = new JS.Obj();
+ private static final JS.Obj ProxyConfig = new JS.Obj() {
+ public Object get(Object name) {
if (name.equals("bindings")) return proxyConfigBindings;
return null;
}
};
- private static final JS.Function isPlainHostName = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- return (args[0].toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
+ private static final JS.Callable isPlainHostName = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
}
};
- private static final JS.Function dnsDomainIs = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- return (args[0].toString().endsWith(args[1].toString())) ? Boolean.TRUE : Boolean.FALSE;
+ private static final JS.Callable dnsDomainIs = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE;
}
};
- private static final JS.Function localHostOrDomainIs = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- return (args[0].toString().equals(args[1].toString()) ||
- (args[0].toString().indexOf('.') == -1 && args[1].toString().startsWith(args[0].toString()))) ?
+ private static final JS.Callable localHostOrDomainIs = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().equals(args.elementAt(1).toString()) ||
+ (args.elementAt(0).toString().indexOf('.') == -1 && args.elementAt(1).toString().startsWith(args.elementAt(0).toString()))) ?
Boolean.TRUE : Boolean.FALSE;
}
};
- private static final JS.Function isResolvable = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+ private static final JS.Callable isResolvable = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
try {
- return (InetAddress.getByName(args[0].toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
+ return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
} catch (UnknownHostException e) {
return Boolean.FALSE;
}
}
};
- private static final JS.Function isInNet = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- if (args.length != 3) return Boolean.FALSE;
+ private static final JS.Callable isInNet = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ if (args.length() != 3) return Boolean.FALSE;
try {
- byte[] host = InetAddress.getByName(args[0].toString()).getAddress();
- byte[] net = InetAddress.getByName(args[1].toString()).getAddress();
- byte[] mask = InetAddress.getByName(args[2].toString()).getAddress();
+ byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress();
+ byte[] net = InetAddress.getByName(args.elementAt(1).toString()).getAddress();
+ byte[] mask = InetAddress.getByName(args.elementAt(2).toString()).getAddress();
return ((host[0] & mask[0]) == net[0] &&
(host[1] & mask[1]) == net[1] &&
(host[2] & mask[2]) == net[2] &&
}
};
- private static final JS.Function dnsResolve = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+ private static final JS.Callable dnsResolve = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
try {
- return InetAddress.getByName(args[0].toString()).getHostAddress();
+ return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress();
} catch (UnknownHostException e) {
return null;
}
}
};
- private static final JS.Function myIpAddress = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+ private static final JS.Callable myIpAddress = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
}
};
- private static final JS.Function dnsDomainLevels = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- String s = args[0].toString();
+ private static final JS.Callable dnsDomainLevels = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ String s = args.elementAt(0).toString();
int i = 0;
while((i = s.indexOf('.', i)) != -1) i++;
return new Integer(i);
return false;
}
- private static final JS.Function shExpMatch = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- StringTokenizer st = new StringTokenizer(args[1].toString(), "*", false);
+ private static final JS.Callable shExpMatch = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false);
String[] arr = new String[st.countTokens()];
- String s = args[0].toString();
+ String s = args.elementAt(0).toString();
for (int i=0; st.hasMoreTokens(); i++) arr[i] = st.nextToken();
return match(arr, s, 0) ? Boolean.TRUE : Boolean.FALSE;
}
public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
- private static final JS.Function weekdayRange = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
- TimeZone tz = (args.length < 3 || args[2] == null || !args[2].equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ private static final JS.Callable weekdayRange = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
+ TimeZone tz = (args.length() < 3 || args.elementAt(2) == null || !args.elementAt(2).equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
Calendar c = new GregorianCalendar();
c.setTimeZone(tz);
- c.setTime(new Date());
- Date d = c.getTime();
+ c.setTime(new java.util.Date());
+ java.util.Date d = c.getTime();
int day = d.getDay();
- String d1s = args[0].toString().toUpperCase();
+ String d1s = args.elementAt(0).toString().toUpperCase();
int d1 = 0, d2 = 0;
for(int i=0; i<days.length; i++) if (days[i].equals(d1s)) d1 = i;
- if (args.length == 1)
+ if (args.length() == 1)
return d1 == day ? Boolean.TRUE : Boolean.FALSE;
- String d2s = args[1].toString().toUpperCase();
+ String d2s = args.elementAt(1).toString().toUpperCase();
for(int i=0; i<days.length; i++) if (days[i].equals(d2s)) d2 = i;
return
}
};
- private static final JS.Function dateRange = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+ private static final JS.Callable dateRange = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
throw new JS.Exn("XWT does not support dateRange() in PAC scripts");
}
};
- private static final JS.Function timeRange = new JS.Function() {
- public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+ private static final JS.Callable timeRange = new JS.Callable() {
+ public Object call(org.xwt.js.Array args) throws JS.Exn {
throw new JS.Exn("XWT does not support timeRange() in PAC scripts");
}
};
}
- */
+
}