2003/11/29 03:06:09
[org.ibex.core.git] / src / org / xwt / Template.java
index 2921cde..4cbf5e4 100644 (file)
@@ -70,7 +70,11 @@ public class Template {
     public static Res resolveStringToResource(String str, XWT xwt, boolean permitAbsolute) {
         // URL
         if (str.indexOf("://") != -1) {
-            if (permitAbsolute) return (Res)xwt.callMethod("res.url", str, null, null, null, 1);
+            try {
+                if (permitAbsolute) return (Res)xwt.callMethod("res.url", str, null, null, null, 1);
+            } catch (JSExn jse) {
+                throw new Error("this should never happen");
+            }
             Log.log(Template.class, "absolute URL " + str + " not permitted here");
             return null;
         }
@@ -102,7 +106,11 @@ public class Template {
         if (staticscript == null) return staticJSScope;
         JSFunction temp = staticscript;
         staticscript = null;
-        temp.cloneWithNewParentScope(staticJSScope).call(null, null, null, null, 0);
+        try {
+            temp.cloneWithNewParentScope(staticJSScope).call(null, null, null, null, 0);
+        } catch (JSExn jse) {
+            throw new Error("this should never happen");
+        }
         return staticJSScope;
     }
     
@@ -110,8 +118,8 @@ public class Template {
      *  @param pboxes a vector of all box parents on which to put $-references
      *  @param ptemplates a vector of the fileNames to recieve private references on the pboxes
      */
-    void apply(Box b, XWT xwt) { apply(b, xwt, null); }
-    void apply(Box b, XWT xwt, PerInstantiationJSScope parentPis) {
+    void apply(Box b, XWT xwt) throws JSExn { apply(b, xwt, null); }
+    void apply(Box b, XWT xwt, PerInstantiationJSScope parentPis) throws JSExn {
 
         getStatic();
 
@@ -126,14 +134,24 @@ public class Template {
         for (int i=0; children != null && i<children.size(); i++) {
             Box kid = new Box();
             ((Template)children.elementAt(i)).apply(kid, xwt, pis);
-            b.putAndTriggerTraps(JS.N(b.numchildren), kid);
+            b.putAndTriggerTraps(JS.N(b.treeSize()), kid);
         }
 
         if (script != null) script.cloneWithNewParentScope(pis).call(null, null, null, null, 0);
 
         for(int i=0; keys != null && i<keys.length; i++)
-            if (vals[i] instanceof String && ((String)vals[i]).charAt(0) == '$') b.putAndTriggerTraps(keys[i], pis.get(vals[i]));
+            if (vals[i] instanceof String && ((String)vals[i]).charAt(0) == '$') {
+                Object rbox = pis.get(vals[i]);
+                if (rbox == null) Log.log(this, "unknown box id '"+vals[i]+"' referenced");
+                else b.putAndTriggerTraps(keys[i], rbox);
+            }
             else if ("image".equals(keys[i])) b.putAndTriggerTraps("image", resolveStringToResource((String)vals[i], xwt, true));
+            else if ("redirect".equals(keys[i])) {
+                if (vals[i] == null || "null".equals(vals[i])) b.putAndTriggerTraps("redirect", null);
+                Object rbox = pis.get("$"+vals[i]);
+                if (rbox == null) Log.log(this, "redirect target '"+vals[i]+"' not found");
+                else b.putAndTriggerTraps("redirect", rbox);
+            }
             else if (keys[i] != null) b.putAndTriggerTraps(keys[i], vals[i]);
     }
 
@@ -347,7 +365,7 @@ public class Template {
         XWT xwt = null;
         PerInstantiationJSScope parentBoxPis = null;
         JSScope myStatic = null;
-        void putDollar(String key, Box target) {
+        void putDollar(String key, Box target) throws JSExn {
             if (parentBoxPis != null) parentBoxPis.putDollar(key, target);
             declare("$" + key);
             put("$" + key, target);
@@ -358,13 +376,13 @@ public class Template {
             this.xwt = xwt;
             this.myStatic = myStatic;
         }
-        public Object get(Object key) {
+        public Object get(Object key) throws JSExn {
             if (super.has(key)) return super.get(key);
             if (key.equals("xwt")) return xwt;
             if (key.equals("static")) return myStatic;
             return super.get(key);
         }
-        public void put(Object key, Object val) {
+        public void put(Object key, Object val) throws JSExn {
             if (super.has(key)) super.put(key, val);
             else super.put(key, val);
         }