- void apply(Box b, Vec pboxes, Vec ptemplates, JS.Callable callback, int numerator, int denominator) {
-
- int original_numerator = numerator;
-
- if (pboxes == null) {
- pboxes = new Vec();
- ptemplates = new Vec();
- }
-
- if (id != null && !id.equals(""))
- for(int i=0; i<pboxes.size(); i++) {
- Box parent = (Box)pboxes.elementAt(i);
- String parentNodeName = (String)ptemplates.elementAt(i);
- parent.put("$" + id, b);
- }
-
- if (script != null || (redirect != null && !"self".equals(redirect))) {
- pboxes.addElement(b);
- ptemplates.addElement(nodeName);
- }
-
- int numids = pboxes.size();
-
- link();
-
- for(int i=0; _preapply != null && i<_preapply.length; i++)
- if (_preapply[i] != null) {
- _preapply[i].apply(b, null, null, callback, numerator, denominator);
- numerator += _preapply[i].numUnits();
- }
-
- for (int i=0; children != null && i<children.length; i++) {
- b.put(Integer.MAX_VALUE, new Box(children[i], pboxes, ptemplates, callback, numerator, denominator));
- numerator += children[i].numUnits();
- }
-
- // whom to redirect to; doesn't take effect until after script runs
- Box redir = null;
- if (redirect != null && !"self".equals(redirect)) redir = (Box)b.get("$" + redirect);
-
- if (script != null) try {
- script.call(new JS.Array(), b);
- } catch (JS.Exn e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- }
-
- for(int i=0; keys != null && i<keys.length; i++) {
- // FIXME: make sure that if exceptions are thrown in here, the line number of the offending XML is logged
- if (keys[i] == null) { }
- else if (keys[i].equals("border") || keys[i].equals("image") &&
- !vals[i].toString().startsWith("http://") && !vals[i].toString().startsWith("https://")) {
- String s = Resources.resolve(vals[i].toString() + ".png", importlist);
- if (s != null) b.put(keys[i], s.substring(0, s.length() - 4));
- else if (Log.on) Log.log(this, "unable to resolve image " + vals[i].toString() + " referenced in attributes of " + nodeName);
- }
- else b.put(keys[i], vals[i]);
- }
-
- if (redirect != null && !"self".equals(redirect)) b.redirect = redir;
-
- for(int i=0; _postapply != null && i<_postapply.length; i++)
- if (_postapply[i] != null) {
- _postapply[i].apply(b, null, null, callback, numerator, denominator);
- numerator += _postapply[i].numUnits();
- }
-
- pboxes.setSize(numids);
- ptemplates.setSize(numids);
-
- numerator = original_numerator + numUnits();
-
- if (callback != null)
- try {
- JS.Array args = new JS.Array();
- args.addElement(new Double(numerator));
- args.addElement(new Double(denominator));
- callback.call(args);
- } catch (JS.Exn e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e);
- }
-
- if (Thread.currentThread() instanceof ThreadMessage) try {
- XWT.sleep(0);
- } catch (JS.Exn e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e);