1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
10 import org.xwt.translators.*;
11 import org.xwt.plat.*;
12 import org.bouncycastle.util.encoders.Base64;
14 /** Entry point for the XWT Engine; handles splash screen, initial xwar loading, and argument processing */
17 // to prevent GCJ from dropping these classes
18 private static final Class[] keep = new Class[] { GCJ.class, Linux.class, Solaris.class, Darwin.class, Win32.class };
21 * FEATURE: this should be implemented using self-emulation
22 * Used for security checks. If this is null, it means that only
23 * scripts originating from the local filesystem are loaded in
24 * the engine (maximum permissions). If scripts have been loaded
25 * from multiple locations, this will be 0.0.0.0 (the invalid
28 public static java.net.InetAddress originAddr = null;
29 public static String originHost = null;
30 public static String origin = null;
31 public static String initialTemplate = null;
33 public static final Stream builtin = new Stream.Zip(new Stream.Builtin());
34 public static Picture scarImage = null;
36 public static void printUsage() {
37 System.err.println("Usage: xwt [-s] [-v] [-l <port>/<url>] source-location [initial-template]");
38 System.err.println("");
39 System.err.println("Options:");
40 System.err.println(" -v verbose logging");
41 System.err.println(" -s [not yet supported]");
42 System.err.println(" -l [not yet supported]");
43 System.err.println("");
44 System.err.println("Source-location is one of the following:");
45 System.err.println(" - the path to an xwar file");
46 System.err.println(" - the path to a directory to be used as an xwar");
47 System.err.println(" - the http url of an xwar");
48 System.err.println("");
49 System.err.println("Initial-template is the path of the template to load; defaults to 'main'");
50 Runtime.getRuntime().exit(-1);
53 public static void main(String[] args) throws Exception {
56 if (startargs > args.length - 1) printUsage();
57 else if (args[startargs].equals("-v")) Log.verbose = true;
63 if (Log.on) for(int i=0; i<args.length; i++) Log.info(Main.class, "argument " + i + ": " + args[i]);
65 initialTemplate = args.length > startargs + 1 ? args[startargs + 1] : "main";
66 origin = args[startargs];
69 final String startupTemplate;
70 if (origin.startsWith("http://") || origin.startsWith("https://")) {
71 originHost = origin.substring(origin.indexOf('/') + 2);
72 originHost = originHost.substring(0, originHost.indexOf('/') == -1 ? originHost.length() : originHost.indexOf('/'));
73 if (originHost.indexOf('@') != -1) originHost = originHost.substring(originHost.indexOf('@') + 1);
74 originAddr = InetAddress.getByName(originHost);
76 startupTemplate = "org.xwt.builtin.splash";
78 rr = new Stream.File(origin);
79 if (!new File(origin).isDirectory()) rr = new Stream.Zip(rr);
80 startupTemplate = initialTemplate;
83 if (Log.on) Log.info(Main.class, "loading xwar");
84 final XWT xwt = new XWT(rr);
85 final JS final_rr = (JS)xwt.get("");
88 Picture.load((Stream)Main.builtin.get("org/xwt/builtin/scar.png"),
89 new Scheduler.Task() { public void perform() throws Exception {
90 xwt.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1);