- } 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("newBox")) {
- if (checkOnly) return Boolean.TRUE;
- return new Box();
-
- } 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 : new Res.stringToResource("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");
- }
- */
-
- } else if (method.equals("parseHTML")) {
- if (checkOnly) return Boolean.TRUE;
- if (args == null || args.length() != 1 || args.elementAt(0) == null) return null;
- try {
- if (args.elementAt(0) instanceof Res) {
- return HTML.parseReader(new InputStreamReader(((Res)args.elementAt(0)).getInputStream()));
- } else {
- return HTML.parseReader(new StringReader(args.elementAt(0).toString()));
- }
- } catch (IOException e) {
- if (Log.on) Log.log(HTML.class, "IO Exception while parsing HTML");
- if (Log.on) Log.log(HTML.class, e);
- throw new JS.Exn("error while parsing HTML");
- }
-
- } else if (method.equals("recursivePrintObject")) {
- if (checkOnly) return Boolean.TRUE;
- if (args.length() != 1) return null;
- recurse("", "", args.elementAt(0));
- return null;
+ } else if (nargs == 1) {
+ //#switch(name)
+ case "ui.browser": Platform.newBrowserWindow((String)a); return null;
+ case "clone": return new XWT((Res)a);
+ case "res.unzip": return new Res.Zip((Res)a);
+ case "res.uncab": return new Res.Cab((Res)a);
+ case "res.cache": try { return new Res.CachedRes((Res)a, "resources", true); }
+ catch (Res.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); }
+ case "res.url":
+ String url = (String)a;
+ if (url.startsWith("http://")) return new Res.HTTP(url);
+ else if (url.startsWith("https://")) return new Res.HTTP(url);
+ else if (url.startsWith("data:")) return new Res.ByteArray(Base64.decode(url.substring(5)), null);
+ else if (url.startsWith("utf8:")) return new Res.ByteArray(url.substring(5).getBytes(), null);
+ throw new JSExn("invalid resource specifier " + url);
+ case "thread.sleep": sleep(JS.toInt(a)); return null;
+ case "log.println": Log.logJS(this, a== null ? "**null**" : a.toString()); return null;
+ case "log.dump": Log.recursiveLog("","",a); return null;
+ case "regexp": return new JSRegexp(a, null);
+ case "rpc.xml": return new XMLRPC((String)a, "");
+ case "rpc.soap": return new SOAP((String)a, "", null, null);
+ case "crypto.rsa": /* FEATURE */ break;
+ case "crypto.md5": /* FEATURE */ break;
+ case "crypto.sha1": /* FEATURE */ break;
+ case "crypto.rc4": /* FEATURE */ break;
+ case "stream.parse.html": /* FEATURE */ break;
+ case "stream.parse.xml": /* FEATURE */ break;
+ case "stream.parse.utf8": /* FEATURE */ break;
+ //#end