+ });
+
+ put("recursivePrintObject", new JS.Function() { public Object _call(JS.Array args) {
+ if (args.length() != 1) return null;
+ recurse("", "", args.elementAt(0));
+ return null;
+ }});
+
+ put("loadArchive", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
+ if (!ThreadMessage.suspendThread()) return null;
+ try {
+ if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;
+ URL u = new URL(args.elementAt(0).toString());
+
+ JS.Function callback = null;
+ if (args.length() == 2 && args.elementAt(1) != null && args.elementAt(1) instanceof JS.Function)
+ callback = (JS.Function)args.elementAt(1);
+
+ if (!u.getFile().endsWith(".xwar")) {
+ if (Log.on) Log.log(this, "Error: archive names must end with .xwar: " + u.getFile());
+ throw new JS.Exn("Error: archive names must end with .xwar: " + u.getFile());
+ }
+
+ if (u.getProtocol().equals("http")) {
+ HTTP http = new HTTP(u.toString());
+ if (Main.originAddr == null) {
+ try {
+ Main.originAddr = InetAddress.getByName(u.getHost());
+ } catch (UnknownHostException e) {
+ if (Log.on) Log.log(this, "couldn't resolve " + u.getHost() + "; proceeding without permissions");
+ Main.originAddr = InetAddress.getByName("0.0.0.0");
+ }
+ } else {
+ Main.originAddr = InetAddress.getByName("0.0.0.0");
+ }
+ HTTP.HTTPInputStream in = http.GET();
+ Resources.loadArchive(in, in.getContentLength(), callback);
+
+ } else if (u.getProtocol().equals("file")) {
+ if (Main.originAddr != null) {
+ if (Log.on) Log.log(this, "scripts downloaded from the network may not load xwars from the local filesystem");
+ throw new JS.Exn("scripts downloaded from the network may not load xwars from the local filesystem");
+ }
+ Resources.loadArchive(new FileInputStream(u.getFile()), (int)new File(u.getFile()).length(), callback);
+
+ } else {
+ if (Log.on) Log.log(this, "unknown protocol \"" + u.getProtocol() + "\"");
+ throw new JS.Exn("unknown protocol \"" + u.getProtocol() + "\"");
+ }
+
+ } catch (MalformedURLException me) {
+ if (Log.on) Log.log(this, "Malformed URL: " + args.elementAt(0));
+ if (Log.on) Log.log(this, me);
+ throw new JS.Exn(me.toString());
+
+ } catch (IOException ioe) {
+ if (Log.on) Log.log(this, "IOException while loading archive:");
+ if (Log.on) Log.log(this, ioe);
+ throw new JS.Exn(ioe.toString());
+
+ } finally {
+ ThreadMessage.resumeThread();
+
+ }
+ return null;
+ }});
+
+ put("prefetchImage", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
+ if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;
+ Box.getImage(args.elementAt(0).toString(),
+ args.length() > 1 && args.elementAt(1) instanceof JS.Function ? (JS.Function)args.elementAt(1) : null);
+ return null;
+ }});
+ }
+
+ private static void recurse(String indent, String name, Object o) {
+ if (!name.equals("")) name += " : ";
+
+ if (o == null) {
+ Log.log(JS.getCurrentFunction().getSourceName(), indent + name + "<null>");