1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 import org.bouncycastle.util.encoders.Base64;
10 import org.xwt.util.*;
11 import org.xwt.translators.*;
13 /** Entry point for the XWT Engine; handles splash screen, initial xwar loading, and argument processing */
17 * FEATURE: this should be implemented using self-emulation
18 * Used for security checks. If this is null, it means that only
19 * scripts originating from the local filesystem are loaded in
20 * the engine (maximum permissions). If scripts have been loaded
21 * from multiple locations, this will be 0.0.0.0 (the invalid
24 public static java.net.InetAddress originAddr = null;
25 public static String originHost = null;
26 public static String origin = null;
28 public static final Res builtin = new Res.Zip(new Res.Builtin());
29 public static Picture scarImage = null;
31 public static void printUsage() {
32 System.err.println("Usage: xwt [-s] [-v] [-l <port>/<url>] source-location [initial-template]");
33 System.err.println("");
34 System.err.println("Options:");
35 // FEATURE: reintroduce
36 //System.err.println(" -s show rendering activity with red rectangles");
37 System.err.println(" -v verbose logging");
38 // FEATURE: reintroduce
39 //System.err.println(" -l serve logs via HTTP on 127.0.0.1:<port>/<url>");
40 System.err.println("");
41 System.err.println("Source-location is one of the following:");
42 System.err.println(" - the path to an xwar file");
43 System.err.println(" - the path to a directory to be used as an xwar");
44 System.err.println(" - the http url of an xwar");
45 System.err.println("");
46 System.err.println("Initial-template is the resource name of the template to load; defaults to 'main'");
47 Runtime.getRuntime().exit(-1);
50 /** common entry point */
51 public static void main(String[] args) throws Exception {
54 if (startargs > args.length - 1) printUsage();
55 else if (args[startargs].equals("-v")) Log.verbose = true;
56 else if (args[startargs].equals("-l")) startargs++;
62 if (Log.on) for(int i=0; i<args.length; i++) Log.log(Main.class, "argument " + i + ": " + args[i]);
64 String initialTemplateName = args.length > startargs + 1 ? args[startargs + 1] : "main";
65 initialTemplateName = initialTemplateName.replace('/', '.');
66 origin = args[startargs];
69 final String initialTemplate;
71 if (origin.startsWith("http://") || origin.startsWith("https://")) {
72 originHost = origin.substring(origin.indexOf('/') + 2);
73 originHost = originHost.substring(0, originHost.indexOf('/') == -1 ? originHost.length() : originHost.indexOf('/'));
74 if (originHost.indexOf('@') != -1) originHost = originHost.substring(originHost.indexOf('@') + 1);
75 originAddr = InetAddress.getByName(originHost);
77 initialTemplate = "org/xwt/builtin/splash.xwt";
79 // HACK because MSIE turns \'s into /'s in file URLs... argh!!
80 if (Platform.platform.getClass().getName().endsWith("Win32")) origin = origin.replace('/', '\\');
81 final String final_origin = origin;
82 rr = new Res.File(origin);
83 if (!new File(origin).isDirectory()) rr = new Res.Zip(rr);
84 initialTemplate = initialTemplateName;
87 if (Log.on) Log.log(Main.class, "loading xwar");
88 final XWT xwt = new XWT(rr);
89 final Res final_rr = rr;
91 Picture.fromRes((Res)Main.builtin.get("org/xwt/builtin/scar.png"), new Callback() {
92 public Object call(Object arg) {
93 scarImage = (Picture)arg;
94 Scheduler.add(new Scheduler.Task() { public void perform() {
95 Template.getTemplate(((Res)final_rr.get(initialTemplate))).apply(new BoxTree(), xwt);
100 new Thread() { public void run() { Scheduler.init(); } }.start();