2003/11/16 02:40:43
[org.ibex.core.git] / src / org / xwt / Template.java
index 6956027..c45134c 100644 (file)
@@ -62,7 +62,7 @@ public class Template {
             new TemplateHelper().parseit(r.getInputStream(), r.t);
             return r.t;
         } catch (Exception e) {
-            if (Log.on) Log.log(r.t.fileName, e);
+            if (Log.on) Log.log(r.t == null ? "null" : r.t.fileName, e);
             return null;
         }
     }
@@ -97,7 +97,7 @@ public class Template {
         if (staticscript == null) return staticJSScope;
         JSFunction temp = staticscript;
         staticscript = null;
-        JSContext.invoke(temp.cloneWithNewParentJSSCope(staticJSScope));
+        temp.cloneWithNewParentJSScope(staticJSScope).call(new JSArray());
         return staticJSScope;
     }
     
@@ -121,15 +121,15 @@ public class Template {
         for (int i=0; children != null && i<children.size(); i++) {
             Box kid = new BoxTree();
             ((Template)children.elementAt(i)).apply(kid, xwt, pis);
-            b.putAndTriggerTraps(b.numChildren(), kid);
+            b.putAndTriggerJSTraps(JSObj.N(b.numchildren), kid);
         }
 
-        if (script != null) JSContext.invoke(script.cloneWithNewParentJSScope(pis));
+        if (script != null) script.cloneWithNewParentJSScope(pis).call(new JSArray());
 
         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]));
-            else if ("image".equals(keys[i])) b.putAndTriggerTraps("image", resolveStringToResource((String)vals[i], xwt, true));
-            else if (keys[i] != null) b.putAndTriggerTraps(keys[i], vals[i]);
+            if (vals[i] instanceof String && ((String)vals[i]).charAt(0) == '$') b.putAndTriggerJSTraps(keys[i], pis.get(vals[i]));
+            else if ("image".equals(keys[i])) b.putAndTriggerJSTraps("image", resolveStringToResource((String)vals[i], xwt, true));
+            else if (keys[i] != null) b.putAndTriggerJSTraps(keys[i], vals[i]);
     }
 
 
@@ -280,7 +280,9 @@ public class Template {
         private JSFunction parseScript(boolean isstatic) {
             JSFunction thisscript = null;
             try {
-                thisscript = JS.parse(t.fileName + (isstatic ? "._" : ""), t.content_start, new StringReader(t.content.toString()));
+                String contentString = t.content.toString();
+                if (contentString.trim().length() > 0)
+                    thisscript = JS.parse(t.fileName + (isstatic ? "._" : ""), t.content_start, new StringReader(contentString));
             } catch (IOException ioe) {
                 if (Log.on) Log.log(this, "  ERROR: " + ioe.getMessage());
                 thisscript = null;