X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=45144cd974fff054edcc26876a2ac19668dfb2de;hb=929a33405c0de48f920e956ab83c1962a8e1baa0;hp=ce2bfba5dd05a403aacf52a6e2fc9bf7a7e234b2;hpb=0373b49c4640afde70d852f2531e46b19260554f;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index ce2bfba..45144cd 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -11,253 +11,249 @@ import org.xwt.translators.*; import org.bouncycastle.util.encoders.Base64; /** Singleton class that provides all functionality in the xwt.* namespace */ -public final class XWT extends JS.Obj { +public final class XWT extends JSCallable { public final Res rr; public XWT(Res rr) { this.rr = rr; } - private final JS xwtMath = new XWTMath(); - private final JS xwtString = new XWTString(); - - /** each key is a string representing a filename which the user has already given XWT permission to write to */ - private static Hashtable safeFiles = new Hashtable(); + /** lets us put multi-level get/put/call keys all in the same method */ + private class Sub extends JSCallable { + String key; + Sub(String key) { this.key = key; } + public String toString() { return "XWTSUB " + key; } + public void put(Object key, Object val) { XWT.this.put(this.key + "." + key, val); } + public Object get(Object key) { return XWT.this.get(this.key + "." + key); } + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + return XWT.this.callMethod(this.key, a0, a1, a2, rest, nargs); + } + public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) { + return XWT.this.callMethod(this.key + "." + method, a0, a1, a2, rest, nargs); + } + } public Object get(Object name) { - if (name.equals("alt")) return Surface.alt ? Boolean.TRUE : Boolean.FALSE; - else if (name.equals("rr")) return rr; - else if (name.equals("box")) return new Box(); - else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE; - else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE; - else if (name.equals("clipboard")) return Platform.getClipBoard(); - else if (name.equals("origin")) return Main.origin; - else if (name.equals("maxdim")) return new Integer(Short.MAX_VALUE); - else if (name.equals("altKeyName")) return Platform.altKeyName(); - else if (name.equals("screenWidth")) return new Integer(Platform.getScreenWidth()); - else if (name.equals("screenHeight")) return new Integer(Platform.getScreenHeight()); - else if (name.equals("fileSeparator")) return File.separator; - else if (name.equals("homeDir")) return System.getProperty("user.home"); - else if (name.equals("tempDir")) return System.getProperty("java.io.tempdir"); - else if (name.equals("math")) return xwtMath; - else if (name.equals("string")) return xwtString; - else if (name.equals("parseInt")) return xwtString.get("parseInt"); - else if (name.equals("parseFloat")) return xwtString.get("parseFloat"); - else if (name.equals("button")) { + //#switch(name) + case "math": return xwtMath; + case "string": return xwtString; + case "date": return METHOD; + case "origin": return Main.origin; + case "box": return new BoxTree(); + case "log": return new Sub("log"); + case "ui": return new Sub("ui"); + case "thread": return new Sub("thread"); + case "font": return new Sub("font"); + case "font.sansserif": return Main.builtin.get("fonts/vera/Vera.ttf"); + case "font.monospace": return Main.builtin.get("fonts/vera/VeraMono.ttf"); + case "font.serif": return Main.builtin.get("fonts/vera/VeraSe.ttf"); + case "ui.key": return new Sub("ui.key"); + case "ui.key.alt": return Surface.alt ? Boolean.TRUE : Boolean.FALSE; + case "ui.key.control": return Surface.control ? Boolean.TRUE : Boolean.FALSE; + case "ui.key.shift": return Surface.shift ? Boolean.TRUE : Boolean.FALSE; + case "ui.clipboard": return Platform.getClipBoard(); + case "ui.maxdim": return new Integer(Short.MAX_VALUE); + case "ui.key.name": return new Sub("ui.key.name"); + case "ui.key.name.alt": return Platform.altKeyName(); + case "ui.screen": return new Sub("ui.screen"); + case "ui.screen.width": return new Integer(Platform.getScreenWidth()); + case "ui.screen.height": return new Integer(Platform.getScreenHeight()); + case "fs.home": return System.getProperty("user.home"); + case "fs.temp": return System.getProperty("java.io.tempdir"); + case "ui.mouse": return new Sub("ui.mouse"); + case "res": return new Sub("res"); + case "ui.mouse.button": if (Surface.button1 && !Surface.button2 && !Surface.button3) return new Integer(1); - else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(1); - else if (!Surface.button1 && !Surface.button2 && Surface.button3) return new Integer(1); + else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(2); + else if (!Surface.button1 && !Surface.button2 && Surface.button3) return new Integer(3); else return new Integer(0); - } - else return super.get(name); + case "undocumented": return new Sub("undocumented"); + case "undocumented.internal": return new Sub("undocumented.internal"); + case "thread.yield": return METHOD; + case "thread.sleep": return METHOD; + case "res.watch": return METHOD; + case "soap": return METHOD; + case "apply": return METHOD; + case "graft": return METHOD; + case "ui.browser": return METHOD; + case "clone": return METHOD; + case "res.unzip": return METHOD; + case "res.uncab": return METHOD; + case "res.cache": return METHOD; + case "res.url": return METHOD; + case "log.println": return METHOD; + case "log.dump": return METHOD; + case "regexp": return METHOD; + case "rpc.xml": return METHOD; + case "rpc.soap": return METHOD; + case "crypto.rsa": return METHOD; + case "crypto.md5": return METHOD; + case "crypto.sha1": return METHOD; + case "crypto.rc4": return METHOD; + case "stream.parse.html": return METHOD; + case "stream.parse.xml": return METHOD; + case "stream.parse.utf8": return METHOD; + //#end + return rr.get(name); } - public void put(Object name, Object value) { - if (name.equals("thread") && value != null && value instanceof JS.Callable) ThreadMessage.newthread((JS.Callable)value); - else if (name.equals("clipboard")) Platform.setClipBoard(value.toString()); - else if (name.equals("proxyAuthorization")) { + public void put(Object name, final Object value) { + //#switch(name) + case "thread": + Scheduler.add(new Scheduler.Task() { public void perform() { JSContext.invokePauseable((JSFunction)value); } }); + case "ui.clipboard": Platform.setClipBoard((String)value); + case "ui.frame": Platform.createSurface((Box)value, true, true); + case "ui.window": Platform.createSurface((Box)value, false, true); + case "undocumented.internal.proxyAuthorization": HTTP.Proxy.Authorization.authorization = value.toString(); HTTP.Proxy.Authorization.waitingForUser.release(); - } else super.put(name, value); + //#end } - public Object callMethod(Object method, JS.Array args, boolean checkOnly) { - - if (method.equals("newBrowserWindow")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 1 || args.elementAt(0) == null) return null; - Platform.newBrowserWindow(args.elementAt(0).toString()); - return null; - - } else if (method.equals("clone")) { - return new XWT((Res)args.elementAt(0)); - - } else if (method.equals("yield")) { - if (checkOnly) return Boolean.TRUE; - sleep(0); - return null; - - } else if (method.equals("load")) { - if (checkOnly) return Boolean.TRUE; - return Res.stringToRes(args.elementAt(0).toString()); - - } else if (method.equals("println")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 1) return null; - if (Log.on) Log.logJS(this, (args.elementAt(0) == null ? "**null**" : args.elementAt(0).toString())); - return null; - - } else if (method.equals("date")) { - if (checkOnly) return Boolean.TRUE; - Log.log(XWT.class, "date not implemented"); - return null; - - } else if (method.equals("regexp")) { - if (checkOnly) return Boolean.TRUE; - return new Regexp(args); - - } else if (method.equals("xmlrpc")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 1 || args.elementAt(0) == null) return null; - return new XMLRPC(args.elementAt(0).toString(), ""); - - } else if (method.equals("soap")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() == 1 && args.elementAt(0) != null) return new SOAP(args.elementAt(0).toString(), "", null, null); - else if (args.length() == 2 && args.elementAt(0) != null && args.elementAt(1) != null) - return new SOAP(args.elementAt(0).toString(), "", args.elementAt(1).toString(), null); - else if (args.length() == 3 && args.elementAt(0) != null && args.elementAt(1) != null && args.elementAt(2) != null) - return new SOAP(args.elementAt(0).toString(), "", args.elementAt(1).toString(), args.elementAt(2).toString()); - else return null; - - } else if (method.equals("sleep")) { - if (checkOnly) return Boolean.TRUE; - if (args != null && (args.length() != 1 || args.elementAt(0) == null)) return null; - int i = args == null ? 0 : Box.stoi(args.elementAt(0).toString()); - sleep(i); - return null; - - } else if (method.equals("openFile")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 1) return null; - String file = Platform.fileDialog(args.elementAt(0).toString(), false); - return file == null ? null : Res.stringToRes("file:" + file); - - } else if (method.equals("saveFile")) { - if (checkOnly) return Boolean.TRUE; - // FIXME - /* - if (args.length() != 2) return null; - if (!(args.elementAt(1) instanceof ByteStream)) return null; - String file = args.elementAt(0).toString(); - if (safeFiles.get(Platform.isCaseSensitive() ? file : file.toLowerCase()) == null) { - file = Platform.fileDialog(file, true); - if (file == null) return null; - safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object()); - } - try { - ((ByteStream)args.elementAt(1)).writeTo(new FileOutputStream(file)); - return null; - } catch (IOException e) { - if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file"); - if (Log.on) Log.log(ByteStream.class, e); - throw new JS.Exn("error while writing a ByteStream to a file"); - } - */ - - } else if (method.equals("saveFileAs")) { - // FIXME - /* - if (checkOnly) return Boolean.TRUE; - if (args.length() != 2) return null; - if (!(args.elementAt(1) instanceof ByteStream)) return null; - String file = args.elementAt(0).toString(); - file = Platform.fileDialog(file, true); - if (file == null) return null; - safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object()); - try { - ((ByteStream)args.elementAt(1)).writeTo(new FileOutputStream(file)); - return null; - } catch (IOException e) { - if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file"); - if (Log.on) Log.log(ByteStream.class, e); - throw new JS.Exn("error while writing a ByteStream to a file"); + public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JS.Exn { + if (name.equals("date")) { + JSArray args = new JSArray(); + for(int i=0; i"); - - } else if (o instanceof JS.Array) { - Log.logJS(indent + name + ""); - JS.Array na = (JS.Array)o; - for(int i=0; i"); - JS s = (JS)o; - Object[] keys = s.keys(); - for(int i=0; i 0) try { java.lang.Thread.sleep(i); } catch (Exception e) { } - Message.Q.add(mythread); - mythread.go.block(); + private class XMLHelper extends XML { + Vector obStack = new Vector(); + public XMLHelper() { super(BUFFER_SIZE); } + public void startElement(XML.Element c) throws XML.SchemaException { + JS o = new JS(); + o.put("$name", c.localName); + for(int i=0; i= 1 ? (JS)obStack.elementAt(0) : null; } } }