// FIXME memory leak
static Hash boxToCursor = new Hash(500, 3);
- static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get("fonts/vera/Vera.ttf"), 10);
+ static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10);
// Flags //////////////////////////////////////////////////////////////////////
set(REPLACE); // FIXME: be smarter / more incremental
}
+ private final static JS SIZECHANGE = JS.S("SizeChange");
+
void resize(int x, int y, int width, int height) {
if (x == this.x && y == this.y && width == this.width && height == this.height) return;
- boolean sizechange = (this.width != width || this.height != height) && hasTrap("SizeChange");
+ boolean sizechange = (this.width != width || this.height != height) && hasTrap(SIZECHANGE);
int thisx = parent == null ? 0 : this.x;
int thisy = parent == null ? 0 : this.y;
Box who = (parent == null ? this : parent);
this.width = width; this.height = height; this.x = x; this.y = y;
dirty();
}
- if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T);
+ if (sizechange) putAndTriggerTrapsAndCatchExceptions(SIZECHANGE, T);
}
private float targetColumnSize = (float)0.0;
// Methods to implement org.ibex.js.JS //////////////////////////////////////
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+ public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
switch (nargs) {
case 1: {
- //#switch(method)
+ //#switch(JS.toString(method))
case "indexof":
Box b = (Box)a0;
if (b.parent != this)
case "distanceto":
Box b = (Box)a0;
JS ret = new JS.O();
- ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0)));
- ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0)));
+ ret.put(JS.S("x"), N(b.localToGlobalX(0) - localToGlobalX(0)));
+ ret.put(JS.S("y"), N(b.localToGlobalY(0) - localToGlobalY(0)));
return ret;
//#end
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
- public Object get(Object name) throws JSExn {
- if (name instanceof Number)
- return redirect == null ? null : redirect == this ? getChild(toInt(name)) : redirect.get(name);
+ public JS get(JS name) throws JSExn {
+ if (JS.isInt(name))
+ return redirect == null ? null : redirect == this ? getChild(JS.toInt(name)) : redirect.get(name);
- //#switch(name)
- case "surface": return parent == null ? null : parent.getAndTriggerTraps("surface");
+ //#switch(JS.toString(name))
+ case "surface": return parent == null ? null : parent.getAndTriggerTraps(name);
case "indexof": return METHOD;
case "distanceto": return METHOD;
- case "text": return text;
- case "path":
- if (path != null) return path.toString();
+ case "text": return JS.S(text);
+ case "path": {
+ if (path != null) return JS.S(path.toString());
if (text == null) return null;
if (font == null) return null;
String ret = "";
for(int i=0; i<text.length(); i++) ret += font.glyphs[text.charAt(i)].path;
- return ret;
- case "fill": return Color.colorToString(fillcolor);
- case "strokecolor": return Color.colorToString(strokecolor);
- case "textcolor": return Color.colorToString(strokecolor);
+ return JS.S(ret);
+ }
+ case "fill": return JS.S(Color.colorToString(fillcolor));
+ case "strokecolor": return JS.S(Color.colorToString(strokecolor));
+ case "textcolor": return JS.S(Color.colorToString(strokecolor));
case "font": return font == null ? null : font.stream;
case "fontsize": return font == null ? N(10) : N(font.pointsize);
case "strokewidth": return N(strokewidth);
- case "align": return alignToString();
+ case "align": return JS.S(alignToString());
case "thisbox": return this;
case "shrink": return B(test(HSHRINK) || test(VSHRINK));
case "hshrink": return B(test(HSHRINK));
case "minheight": return N(minheight);
case "maxheight": return N(maxheight);
case "clip": return B(test(CLIP));
- case "visible": return B(test(VISIBLE) && (parent == null || (parent.get("visible") == T)));
+ case "visible": return B(test(VISIBLE) && (parent == null || (parent.get(JS.S("visible")) == T)));
case "packed": return B(test(PACKED));
case "globalx": return N(localToGlobalX(0));
case "globaly": return N(localToGlobalY(0));
- case "cursor": return test(CURSOR) ? boxToCursor.get(this) : null;
+ case "cursor": return test(CURSOR) ? JS.S((String)boxToCursor.get(this)) : null;
case "mouse":
if (getSurface() == null) return null;
if (getSurface()._mousex == Integer.MAX_VALUE)
throw new JSExn("you cannot read from the box.mouse property in background thread context");
return new Mouse();
- case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get("numchildren");
- case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get("redirect");
+ case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get(JS.S("numchildren"));
+ case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get(JS.S("redirect"));
case "Minimized": if (parent == null && getSurface() != null) return B(getSurface().minimized);
default: return super.get(name);
//#end
}
private class Mouse extends JS implements JS.Cloneable {
- public Object get(Object key) {
- //#switch(key)
+ public JS get(JS key) throws JSExn {
+ //#switch(JS.toString(key))
case "x": return N(globalToLocalX(getSurface()._mousex));
case "y": return N(globalToLocalY(getSurface()._mousey));
}
//#end
- public void put(Object name, Object value) throws JSExn {
- if (name instanceof Number) { put(toInt(name), value); return; }
- //#switch(name)
+ public void put(JS name, JS value) throws JSExn {
+ if (JS.isInt(name)) { put(JS.toInt(name), value); return; }
+ //#switch(JS.toString(name))
case "thisbox": if (value == null) removeSelf();
- case "text": if (value == null) value = ""; CHECKSET_STRING(text); RECONSTRAIN(); dirty();
- case "strokecolor": value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
- case "textcolor": value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
+ case "text": { String s = value == null ? "" : JS.toString(value); CHECKSET_STRING(text); RECONSTRAIN(); dirty(); }
+ case "strokecolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
+ case "textcolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
case "strokewidth": CHECKSET_SHORT(strokewidth); dirty();
case "shrink": CHECKSET_FLAG(HSHRINK | VSHRINK); RECONSTRAIN();
case "hshrink": CHECKSET_FLAG(HSHRINK); RECONSTRAIN();
case "rowspan": if (toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); }
case "visible": CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); dirty();
case "packed": CHECKSET_FLAG(PACKED); if (parent != null) { parent.REPACK(); } else { REPACK(); }
- case "align": clear(ALIGNS); setAlign(value == null ? "center" : value); REPLACE();
- case "cursor": setCursor(value);
+ case "align": clear(ALIGNS); setAlign(value == null ? "center" : JS.toString(value)); REPLACE();
+ case "cursor": setCursor(JS.toString(value));
case "fill": setFill(value);
case "clip": CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty();
case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); REPACK();
// FIXME: remove
case "mouse":
- int mousex = toInt(((JS)value).get("x"));
- int mousey = toInt(((JS)value).get("y"));
+ int mousex = toInt(((JS)value).get(JS.S("x")));
+ int mousey = toInt(((JS)value).get(JS.S("y")));
getSurface()._mousex = localToGlobalX(mousex);
getSurface()._mousey = localToGlobalY(mousey);
case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty();
case "font":
if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property");
- if (font == value) return; // FIXME: unclone()
+ //FIXME: if (font == value) return; // FIXME: unclone()
font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize);
RECONSTRAIN();
dirty();
case "KeyReleased": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
case "Move": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
case "HScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
- parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+ parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize())));
case "VScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
- parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+ parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize())));
case "_Move": propagateDownward(name, value, false);
case "_Press1": propagateDownward(name, value, false);
}
}
- private void setAlign(Object value) {
+ private void setAlign(String value) {
clear(ALIGNS);
//#switch(value)
case "topleft": set(ALIGN_TOP | ALIGN_LEFT);
//#end
}
- private void setCursor(Object value) {
+ private void setCursor(String value) throws JSExn {
if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; }
if (value.equals(boxToCursor.get(this))) return;
set(CURSOR);
if (surface.cursor != tempcursor) surface.syncCursor();
}
- private void setFill(Object value) throws JSExn {
+ private void setFill(JS value) throws JSExn {
if (value == null) {
if (texture == null && fillcolor == 0) return;
texture = null;
fillcolor = 0;
- } else if (value instanceof String) {
- int newfillcolor = Color.stringToColor((String)value);
+ } else if (JS.isString(value)) {
+ int newfillcolor = Color.stringToColor(JS.toString(value));
if (newfillcolor == fillcolor) return;
fillcolor = newfillcolor;
texture = null;
- } else if (value instanceof JS) {
+ } else {
Picture newtex = Picture.load((JS)value, this);
if (texture == newtex) return;
texture = newtex;
fillcolor = 0;
if (texture != null && texture.isLoaded) perform();
- } else {
- throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass());
}
dirty();
}
* Handles events which propagate down the box tree. If obscured
* is set, then we merely check for Enter/Leave.
*/
- private void propagateDownward(Object name_, Object value, boolean obscured) {
+ private void propagateDownward(JS name_, JS value, boolean obscured) throws JSExn {
- String name = (String)name_;
+ String name = JS.toString(name_);
if (getSurface() == null) return;
int x = globalToLocalX(getSurface()._mousex);
int y = globalToLocalY(getSurface()._mousey);
boolean isinside = test(VISIBLE) && inside(x, y) && !obscured;
if (!wasinside && isinside) {
set(MOUSEINSIDE);
- putAndTriggerTrapsAndCatchExceptions("Enter", T);
+ putAndTriggerTrapsAndCatchExceptions(JS.S("Enter"), T);
}
if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this);
if (wasinside && !isinside) {
clear(MOUSEINSIDE);
- putAndTriggerTrapsAndCatchExceptions("Leave", T);
+ putAndTriggerTrapsAndCatchExceptions(JS.S("Leave"), T);
}
boolean found = false;
if (wasinside || isinside)
for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
- Object value2 = value;
+ JS value2 = value;
if (name.equals("_HScroll") || name.equals("_VScroll"))
- value2 = N(((Number)value).floatValue() * ((float)child.fontSize()) / (float)fontSize());
+ value2 = N(JS.toFloat(value) * ((float)child.fontSize()) / (float)fontSize());
if (obscured || !child.inside(x - child.x, y - child.y)) {
- child.propagateDownward(name, value2, true);
+ child.propagateDownward(name_, value2, true);
} else try {
found = true;
child.clear(STOP_UPWARD_PROPAGATION);
- if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value2);
- else child.propagateDownward(name, value2, obscured);
+ if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name_, value2);
+ else child.propagateDownward(name_, value2, obscured);
} finally {
if (save_stop) child.set(STOP_UPWARD_PROPAGATION); else child.clear(STOP_UPWARD_PROPAGATION);
}
if (!obscured && !found)
if ("_Move".equals(name) || name.startsWith("_Release") || wasinside)
if (name != null)
- putAndTriggerTrapsAndCatchExceptions(name.substring(1), value);
+ putAndTriggerTrapsAndCatchExceptions(JS.S(name.substring(1)), value);
}
/** figures out what box in this subtree of the Box owns the pixel at x,y relitave to the Surface */
deleteNode(i);
b.parent = null;
REPACK();
- putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+ putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
}
- public void put(int i, Object value) throws JSExn {
+ public void put(int i, JS value) throws JSExn {
if (i < 0) return;
if (value != null && !(value instanceof Box)) {
}
if (redirect == null) {
- if (value == null) putAndTriggerTrapsAndCatchExceptions("ChildChange", getChild(i));
+ if (value == null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), getChild(i));
else JS.warn("attempt to add/remove children to/from a node with a null redirect");
} else if (redirect != this) {
- if (value != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", value);
+ if (value != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), value);
redirect.put(i, value);
if (value == null) {
- Box b = (Box)redirect.get(new Integer(i));
- if (b != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+ Box b = (Box)redirect.get(JS.N(i));
+ if (b != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
}
} else if (value == null) {
if (i < 0 || i > treeSize()) return;
Box b = getChild(i);
removeChild(i);
- putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+ putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
} else {
Box b = (Box)value;
REPACK();
b.dirty();
- putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+ putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
}
}
- public void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
+ public void putAndTriggerTrapsAndCatchExceptions(JS name, JS val) {
try {
putAndTriggerTraps(name, val);
} catch (JSExn e) {
- JS.log("caught js exception while putting to trap \""+name+"\"");
+ JS.log("caught js exception while putting to trap \""+ JS.debugToString(name)+"\"");
JS.log(e);
} catch (Exception e) {
- JS.log("caught exception while putting to trap \""+name+"\"");
+ JS.log("caught exception while putting to trap \""+ JS.debugToString(name)+"\"");
JS.log(e);
}
}
-
}
-
-
-
-
-
-
while(str.indexOf('.') != -1) {
String path = str.substring(0, str.indexOf('.'));
str = str.substring(str.indexOf('.') + 1);
- ret = (JS)ret.get(path);
+ ret = ret.get(JS.S(path));
}
- if (!"".equals(str)) ret = (JS)ret.get(str);
+ if (!"".equals(str)) ret = ret.get(JS.S(str));
return ret;
}
private class Sub extends JS {
String key;
Sub(String key) { this.key = key; }
- public void put(Object key, Object val) throws JSExn { Ibex.this.put(this.key + "." + key, val); }
- public Object get(Object key) throws JSExn { return Ibex.this.get(this.key + "." + key); }
- public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+ public void put(JS key, JS val) throws JSExn { Ibex.this.put(this.key + "." + JS.toString(key), val); }
+ public JS get(JS key) throws JSExn { return Ibex.this.get(this.key + "." + JS.toString(key)); }
+ public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
return Ibex.this.callMethod(this.key, a0, a1, a2, rest, nargs);
}
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- return Ibex.this.callMethod(this.key + "." + method, a0, a1, a2, rest, nargs);
+ public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
+ return Ibex.this.callMethod(this.key + "." + JS.toString(method), a0, a1, a2, rest, nargs);
}
}
private Cache subCache = new Cache(20);
return ret;
}
- public Object get(Object name) throws JSExn {
+ public JS get(JS key) throws JSExn { return JS.isString(key) ? get(JS.toString(key)) : null; }
+ JS get(String name) throws JSExn {
if (name instanceof String && ((String)name).length() == 0) return rr;
//#switch(name)
case "math": return ibexMath;
case "ui.font.wait": return METHOD;
case "ui.font.width": return METHOD;
case "ui.font.height": return METHOD;
- case "ui.font.sansserif": return Main.builtin.get("fonts/vera/Vera.ttf");
- case "ui.font.monospace": return Main.builtin.get("fonts/vera/VeraMono.ttf");
- case "ui.font.serif": return Main.builtin.get("fonts/vera/VeraSe.ttf");
+ case "ui.font.sansserif": return Main.builtin.get(JS.S("fonts/vera/Vera.ttf"));
+ case "ui.font.monospace": return Main.builtin.get(JS.S("fonts/vera/VeraMono.ttf"));
+ case "ui.font.serif": return Main.builtin.get(JS.S("fonts/vera/VeraSe.ttf"));
case "ui.browser": return METHOD;
case "ui.mouse": return getSub("ui.mouse");
case "ui.mouse.button":
else return ZERO;
case "ui.key": return getSub("ui.key");
case "ui.key.name": return getSub("ui.key.name");
- case "ui.key.name.alt": return Platform.altKeyName();
+ case "ui.key.name.alt": return JS.S(Platform.altKeyName());
case "ui.key.alt": return Surface.alt ? T : F;
case "ui.key.control": return Surface.control ? T : F;
case "ui.key.shift": return Surface.shift ? T : F;
- case "ui.clipboard": return Platform.getClipBoard();
+ case "ui.clipboard": return JS.S((String)Platform.getClipBoard());
case "ui.maxdim": return N(Short.MAX_VALUE);
case "ui.screen": return getSub("ui.screen");
case "ui.screen.width": return N(Platform.getScreenWidth());
case "ui.screen.height": return N(Platform.getScreenHeight());
case "undocumented": return getSub("undocumented");
- case "undocumented.initialOrigin": return Main.origin;
- case "undocumented.initialTemplate": return Main.initialTemplate;
+ case "undocumented.initialOrigin": return JS.S(Main.origin);
+ case "undocumented.initialTemplate": return JS.S(Main.initialTemplate);
case "thread": return getSub("thread");
case "thread.yield": return METHOD;
case "thread.sleep": return METHOD;
case "crypto.sha1": return METHOD;
case "crypto.rc4": return METHOD;
//#end
- return super.get(name);
+ return null;
}
- public void put(Object name, final Object value) throws JSExn {
+ public void put(JS key, JS value) throws JSExn { if(JS.isString(key)) put(JS.toString(key),value); else super.put(key,value); }
+ void put(Object name, final JS value) throws JSExn {
//#switch(name)
case "thread": Scheduler.add((Task)value); return;
- case "ui.clipboard": Platform.setClipBoard((String)value); return;
+ case "ui.clipboard": Platform.setClipBoard(JS.toString(value)); return;
case "ui.frame": Platform.createSurface((Box)value, true, true); return;
case "ui.window": Platform.createSurface((Box)value, false, true); return;
case "undocumented.proxyAuthorization":
throw new JSExn("attempted to put unknown property: ibex."+name);
}
- public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+ public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+ if(JS.isString(name)) return callMethod(JS.toString(name),a,b,c,rest,nargs);
+ return super.callMethod(name,a,b,c,rest,nargs);
+ }
+ JS callMethod(String name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
try {
//#switch(name)
case "date": return new JSDate(a, b, c, rest, nargs);
- case "net.rpc.soap": return new SOAP((String)a, "", (String)b, (String)c);
+ case "net.rpc.soap": return new SOAP(JS.toString(a), "", JS.toString(b), JS.toString(c));
// FIXME support object dumping
case "log.debug": JS.debug(a== null ? "**null**" : a.toString()); return null;
case "log.info": JS.info(a== null ? "**null**" : a.toString()); return null;
if(a == null) throw new JSExn("can't clone the null value");
return ((JS)a).jsclone();
case "bless": return bless((JS)a);
- case "ui.browser": Platform.newBrowserWindow((String)a); return null;
+ case "ui.browser": Platform.newBrowserWindow(JS.toString(a)); return null;
case "stream.unzip": return new Stream.Zip((Stream)a);
case "stream.uncab": return new Stream.Cab((Stream)a);
case "stream.cache":
try { return new Stream.CachedStream((Stream)a, "resources", true); }
catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); }
case "stream.url": {
- String url = (String)a;
+ String url = JS.toString(a);
if (url.startsWith("http://")) return new Stream.HTTP(url);
else if (url.startsWith("https://")) return new Stream.HTTP(url);
else if (url.startsWith("data:")) return new Stream.ByteArray(Base64.decode(url.substring(5)), null);
}
case "thread.sleep": sleep(JS.toInt(a)); return null;
case "regexp": return new JSRegexp(a, null);
- case "net.rpc.xml": return new XMLRPC((String)a, "");
+ case "net.rpc.xml": return new XMLRPC(JS.toString(a), "");
case "crypto.rsa": /* FEATURE */ return null;
case "crypto.md5": /* FEATURE */ return null;
case "crypto.sha1": /* FEATURE */ return null;
case "stream.parse.html": throw new JSExn("not implemented yet"); //return null;
case "stream.parse.xml": new XMLHelper((JS)b).doParse((JS)a); return null;
// FIXME backgrounding
- case "stream.parse.utf8": try { return new String(InputStreamToByteArray.convert(Stream.getInputStream(a))); }
+ case "stream.parse.utf8": try { return JS.S(new String(InputStreamToByteArray.convert(Stream.getInputStream(a)))); }
catch (Exception e) { Log.warn(this, e); }
//#end
break;
//#end
case 3:
//#switch(name)
- case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight((String)c));
+ case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight(JS.toString(c)));
case "ui.font.wait": throw new Error("FIXME: ibex.ui.font.wait not implemented");
- case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth((String)c));
+ case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth(JS.toString(c)));
//#end
break;
}
public static final JSMath ibexMath = new JSMath() {
// FEATURE: find a cleaner way to do this
- private JS gs = new JSScope.Global();
- public Object get(Object key) throws JSExn {
- //#switch(key)
+ private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope
+ public JS get(JS key) throws JSExn {
+ //#switch(JS.toString(key))
case "isNaN": return METHOD;
case "isFinite": return METHOD;
case "NaN": return METHOD;
//#end
return super.get(key);
}
- public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
- //#switch(name)
+ public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+ //#switch(JS.toString(name))
case "isNaN": return gs.callMethod(name,a,b,c,rest,nargs);
case "isFinite": return gs.callMethod(name,a,b,c,rest,nargs);
case "NaN": return gs.callMethod(name,a,b,c,rest,nargs);
};
public static final JS ibexString = new JS() {
- private JS gs = new JSScope.Global();
- public Object get(Object key) throws JSExn {
- //#switch(key)
+ private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope
+ public JS get(JS key) throws JSExn {
+ //#switch(JS.toString(key))
case "parseInt": return METHOD;
case "parseFloat": return METHOD;
case "decodeURI": return METHOD;
//#end
return super.get(key);
}
- public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
- //#switch(name)
+ public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+ //#switch(JS.toString(name))
case "parseInt": return gs.callMethod(name,a,b,c,rest,nargs);
case "parseFloat": return gs.callMethod(name,a,b,c,rest,nargs);
case "decodeURI": return gs.callMethod(name,a,b,c,rest,nargs);
private JS characters, whitespace, endElement, startElement;
public XMLHelper(JS b) throws JSExn {
super(BUFFER_SIZE);
- startElement = (JS)b.getAndTriggerTraps("startElement");
- endElement = (JS)b.getAndTriggerTraps("endElement");
- characters = (JS)b.getAndTriggerTraps("characters");
- whitespace = (JS)b.getAndTriggerTraps("whitespace");
+ startElement = b.getAndTriggerTraps(JS.S("startElement"));
+ endElement = b.getAndTriggerTraps(JS.S("endElement"));
+ characters = b.getAndTriggerTraps(JS.S("characters"));
+ whitespace = b.getAndTriggerTraps(JS.S("whitespace"));
}
public void startElement(XML.Element c) throws XML.Exn { try {
JS attrs = new JS.O();
// FIXME attribute URIs? add an additional hash?
- for(int i=0; i<c.getAttrLen(); i++) attrs.put(c.getAttrKey(i), c.getAttrVal(i));
- startElement.call(c.getLocalName(), attrs, c.getUri(), null, 3);
+ for(int i=0; i<c.getAttrLen(); i++) attrs.put(JS.S(c.getAttrKey(i)), JS.S(c.getAttrVal(i)));
+ startElement.call(JS.S(c.getLocalName()), attrs, JS.S(c.getUri()), null, 3);
} catch (JSExn jse) { throw new Wrapper(jse); } }
public void endElement(XML.Element c) throws XML.Exn { try {
- endElement.call(c.getLocalName(), c.getUri(), null, null, 2);
+ endElement.call(JS.S(c.getLocalName()), JS.S(c.getUri()), null, null, 2);
} catch (JSExn jse) { throw new Wrapper(jse); } }
public void characters(char[] ch, int start, int length) throws XML.Exn { try {
- characters.call(new String(ch, start, length), null, null, null, 1);
+ characters.call(JS.S(new String(ch, start, length)), null, null, null, 1);
} catch (JSExn jse) { throw new Wrapper(jse); } }
public void whitespace(char[] ch, int start, int length) throws XML.Exn { try {
- whitespace.call(new String(ch, start, length), null, null, null, 1);
+ whitespace.call(JS.S(new String(ch, start, length)), null, null, null, 1);
} catch (JSExn jse) { throw new Wrapper(jse); } }
public void doParse(JS s) throws JSExn {
public static class Blessing extends JS.Clone {
private Ibex ibex;
private Template t = null;
- public Object parentkey = null;
+ public JS parentkey = null;
public Blessing parent = null;
private Hash cache = new Hash();
- public Blessing(JS clonee, Ibex ibex, Blessing parent, Object parentkey) throws JSExn {
+ public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn {
super(clonee); this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
- public Object get(Object key) throws JSExn {
- if (key.equals("")) return ((Object)getStatic());
- if (cache.get(key) != null) return cache.get(key);
- Object ret = new Blessing((JS)clonee.get(key), ibex, this, key);
+ public JS get(JS key) throws JSExn {
+ if (JS.isString(key) && JS.toString(key).equals("")) return getStatic();
+ if (cache.get(key) != null) return (JS)cache.get(key);
+ JS ret = new Blessing(clonee.get(key), ibex, this, key);
cache.put(key, ret);
return ret;
}
- public static Blessing getBlessing(Object o) {
- if (!(o instanceof JS)) return null;
- JS js = (JS)o;
+ public static Blessing getBlessing(JS js) {
while (js instanceof JS.Clone && !(js instanceof Blessing)) js = ((JS.Clone)js).getClonee();
if (!(js instanceof Blessing)) return null;
return (Blessing)js;
String[] exts = new String[] { ".png", ".jpeg", ".gif" };
for (int i=0; i < exts.length; i++)
try {
- InputStream in = Stream.getInputStream(parent.get(parentkey + exts[i]));
+ InputStream in = Stream.getInputStream(parent.get(JS.S(JS.toString(parentkey) + exts[i])));
if (in != null) return in;
} catch (IOException f) { /* DELIBERATE */ }
return null;
public JSScope getStatic() {
try {
if (t == null) {
- JS res = (JS) parent.get(parentkey + ".t");
+ JS res = (JS) parent.get(JS.S(JS.toString(parentkey) + ".t"));
t = Template.buildTemplate(res.unclone().toString(), res, ibex);
}
return t.staticScope;
return null;
}
}
- public Object call(Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+ public JS call(JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
// GROSS hack
if (nargs != 1 && nargs != 9999) throw new JSExn("FIXME can only call with one arg");
getStatic();
if (t == null) throw new JSExn("No such template " + parentkey);
- if (nargs == 9999) return t;
+ if (nargs == 9999) /*return t;*/ throw new Error("FIXME"); // FIXME: 9999 stuff
+ if(!(a instanceof Box)) throw new JSExn("can only apply templates to boxes");
t.apply((Box)a);
return a;
}
final Ibex ibex = new Ibex(rr);
org.ibex.graphics.Surface.scarImage =
- Picture.load((Stream)Main.builtin.get("org/ibex/core/builtin/scar.png"),
+ Picture.load((Stream)Main.builtin.get(JS.S("org/ibex/core/builtin/scar.png")),
new Task() { public void perform() throws JSExn, UnknownHostException {
if (Log.on) Log.info(Main.class, "invoking initial template");
ibex.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1);
String id = null; ///< the id of this box
String redirect = null; ///< the id of the redirect target; only meaningful on a root node
private String[] keys; ///< keys to be "put" to instances of this template; elements correspond to those of vals
- private Object[] vals; ///< values to be "put" to instances of this template; elements correspond to those of keys
+ private JS[] vals; ///< values to be "put" to instances of this template; elements correspond to those of keys
private String[] urikeys;
private String[] urivals;
private Vec children = new Vec(); ///< during XML parsing, this holds the list of currently-parsed children; null otherwise
PerInstantiationScope pis = new PerInstantiationScope(b, ibex, parentPis, staticObject);
for(int i=0; i<urikeys.length; i++) {
if (urikeys[i] == null) continue;
- pis.declare(urikeys[i]);
- pis.put(urikeys[i], ibex.resolveString(urivals[i], true));
+ // FEATURE: Cache urikeys and resolved resources
+ pis.declare(JS.S(urikeys[i]));
+ pis.put(JS.S(urikeys[i]), ibex.resolveString(urivals[i], true));
}
// FIXME needs to obey the new application-ordering rules
for (int i=0; children != null && i<children.size(); i++) {
Box kid = new Box();
((Template)children.elementAt(i)).apply(kid, pis);
- b.putAndTriggerTraps(b.get("numchildren"), kid);
+ b.putAndTriggerTraps(b.get(JS.S("numchildren")), kid);
}
if (script != null) JS.cloneWithNewParentScope(script, pis).call(null, null, null, null, 0);
- Object key, val;
for(int i=0; keys != null && i < keys.length; i++) {
if (keys[i] == null) continue;
- key = keys[i];
- val = vals[i];
+ String key = keys[i];
+ JS val = vals[i];
if ("null".equals(val)) val = null;
- if (val != null && val instanceof String && ((String)val).length() > 0) {
- switch (((String)val).charAt(0)) {
+ if (JS.isString(val) && (JS.toString(val).length() > 0)) {
+ switch (JS.toString(val).charAt(0)) {
case '$':
val = pis.get(val);
- if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute");
+ if (val == null) throw new JSExn("unknown box id '"+JS.toString(vals[i])+"' referenced in XML attribute");
break;
case '.':
- val = ibex.resolveString(((String)val).substring(1), false);
+ val = ibex.resolveString(JS.toString(val).substring(1), false);
// FIXME: url case
// FIXME: should we be resolving all of these in the XML-parsing code?
}
}
- b.putAndTriggerTraps(key, val);
+ b.putAndTriggerTraps(JS.S(key), val);
}
}
// XML Parsing /////////////////////////////////////////////////////////////////
- public static Template buildTemplate(String sourceName, Object s, Ibex ibex) {
+ public static Template buildTemplate(String sourceName, JS s, Ibex ibex) {
try {
return new TemplateHelper(sourceName, s, ibex).t;
} catch (Exception e) {
String initial_uri = "";
- public TemplateHelper(String sourceName, Object s, Ibex ibex) throws XML.Exn, IOException, JSExn {
+ public TemplateHelper(String sourceName, JS s, Ibex ibex) throws XML.Exn, IOException, JSExn {
this.sourceName = sourceName;
this.ibex = ibex;
InputStream is = Stream.getInputStream(s);
// GROSS hack
try {
// GROSSER hack
- t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+ // t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+ throw new Error("FIXME - 9999 thing"); // FIXME:9999 thing
} catch (Exception e) {
Log.error(Template.class, e);
}
} });
t.keys = new String[keys.size()];
- t.vals = new Object[vals.size()];
+ t.vals = new JS[vals.size()];
keys.copyInto(t.keys);
vals.copyInto(t.vals);
String valString = t.vals[i].toString();
- if (valString.equals("true")) t.vals[i] = Boolean.TRUE;
- else if (valString.equals("false")) t.vals[i] = Boolean.FALSE;
+ if (valString.equals("true")) t.vals[i] = JS.T;
+ else if (valString.equals("false")) t.vals[i] = JS.F;
else if (valString.equals("null")) t.vals[i] = null;
else {
boolean hasNonNumeral = false;
hasNonNumeral = true;
break;
}
- if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = new Double(valString);
- else t.vals[i] = valString.intern();
+ if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = JS.N(Double.parseDouble((valString)));
+ else t.vals[i] = JS.S(valString.intern()); // FEATURE: JS.intern() ?
}
}
}
JS myStatic = null;
void putDollar(String key, Box target) throws JSExn {
if (parentBoxPis != null) parentBoxPis.putDollar(key, target);
- declare("$" + key);
- put("$" + key, target);
+ JS jskey = JS.S("$" + key);
+ declare(jskey);
+ put(jskey, target);
}
public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) {
super(parentScope);
this.ibex = ibex;
this.myStatic = myStatic;
}
- public Object get(Object key) throws JSExn {
+ public JS get(JS key) throws JSExn {
if (super.has(key)) return super.get(key);
- if (key.equals("ibex")) return ibex;
- if (key.equals("")) return ibex.get("");
- if (key.equals("static")) return myStatic;
+ if(JS.isString(key)) {
+ String s = JS.toString(key);
+ if (s.equals("ibex")) return ibex;
+ if (s.equals("")) return ibex.get(key);
+ if (s.equals("static")) return myStatic;
+ }
return super.get(key);
}
}
public static int stringToColor(String s) {
// FIXME support three-char strings by doubling digits
if (s == null) return 0x00000000;
- else if (standard.get(s) != null) return 0xFF000000 | org.ibex.js.JS.toInt(standard.get(s));
+ else if (standard.get(s) != null) return 0xFF000000 | ((Integer)standard.get(s)).intValue();
else if (s.length() == 7 && s.charAt(0) == '#') try {
// FEATURE alpha
return 0xFF000000 |
/** true iff we have encountered an LI more recently than the last OL/UL */
private static boolean withinLI = false;
+ // FEATURE: This is ugly
+ private static class JS extends org.ibex.js.JS.O {
+ public void put(String key, Object value) throws JSExn {
+ if(value instanceof String) put(JS.S(key),JS.S((String)value));
+ else if(value instanceof Number) put(JS.S(key), JS.N((Number)value));
+ else if(value == null) put(JS.S(key),null);
+ else throw new Error("FIXME");
+ }
+ public Object _get(String key) throws JSExn {
+ org.ibex.js.JS js = get(JS.S(key));
+ if(JS.isInt(js)) return new Integer(JS.toInt(js));
+ return JS.toString(js);
+ }
+ }
+
public static synchronized JS parseReader(Reader r) throws IOException, JSExn {
CharStream cs = new CharStream(r);
- JS h = new JS.O();
+ JS h = new JS();
withinLI = false;
h.put("$name", "html");
*/
private static String parseBody(CharStream cs, JS h, String elementName) throws IOException, JSExn {
String cdata = "";
- int length = h.get("$numchildren") == null ? 0 : Integer.parseInt(h.get("$numchildren").toString());
+ int length = h._get("$numchildren") == null ? 0 : Integer.parseInt(h._get("$numchildren").toString());
while(true) {
String closetag = null;
try {
// scan subelement
if (cs.peek() != '/') {
- JS kid = new JS.O();
+ JS kid = new JS();
closetag = parseElement(cs, kid);
h.put(String.valueOf(length), kid);
h.put("$numchildren", new Integer(++length));
// Static Data ////////////////////////////////////////////////////////////////////////////////
- private static Boolean T = Boolean.TRUE;
- private static Boolean F = Boolean.FALSE;
+ private static final JS T = JS.T;
+ private static final JS F = JS.F;
/** all instances of Surface which need to be refreshed by the Scheduler */
public static Vec allSurfaces = new Vec();
Scheduler.add(new Task() { public void perform() throws JSExn {
Platform.clipboardReadEnabled = true;
try {
- root.putAndTriggerTraps("_Press3", T);
+ root.putAndTriggerTraps(JS.S("_Press3"), T);
} finally {
Platform.clipboardReadEnabled = false;
}
}
}
+ private final static JS MOVE = JS.S("_Move");
/** we enqueue ourselves in the Scheduler when we have a Move message to deal with */
private Task mover = new Task() {
public void perform() {
String oldcursor = cursor; cursor = "default";
// FIXME: Root (ONLY) gets motion events outside itself (if trapped)
if (oldmousex != mousex || oldmousey != mousey)
- root.putAndTriggerTrapsAndCatchExceptions("_Move", T);
+ root.putAndTriggerTrapsAndCatchExceptions(MOVE, T);
if (!cursor.equals(oldcursor)) syncCursor();
} };
Scheduler.add(mover);
}
- protected final void HScroll(int pixels) { new Message("_HScroll", new Integer(pixels), root); }
- protected final void VScroll(int pixels) { new Message("_VScroll", new Integer(pixels), root); }
- protected final void HScroll(float lines) { new Message("_HScroll", new Float(lines), root); }
- protected final void VScroll(float lines) { new Message("_VScroll", new Float(lines), root); }
+ protected final void HScroll(int pixels) { new Message("_HScroll", JS.N(pixels), root); }
+ protected final void VScroll(int pixels) { new Message("_VScroll", JS.N(pixels), root); }
+ protected final void HScroll(float lines) { new Message("_HScroll", JS.N(lines), root); }
+ protected final void VScroll(float lines) { new Message("_VScroll", JS.N(lines), root); }
/** subclasses should invoke this method when the user resizes the window */
protected final void SizeChange(final int width, final int height) {
Scheduler.add(new Task() { public void perform() throws JSExn {
root.x = x;
root.y = y;
- root.putAndTriggerTrapsAndCatchExceptions("PosChange", T);
+ root.putAndTriggerTrapsAndCatchExceptions(JS.S("PosChange"), T);
}});
}
private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" };
protected final void DoubleClick(int button) { new Message(doubleClick[button], T, root); }
- protected final void KeyPressed(String key) { new Message("_KeyPressed", key, root); }
- protected final void KeyReleased(String key) { new Message("_KeyReleased", key, root); }
+ protected final void KeyPressed(String key) { new Message("_KeyPressed", JS.S(key), root); }
+ protected final void KeyReleased(String key) { new Message("_KeyReleased", JS.S(key), root); }
protected final void Close() { new Message("Close", T, root); }
protected final void Minimized(boolean b) { minimized = b; new Message("Minimized", b ? T : F, root); }
protected final void Maximized(boolean b) { maximized = b; new Message("Maximized", b ? T : F, root); }
public class Message implements Task {
private Box boxContainingMouse;
- private Object value;
+ private JS value;
public String name;
- Message(String name, Object value, Box boxContainingMouse) {
+ Message(String name, JS value, Box boxContainingMouse) {
this.boxContainingMouse = boxContainingMouse;
this.name = name;
this.value = value;
Scheduler.add(this);
}
- public void perform() {
+ public void perform() throws JSExn {
if (name.equals("_KeyPressed")) {
- String value = (String)this.value;
+ String value = JS.toString(this.value);
if (value.toLowerCase().endsWith("shift")) shift = true; else if (shift) value = value.toUpperCase();
if (value.toLowerCase().equals("alt")) alt = true; else if (alt) value = "A-" + value;
if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value;
if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true;
- this.value = value;
+ this.value = JS.S(value);
} else if (name.equals("_KeyReleased")) {
- String value = (String)this.value;
+ String value = JS.toString(this.value);
if (value.toLowerCase().equals("alt")) alt = false;
else if (value.toLowerCase().equals("control")) control = false;
else if (value.toLowerCase().equals("shift")) shift = false;
- this.value = value;
+ this.value = JS.S(value);
} else if (name.equals("_HScroll") || name.equals("_VScroll")) {
// FIXME: technically points != pixels
- if (value instanceof Integer)
- value = new Float(((Integer)value).intValue() * root.fontSize());
+ if (JS.isInt(value))
+ value = JS.N(JS.toInt(value) * root.fontSize());
}
try {
- boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(name, value);
+ boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JS.S(name), value);
} finally {
Platform.clipboardReadEnabled = false;
}
if (Log.verbose) Log.info(this, "evaluating PAC script");
String pac = null;
try {
- Object obj = pacFunc.call(url, host, null, null, 2);
- if (Log.verbose) Log.info(this, " PAC script returned \"" + obj + "\"");
- pac = obj.toString();
+ JS obj = pacFunc.call(JS.S(url), JS.S(host), null, null, 2);
+ if (Log.verbose) Log.info(this, " PAC script returned \"" + JS.debugToString(obj) + "\"");
+ pac = JS.toString(obj);
} catch (Throwable e) {
if (Log.on) Log.info(this, "PAC script threw exception " + e);
return null;
return ret;
}
- public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+ public static JSScope proxyAutoConfigRootScope = /*new ProxyAutoConfigRootScope();*/ null; // FIXME: New api
public static JS getProxyAutoConfigFunction(String url) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
JS scr = JS.fromReader("PAC script at " + url, 0, new StringReader(script));
JS.cloneWithNewParentScope(scr, proxyAutoConfigRootScope).call(null, null, null, null, 0);
- return (JS)proxyAutoConfigRootScope.get("FindProxyForURL");
+ return (JS)proxyAutoConfigRootScope.get(JS.S("FindProxyForURL"));
} catch (Exception e) {
if (Log.on) {
Log.info(Platform.class, "WPAD detection failed due to:");
// FIXME
//Template.buildTemplate("org/ibex/builtin/proxy_authorization.ibex", Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")), new Ibex(null));
t.apply(b);
- b.put("realm", realm);
- b.put("proxyIP", proxyIP);
+ b.put(JS.S("realm"), JS.S(realm));
+ b.put(JS.S("proxyIP"), JS.S(proxyIP));
}
});
// ProxyAutoConfigRootJSScope ////////////////////////////////////////////////////////////////////
- public static class ProxyAutoConfigRootScope extends JSScope.Global {
+ // FIXME: JS Update for new API
+ /*public static class ProxyAutoConfigRootScope extends JSScope.Global {
public ProxyAutoConfigRootScope() { super(); }
return false;
}
public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
- }
+ }*/
/**
}
// remove ourselves
- Object me = objects.elementAt(objects.size() - 1);
+ JS me = (JS) objects.elementAt(objects.size() - 1);
// find our parent
Object parent = objects.size() > 1 ? objects.elementAt(objects.size() - 2) : null;
} else if (parent != null && parent instanceof JS) {
objects.removeElementAt(objects.size() - 1);
try {
- ((JS)parent).put(name, me);
+ ((JS)parent).put(JS.S(name), me);
} catch (JSExn e) {
throw new Error("this should never happen");
}
}
/** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
- void appendObject(String name, Object o, StringBuffer sb) throws JSExn {
+ void appendObject(String name, JS o, StringBuffer sb) throws JSExn {
+ // FIXME: Update for new api
+ /*
if (o instanceof Number) {
if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
sb.append(" <" + name + " xsi:type=\"xsd:int\">");
}
sb.append("</" + name + ">\r\n");
- }
+ }*/
}
protected String buildRequest(JSArray args) throws JSExn, IOException {
Enumeration e = ((JS)args.elementAt(0)).keys();
while(e.hasMoreElements()) {
Object key = e.nextElement();
- appendObject((String)key, ((JS)args.elementAt(0)).get(key), content);
+ appendObject((String)key, args.elementAt(0).get((JS)key), content);
}
}
content.append(" </" + method + "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n");
public void endElement(XML.Element c) {
//#switch(c.getLocalName())
- case "int": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
- case "i4": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
- case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
- case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
- case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "int": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
+ case "i4": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
+ case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? JS.T : JS.F, objects.size() - 1);
+ case "string": objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "double": objects.setElementAt(JS.N(Double.parseDouble(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
case "base64":
objects.setElementAt(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
null), objects.size() - 1);
- case "name": objects.addElement(new String(content.getBuf(), 0, content.size()));
+ case "name": objects.addElement(JS.S(new String(content.getBuf(), 0, content.size())));
case "value": if ("".equals(objects.lastElement()))
- objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
+ objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
case "dateTime.iso8601":
String s = new String(content.getBuf(), 0, content.size());
"the server sent a <dateTime.iso8601> tag which was malformed: " + s);
}
case "member":
- Object memberValue = objects.elementAt(objects.size() - 1);
+ JS memberValue = (JS) objects.elementAt(objects.size() - 1);
String memberName = (String)objects.elementAt(objects.size() - 2);
JS struct = (JS)objects.elementAt(objects.size() - 3);
try {
- struct.put(memberName, memberValue);
+ struct.put(JS.S(memberName), memberValue);
} catch (JSExn e) {
throw new Error("this should never happen");
}
for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
JSArray arr = new JSArray();
try {
- for(int j = i + 1; j<objects.size(); j++) arr.put(new Integer(j - i - 1), objects.elementAt(j));
+ for(int j = i + 1; j<objects.size(); j++) arr.put(JS.N(j - i - 1), (JS)objects.elementAt(j));
} catch (JSExn e) {
throw new Error("this should never happen");
}
}
/** Appends the XML-RPC representation of <code>o</code> to <code>sb</code> */
- void appendObject(Object o, StringBuffer sb) throws JSExn {
-
- if (o == null) {
+ void appendObject(JS o, StringBuffer sb) throws JSExn {
+ // FIXME: Update for new api
+ throw new Error("FIXME");
+ /*if (o == null) {
throw new JSExn("attempted to send a null value via XML-RPC");
} else if (o instanceof Number) {
} else {
throw new JSExn("attempt to send object of type " + o.getClass().getName() + " via XML-RPC");
- }
+ }*/
}
// Call Sequence //////////////////////////////////////////////////////////////////////////
- public final Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+ public final JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
JSArray args = new JSArray();
for(int i=0; i<nargs; i++) args.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
return call(args);
}
- public final Object call(final JSArray args) throws JSExn {
+ public final JS call(final JSArray args) throws JSExn {
try {
final JS.UnpauseCallback callback = JS.pause();
new java.lang.Thread() { public void run() { call(callback, args); } }.start();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
new Helper().parse(br);
- final Object result = fault ? new JSExn(objects.elementAt(0)) : objects.size() == 0 ? null : objects.elementAt(0);
- Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(result); }});
+ final JSExn exn = fault ? new JSExn(objects.elementAt(0).toString()) : null;
+ final JS result = fault ? null : objects.size() == 0 ? null : (JS) objects.elementAt(0);
+ Scheduler.add(new Task() { public void perform() throws JSExn { if(fault) callback.unpause(exn); else callback.unpause(result); }});
} finally {
tracker.clear();
objects.setSize(0);
}
} catch (final JSExn e) {
- final Exception e2 = e;
- Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(e2); }});
+ Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(e); }});
} catch (final IOException e) {
final Exception e2 = e;
- Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+ Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.toString())); }});
} catch (final XML.Exn e) {
final Exception e2 = e;
- Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+ Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.toString())); }});
}
}
}
ret.Refresh();
}
try {
- if (b.get("titlebar") != null) ret.setTitleBarText((String)b.get("titlebar"));
+ if (b.get(JS.S("titlebar")) != null) ret.setTitleBarText(JS.toString(b.get(JS.S("titlebar"))));
} catch (JSExn e) {
Log.warn(Platform.class, e);
}
public JS action = null;
+ // FIXME: Updae for new api
+
// means we call()ed a Grammar that hasn't been bound to a scope yet
- public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+ /*public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
throw new Error("this should never happen");
}
public int match(String s, int start, Hash v, JSScope scope) throws JSExn {
return ((Grammar)scope.get(key)).matchAndWrite(s, start, v, scope, key);
}
- }
+ }*/
}
logstream.println(classname + colorize(levelcolor, bright, str));
}
- public static void recursiveLog(String indent, String name, Object o) throws JSExn {
+ // FIXME: Update for new api
+ /*public static void recursiveLog(String indent, String name, Object o) throws JSExn {
if (!name.equals("")) name += " : ";
if (o == null) {
JS.log(indent + name + o);
}
- }
+ }*/
}
private PrintWriter out;
private Hashtable replace = new Hashtable();
- private Hashtable repeatreplace = null;
+ private Hashtable[] repeatreplaces = null;
private Vector sinceLastRepeat = null;
private Vector err = new Vector();
out.print("\n"); // preserve line numbers
}
StringTokenizer st = new StringTokenizer(trimmed, " ");
- repeatreplace = (Hashtable)replace.clone();
+ repeatreplaces = null;
while (st.hasMoreTokens()) {
String tok = st.nextToken().trim();
String key = tok.substring(0, tok.indexOf('/'));
- String val = tok.substring(tok.indexOf('/') + 1);
- repeatreplace.put(key, val);
+ String vals = tok.substring(tok.indexOf('/') + 1);
+ StringTokenizer st2 = new StringTokenizer(vals,"/");
+ if(repeatreplaces == null) {
+ repeatreplaces = new Hashtable[st2.countTokens()];
+ for(int i=0;i<repeatreplaces.length;i++) repeatreplaces[i] = (Hashtable) replace.clone();
+ }
+ for(int i=0;st2.hasMoreTokens() && i<repeatreplaces.length;i++)
+ repeatreplaces[i].put(key, st2.nextToken());
}
sinceLastRepeat = new Vector();
out.print("\n"); // preserve line numbers
} else if (trimmed.startsWith("//#end")) {
if (sinceLastRepeat == null) { err.add(new Warning("#end orphaned")); continue PROCESS; }
Hashtable save = replace;
- replace = repeatreplace;
out.print("\n");
- for(int i=0; i<sinceLastRepeat.size() - 1; i++) out.print(processLine((String)sinceLastRepeat.elementAt(i), true));
+ for(int i=0;i<repeatreplaces.length;i++) {
+ replace = repeatreplaces[i];
+ for(int j=0; j<sinceLastRepeat.size() - 1; j++) out.print(processLine((String)sinceLastRepeat.elementAt(j), true));
+ }
sinceLastRepeat = null;
replace = save;
buildTrie("", byLength[i]);
out.print("}; break; } ");
}
- out.print("} /* switch */ ");
+ out.print("} "); /* switch */
if (Default != null) out.print(" " + Default);
- out.print(" } while(false); /* OUTER */\n");
+ out.print(" } while(false);\n"); /* OUTER */
enumSwitch++;
} else {