2003/12/22 04:50:08
[org.ibex.core.git] / src / org / xwt / Template.java
index a95ec38..af84178 100644 (file)
@@ -6,6 +6,7 @@ import java.util.zip.*;
 import java.util.*;
 import java.lang.*;
 import org.xwt.js.*;
+import org.xwt.translators.*;
 import org.xwt.util.*;
 
 /**
@@ -106,8 +107,20 @@ 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) throws JSExn { apply(b, xwt, null); }
-    void apply(Box b, XWT xwt, PerInstantiationJSScope parentPis) throws JSExn {
+    void apply(Box b, XWT xwt) {
+        try {
+            apply(b, xwt, null);
+        } catch (JSExn e) {
+            b.clear(b.VISIBLE);
+            b.mark_for_repack();
+            Log.log(Template.class, "WARNING: exception (below) thrown during application of template;");
+            Log.log(Template.class, "         setting visibility of target box to \"false\"");
+            Log.logJS(e);
+        }
+    }
+
+
+    private void apply(Box b, XWT xwt, PerInstantiationJSScope parentPis) throws JSExn {
 
         getStatic();
 
@@ -133,7 +146,9 @@ public class Template {
                 if (rbox == null) Log.log(this, "unknown box id '"+vals[i]+"' referenced in XML attribute");
                 else b.putAndTriggerTraps(keys[i], rbox);
             }
-            else if ("image".equals(keys[i])) b.putAndTriggerTraps("image", resolveStringToResource((String)vals[i], xwt, true));
+            else if ("fill".equals(keys[i]) && ((String)vals[i]).indexOf('.') >= 0) {
+                b.putAndTriggerTraps("fill", 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]);
@@ -223,8 +238,10 @@ public class Template {
             // WARNING: c.keys.length != c.len; USE c.len
             for(int i=0; i<c.len; i++) {
                 if (c.keys[i] == null) throw new RuntimeException("XML parser returned a null key position="+i);
-                if (c.keys[i].equals("font") && c.uris[i] != null) c.vals[i] = c.uris[i] + "." + c.vals[i];
-                if (c.keys[i].equals("preapply")) {
+                else if (c.keys[i].equals("font") && c.uris[i] != null) c.vals[i] = c.uris[i] + "." + c.vals[i];
+                else if (c.keys[i].equals("fill") && c.uris[i] != null && !c.vals[i].startsWith("#")
+                        && SVG.colors.get(c.vals[i]) == null) c.vals[i] = c.uris[i] + "." + c.vals[i];
+                else if (c.keys[i].equals("preapply")) {
                     // process preapply and 'remove' from array
                     String uri = c.uris[i] == null ? "" : c.uris[i] + '.';
                     StringTokenizer tok = new StringTokenizer(c.vals[i].toString(), " ");
@@ -362,7 +379,7 @@ public class Template {
         public Object get(Object key) throws JSExn {
             if (super.has(key)) return super.get(key);
             if (key.equals("xwt")) return xwt;
-            if (key.equals("_")) return xwt.rr;
+            if (key.equals("")) return xwt.rr;
             if (key.equals("static")) return myStatic;
             return super.get(key);
         }