fixed bug 440
[org.ibex.core.git] / src / org / ibex / Template.java
index ec47e7c..aa190b3 100644 (file)
@@ -32,7 +32,7 @@ public class Template {
     private Vec children = new Vec();   ///< during XML parsing, this holds the list of currently-parsed children; null otherwise
     private JS script = null;           ///< the script on this node
     Template prev;
-    JSScope staticScope = null;   ///< the scope in which the static block is executed
+    JSScope staticScope = null;         ///< the scope in which the static block is executed
 
 
     // Only used during parsing /////////////////////////////////////////////////////////////////
@@ -138,7 +138,7 @@ public class Template {
        String sourceName;
         private int state = STATE_INITIAL;
         private static final int STATE_INITIAL = 0;
-        private static final int STATE_IN_Ibex_NODE = 1;
+        private static final int STATE_IN_ROOT_NODE = 1;
         private static final int STATE_IN_TEMPLATE_NODE = 2; 
         private static final int STATE_IN_META_NODE = 3;
 
@@ -173,9 +173,9 @@ public class Template {
                         throw new XML.Exn("root element was not <ibex>", XML.Exn.SCHEMA, getLine(), getCol());
                     if (c.getAttrLen() != 0)
                         throw new XML.Exn("root element must not have attributes", XML.Exn.SCHEMA, getLine(), getCol());
-                    state = STATE_IN_Ibex_NODE;
+                    state = STATE_IN_ROOT_NODE;
                     return;
-                case STATE_IN_Ibex_NODE:
+                case STATE_IN_ROOT_NODE:
                     if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; }
                     state = STATE_IN_TEMPLATE_NODE;
                     t = (t == null) ? new Template(ibex) : new Template(t, getLine());
@@ -186,11 +186,12 @@ public class Template {
                     break;
             }
 
-            if (!("ui".equals(c.getPrefix()) && "box".equals(c.getLocalName()))) {
+            if (!(/* "ui".equals(c.getPrefix()) && */ "box".equals(c.getLocalName()))) {
                 String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName();
                 // GROSS hack
                 try {
                     t.prev = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+                    if (t.prev == null) throw new JSExn("template " + tagname + " not found");
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
@@ -267,11 +268,11 @@ public class Template {
 
         public void endElement(XML.Element c) throws XML.Exn, IOException {
             switch(state) {
-                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_Ibex_NODE; return;
-                case STATE_IN_Ibex_NODE: return;
+                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_ROOT_NODE; return;
+                case STATE_IN_ROOT_NODE: return;
                 case STATE_IN_TEMPLATE_NODE: {
                     if (t.content != null) { t.script = parseScript(t.content, t.content_start); t.content = null; }
-                    if (nodeStack.size() == 0) { state = STATE_IN_Ibex_NODE; return; }
+                    if (nodeStack.size() == 0) { state = STATE_IN_ROOT_NODE; return; }
                     Template oldt = t;
                     t = (Template)nodeStack.lastElement();
                     nodeStack.setSize(nodeStack.size() - 1);
@@ -293,7 +294,7 @@ public class Template {
                     }
                     t.content.append(ch, start, length);
                     return;
-                case STATE_IN_Ibex_NODE:
+                case STATE_IN_ROOT_NODE:
                     if (static_content == null) {
                         static_content_start = getLine();
                         static_content = new StringBuffer();