2003/05/12 05:31:50
[org.ibex.core.git] / src / org / xwt / Proxy.java
index 632034e..81318a0 100644 (file)
@@ -4,8 +4,8 @@ package org.xwt;
 import java.net.*;
 import java.io.*;
 import java.util.*;
+import org.xwt.js.*;
 import org.xwt.util.*;
-import org.mozilla.javascript.*;
 import org.bouncycastle.util.encoders.Base64;
 
 /** encapsulates most of the proxy logic; some is shared in HTTP.java */
@@ -35,7 +35,7 @@ public class Proxy {
     public String[] excluded = null;
     
     /** the PAC script */
-    public Function proxyAutoConfigFunction = null;
+    public JS.Function proxyAutoConfigFunction = null;
     
     public static Proxy detectProxyViaManual() {
         Proxy ret = new Proxy();
@@ -87,9 +87,11 @@ public class Proxy {
         return ret;
     }
     
-    public static Scriptable proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
-    
-    public static Function getProxyAutoConfigFunction(String url) {
+    //public static JS proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+    public static JS.Function getProxyAutoConfigFunction(String url) {
+       throw new Error("not implemented");
+       // FIXME
+       /*
         try { 
             Context cx = Context.enter();
             cx.setOptimizationLevel(-1);
@@ -119,16 +121,16 @@ public class Proxy {
             
             Script scr = cx.compileReader(proxyAutoConfigRootScope, new StringReader(script), "PAC script at " + url, 0, null);
             scr.exec(cx, proxyAutoConfigRootScope);
-            return (Function)proxyAutoConfigRootScope.get("FindProxyForURL", null);
+            return (JS.Function)proxyAutoConfigRootScope.get("FindProxyForURL", null);
         } 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 JavaScriptException) {
+                else if (e instanceof JS.Exn) {
             try {
             XWT.recursivePrintObject.call(Context.enter(), null, null, new Object[] {
-                ((JavaScriptException)e).getValue() });
+                ((JS.Exn)e).getValue() });
             } catch (Exception e2) {
             Log.log(Platform.class, e);
             }
@@ -137,6 +139,7 @@ public class Proxy {
             }
             return null;
         }
+       */
     }
 
 
@@ -172,13 +175,13 @@ public class Proxy {
 
 
     // ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
-    
-    public static class ProxyAutoConfigRootScope extends ScriptableObject {
+    /*    
+    public static class ProxyAutoConfigRootScope extends JSObject {
         
         public String getClassName() { return "ProxyAutoConfigRootScope"; }
         ProxyAutoConfigRootScope() { Context.enter().initStandardObjects(this); }
         
-        public Object get(String name, Scriptable start) {
+        public Object get(String name, JS start) {
             if (name.equals("isPlainHostName")) return isPlainHostName;
             else if (name.equals("dnsDomainIs")) return dnsDomainIs;
             else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs;
@@ -195,41 +198,36 @@ public class Proxy {
             else return super.get(name, start);
         }
         
-        private static final JSObject proxyConfigBindings = new JSObject();
-        private static final JSObject ProxyConfig = new JSObject() {
-                public Object get(String name, Scriptable start) {
+        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) {
                     if (name.equals("bindings")) return proxyConfigBindings;
                     return null;
                 }
             };
         
-        private static abstract class JSFunction extends JSObject implements Function {
-            JSFunction() { setSeal(true); }
-            public Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args) { return null; }
-        }
-        
-        private static final JSFunction isPlainHostName = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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 JSFunction dnsDomainIs = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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 JSFunction localHostOrDomainIs = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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()))) ?
                         Boolean.TRUE : Boolean.FALSE;
                 }
             };
         
-        private static final JSFunction isResolvable = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        private static final JS.Function isResolvable = new JS.Function() {
+                public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
                     try {
                         return (InetAddress.getByName(args[0].toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
                     } catch (UnknownHostException e) {
@@ -238,8 +236,8 @@ public class Proxy {
                 }
             };
         
-        private static final JSFunction isInNet = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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;
                     try {
                         byte[] host = InetAddress.getByName(args[0].toString()).getAddress();
@@ -251,13 +249,13 @@ public class Proxy {
                                 (host[3] & mask[3]) == net[3]) ?
                             Boolean.TRUE : Boolean.FALSE;
                     } catch (Exception e) {
-                        throw new JavaScriptException("exception in isInNet(): " + e);
+                        throw new JS.Exn("exception in isInNet(): " + e);
                     }
                 }
             };
         
-        private static final JSFunction dnsResolve = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        private static final JS.Function dnsResolve = new JS.Function() {
+                public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
                     try {
                         return InetAddress.getByName(args[0].toString()).getHostAddress();
                     } catch (UnknownHostException e) {
@@ -266,8 +264,8 @@ public class Proxy {
                 }
             };
         
-        private static final JSFunction myIpAddress = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        private static final JS.Function myIpAddress = new JS.Function() {
+                public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
                     try {
                         return InetAddress.getLocalHost().getHostAddress();
                     } catch (UnknownHostException e) {
@@ -277,8 +275,8 @@ public class Proxy {
                 }
             };
         
-        private static final JSFunction dnsDomainLevels = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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();
                     int i = 0;
                     while((i = s.indexOf('.', i)) != -1) i++;
@@ -295,8 +293,8 @@ public class Proxy {
             return false;
         }
         
-        private static final JSFunction shExpMatch = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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);
                     String[] arr = new String[st.countTokens()];
                     String s = args[0].toString();
@@ -307,8 +305,8 @@ public class Proxy {
         
         public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
         
-        private static final JSFunction weekdayRange = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+        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();
                     Calendar c = new GregorianCalendar();
                     c.setTimeZone(tz);
@@ -333,18 +331,18 @@ public class Proxy {
                 }
             };
         
-        private static final JSFunction dateRange = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
-                    throw new JavaScriptException("XWT does not support dateRange() in PAC scripts");
+        private static final JS.Function dateRange = new JS.Function() {
+                public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn {
+                    throw new JS.Exn("XWT does not support dateRange() in PAC scripts");
                 }
             };
         
-        private static final JSFunction timeRange = new JSFunction() {
-                public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
-                    throw new JavaScriptException("XWT does not support timeRange() 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 {
+                    throw new JS.Exn("XWT does not support timeRange() in PAC scripts");
                 }
             };
         
     }
-    
+    */    
 }