import java.util.zip.*;
import java.util.*;
import java.lang.*;
-import org.mozilla.javascript.*;
+import org.xwt.js.*;
import org.xwt.util.*;
/**
private boolean changed = false;
/** the script on the static node of this template, null if it has already been executed */
- private Script staticscript = null;
+ private JS.CompiledFunction staticscript = null;
/** the script on this node */
- private Script script = null;
+ private JS.CompiledFunction script = null;
/** during XML parsing, this holds the list of currently-parsed children; null otherwise */
private Vec childvect = new Vec();
// Static data/methods ///////////////////////////////////////////////////////////////////
- /** maximum length of a line */
- private static final int MAX_COLUMN = 150;
-
/** a template cache so that only one Template object is created for each xwt */
private static Hashtable cache = new Hashtable(1000);
* @param pboxes a vector of all box parents on which to put $-references
* @param ptemplates a vector of the nodeNames to recieve private references on the pboxes
*/
- void apply(Box b, Vec pboxes, Vec ptemplates, Function callback, int numerator, int denominator) {
+ void apply(Box b, Vec pboxes, Vec ptemplates, JS.Callable callback, int numerator, int denominator) {
int original_numerator = numerator;
for(int i=0; i<pboxes.size(); i++) {
Box parent = (Box)pboxes.elementAt(i);
String parentNodeName = (String)ptemplates.elementAt(i);
- parent.putPrivately("$" + id, b, parentNodeName);
+ parent.put("$" + id, b);
}
if (script != null || (redirect != null && !"self".equals(redirect))) {
}
for (int i=0; children != null && i<children.length; i++) {
- b.put(Integer.MAX_VALUE, null, new Box(children[i], pboxes, ptemplates, callback, numerator, denominator));
+ Box newkid = new Box();
+ children[i].apply(newkid, pboxes, ptemplates, callback, numerator, denominator);
+ b.put(Integer.MAX_VALUE, newkid);
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.getPrivately("$" + redirect, nodeName);
+ if (redirect != null && !"self".equals(redirect)) redir = (Box)b.get("$" + redirect);
if (script != null) try {
- Context cx = Context.enter();
- script.exec(cx, b);
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while instantiating " + nodeName + " at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
+ script.call(new JS.Array(), b);
+ } catch (JS.Exn e) {
if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while instantiating " + nodeName + " at " + e.sourceFile + ":" + e.line);
}
for(int i=0; keys != null && i<keys.length; i++) {
- Context.enter().interpreterSourceFile = nodeName;
- Context.enter().interpreterLine = startLine;
- 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], null, 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);
+ try {
+ 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]);
+ } catch(JS.Exn e) {
+ if(Log.on) Log.log(this,"WARNING: uncaught ecmascript exception while putting attr \"" + keys[i] +
+ "\" of " + nodeName + " : " + e.getMessage());
}
- else b.put(keys[i], null, vals[i]);
}
if (redirect != null && !"self".equals(redirect)) b.redirect = redir;
if (callback != null)
try {
- callback.call(Context.enter(), null, null, new Object[] { new Double(numerator), new Double(denominator) });
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within progress callback at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within progress callback at " + e.sourceFile + ":" + e.line);
+ 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.yield.call(Context.enter(), null, null, null);
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within yield at " + e.sourceFile + ":" + e.line);
+ XWT.sleep(0);
+ } catch (JS.Exn e) {
+ if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e);
}
}
}
/** adds a theme mapping, retemplatizing as needed */
- public static void retheme(Function callback) {
+ public static void retheme(JS.Callable callback) {
+ /*
XWF.flushXWFs();
// clear changed marker and relink
if (callback != null)
try {
- callback.call(Context.enter(), null, null, new Object[] { new Double(1.0), new Double(1.0) });
- } catch (EcmaError ex) {
- if (Log.on) Log.log(Template.class, "WARNING: uncaught interpreter exception: " + ex.getMessage());
- if (Log.on) Log.log(Template.class, " thrown from within progress callback at " + ex.getSourceName() + ":" + ex.getLineNumber());
- } catch (JavaScriptException ex) {
+ JS.Array args = new JS.Array();
+ args.addElement(new Double(1.0));
+ args.addElement(new Double(1.0));
+ callback.call(args);
+ } catch (JS.Exn ex) {
if (Log.on) Log.log(Template.class, "WARNING: uncaught ecmascript exception: " + ex.getMessage());
- if (Log.on) Log.log(Template.class, " thrown from within progress callback at " + ex.sourceFile + ":" + ex.line);
}
+ */
}
/** template reapplication procedure */
private static void reapply(Box b) {
+ Log.log(Template.class, "Template.reapply() not implemented");
+ /*
// Ref 7.5.1: check if we need to retemplatize
boolean retemplatize = false;
if (b.templatename != null) {
// Recurse
for(Box j = b.getChild(0); j != null; j = j.nextSibling()) reapply(j);
+ */
}
/** runs statics, resolves string references to other templates into actual Template instance references, and sets <tt>change</tt> as needed */
private void link(boolean force) {
if (staticscript != null) try {
- Scriptable s = Static.createStatic(nodeName, false);
+ JS.Scope s = Static.createStatic(nodeName, false);
if (staticscript != null) {
- Script temp = staticscript;
- ((InterpretedScript)temp).setParentScope(s); // so we know how to handle Static.get("xwt")
+ JS.CompiledFunction temp = staticscript;
staticscript = null;
- temp.exec(Context.enter(), s);
+
+ // we layer a transparent scope over the Static so that we can catch requests for the xwt object
+ // yet not screw up paths that include a package called xwt (ie xwt.static.org.xwt.foo)
+ JS.Scope varScope = new JS.Scope(s) {
+ public boolean isTransparent() { return true; }
+ public Object get(Object key) {
+ if ("xwt".equals(key)) return XWT.singleton; else return super.get(key);
+ } };
+
+ temp.call(new JS.Array(), varScope);
}
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while executing <static/> block for " + nodeName +
- " at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
+ } catch (JS.Exn e) {
if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while executing <static/> block for " + nodeName + " at " + e.sourceFile + ":" + e.line);
}
if (!(force || (preapply != null && _preapply == null) || (postapply != null && _postapply == null))) return;
if (t.redirect != null)
throw new XML.SchemaException("the <redirect> header element may not appear more than once");
t.redirect = c.vals[0].toString();
+ if(t.redirect.equals("null")) t.redirect = null;
return;
} else if (c.localName.equals("preapply")) {
}
}
- private Script genscript(boolean isstatic) {
- Script thisscript = null;
- Context cx = Context.enter();
- cx.setOptimizationLevel(-1);
-
+ private JS.CompiledFunction genscript(boolean isstatic) {
+ JS.CompiledFunction thisscript = null;
try {
- thisscript = cx.compileReader(null, new StringReader(t.content.toString()), t.nodeName + (isstatic ? "._" : ""), t.content_start, null);
- } catch (EcmaError ee) {
- if (Log.on) Log.log(this, ee.getMessage() + " at " + ee.getSourceName() + ":" + ee.getLineNumber());
- thisscript = null;
- } catch (EvaluatorException ee) {
+ thisscript = JS.parse(t.nodeName + (isstatic ? "._" : ""), t.content_start, new StringReader(t.content.toString()));
+ } catch (JS.Exn ee) {
if (Log.on) Log.log(this, " ERROR: " + ee.getMessage());
thisscript = null;
} catch (IOException ioe) {
}
public void characters(char[] ch, int start, int length) throws XML.SchemaException {
- // invoke the max-column-length and no-tab crusade
- if (getCol() + length > MAX_COLUMN) throw new XML.SchemaException(
- t.nodeName+ ":" + getLine() + ": lines longer than " + MAX_COLUMN + " characters not allowed");
-
+ // invoke the no-tab crusade
for (int i=0; length >i; i++) if (ch[start+i] == '\t') throw new XML.SchemaException(
t.nodeName+ ":" + getLine() + "," + getCol() + ": tabs are not allowed in XWT files");