mass rename and rebranding from xwt to ibex - fixed to use ixt files
[org.ibex.core.git] / src / org / ibex / Template.java
similarity index 87%
rename from src/org/xwt/Template.java
rename to src/org/ibex/Template.java
index 2cc6242..00e580a 100644 (file)
@@ -1,17 +1,14 @@
 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
+package org.ibex;
 
 import java.io.*;
 
 import java.io.*;
-import java.util.zip.*;
 import java.util.*;
 import java.util.*;
-import java.lang.*;
-import org.xwt.js.*;
-import org.xwt.translators.*;
-import org.xwt.util.*;
+import org.ibex.js.*;
+import org.ibex.util.*;
 
 /**
  *  Encapsulates a template node (the <template/> element of a
 
 /**
  *  Encapsulates a template node (the <template/> element of a
- *  .xwt file, or any child element thereof).
+ *  .ibex file, or any child element thereof).
  *
  *  Note that the Template instance corresponding to the
  *  <template/> node carries all the header information -- hence
  *
  *  Note that the Template instance corresponding to the
  *  <template/> node carries all the header information -- hence
@@ -19,7 +16,7 @@ import org.xwt.util.*;
  *  Template instances. We refer to these non-root instances as
  *  <i>anonymous templates</i>.
  *
  *  Template instances. We refer to these non-root instances as
  *  <i>anonymous templates</i>.
  *
- *  See the XWT reference for information on the order in which
+ *  See the Ibex reference for information on the order in which
  *  templates are applied, attributes are put, and scripts are run.
  */
 public class Template {
  *  templates are applied, attributes are put, and scripts are run.
  */
 public class Template {
@@ -43,14 +40,14 @@ public class Template {
     private StringBuffer content = null;   ///< during XML parsing, this holds partially-read character data; null otherwise
     private int content_start = 0;         ///< line number of the first line of <tt>content</tt>
     private int startLine = -1;            ///< the line number that this element starts on
     private StringBuffer content = null;   ///< during XML parsing, this holds partially-read character data; null otherwise
     private int content_start = 0;         ///< line number of the first line of <tt>content</tt>
     private int startLine = -1;            ///< the line number that this element starts on
-    private XWT xwt;
+    private Ibex ibex;
 
 
     // Static data/methods ///////////////////////////////////////////////////////////////////
 
     // for non-root nodes
 
 
     // Static data/methods ///////////////////////////////////////////////////////////////////
 
     // for non-root nodes
-    private Template(Template t, int startLine) { prev = t; this.xwt = t.xwt; this.startLine = startLine; }
-    private Template(XWT xwt) { this.xwt = xwt; }
+    private Template(Template t, int startLine) { prev = t; this.ibex = t.ibex; this.startLine = startLine; }
+    private Template(Ibex ibex) { this.ibex = ibex; }
     
 
     // Methods to apply templates ////////////////////////////////////////////////////////
     
 
     // Methods to apply templates ////////////////////////////////////////////////////////
@@ -82,10 +79,10 @@ public class Template {
         // FIXME this dollar stuff is all wrong
         if (id != null) parentPis.putDollar(id, b);
 
         // FIXME this dollar stuff is all wrong
         if (id != null) parentPis.putDollar(id, b);
 
-        PerInstantiationScope pis = new PerInstantiationScope(b, xwt, parentPis, staticScope);
+        PerInstantiationScope pis = new PerInstantiationScope(b, ibex, parentPis, staticScope);
         for(int i=0; i<urikeys.length; i++) {
             pis.declare(urikeys[i]);
         for(int i=0; i<urikeys.length; i++) {
             pis.declare(urikeys[i]);
-            pis.put(urikeys[i], xwt.resolveString(urivals[i], true));
+            pis.put(urikeys[i], ibex.resolveString(urivals[i], true));
         }
 
         // FIXME needs to obey the new application-ordering rules
         }
 
         // FIXME needs to obey the new application-ordering rules
@@ -112,7 +109,7 @@ public class Template {
                         if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute");
                         break;
                     case '.':
                         if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute");
                         break;
                     case '.':
-                        val = xwt.resolveString(((String)val).substring(1), false);
+                        val = ibex.resolveString(((String)val).substring(1), false);
                     // FIXME: url case
                     // FIXME: should we be resolving all of these in the XML-parsing code?
                 }
                     // FIXME: url case
                     // FIXME: should we be resolving all of these in the XML-parsing code?
                 }
@@ -126,9 +123,9 @@ public class Template {
 
     // XML Parsing /////////////////////////////////////////////////////////////////
 
 
     // XML Parsing /////////////////////////////////////////////////////////////////
 
-    public static Template buildTemplate(InputStream is, XWT xwt) {
+    public static Template buildTemplate(InputStream is, Ibex ibex) {
         try {
         try {
-            return new TemplateHelper(is, xwt).t;
+            return new TemplateHelper(is, ibex).t;
         } catch (Exception e) {
             Log.error(Template.class, e);
             return null;
         } catch (Exception e) {
             Log.error(Template.class, e);
             return null;
@@ -140,7 +137,7 @@ public class Template {
 
         private int state = STATE_INITIAL;
         private static final int STATE_INITIAL = 0;
 
         private int state = STATE_INITIAL;
         private static final int STATE_INITIAL = 0;
-        private static final int STATE_IN_XWT_NODE = 1;
+        private static final int STATE_IN_Ibex_NODE = 1;
         private static final int STATE_IN_TEMPLATE_NODE = 2; 
         private static final int STATE_IN_META_NODE = 3;
 
         private static final int STATE_IN_TEMPLATE_NODE = 2; 
         private static final int STATE_IN_META_NODE = 3;
 
@@ -149,13 +146,13 @@ public class Template {
         Vec nodeStack = new Vec();
         Template t = null;
         int meta = 0;
         Vec nodeStack = new Vec();
         Template t = null;
         int meta = 0;
-        XWT xwt;
+        Ibex ibex;
 
 
-        public TemplateHelper(InputStream is, XWT xwt) throws XML.Exn, IOException, JSExn {
-            this.xwt = xwt;
+        public TemplateHelper(InputStream is, Ibex ibex) throws XML.Exn, IOException, JSExn {
+            this.ibex = ibex;
             parse(new InputStreamReader(is));
             JS staticScript = parseScript(static_content, static_content_start);
             parse(new InputStreamReader(is));
             JS staticScript = parseScript(static_content, static_content_start);
-            t.staticScope = new PerInstantiationScope(null, xwt, null, null);
+            t.staticScope = new PerInstantiationScope(null, ibex, null, null);
             if (staticScript != null) JS.cloneWithNewParentScope(staticScript, t.staticScope).call(null, null, null, null, 0);
         }
 
             if (staticScript != null) JS.cloneWithNewParentScope(staticScript, t.staticScope).call(null, null, null, null, 0);
         }
 
@@ -174,16 +171,16 @@ 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());
                         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_XWT_NODE;
+                    state = STATE_IN_Ibex_NODE;
                     return;
                     return;
-                case STATE_IN_XWT_NODE:
+                case STATE_IN_Ibex_NODE:
                     if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; }
                     state = STATE_IN_TEMPLATE_NODE;
                     if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; }
                     state = STATE_IN_TEMPLATE_NODE;
-                    t = (t == null) ? new Template(xwt) : new Template(t, getLine());
+                    t = (t == null) ? new Template(ibex) : new Template(t, getLine());
                     break;
                 case STATE_IN_TEMPLATE_NODE:
                     nodeStack.addElement(t);
                     break;
                 case STATE_IN_TEMPLATE_NODE:
                     nodeStack.addElement(t);
-                    t = new Template(xwt);
+                    t = new Template(ibex);
                     break;
             }
 
                     break;
             }
 
@@ -191,7 +188,7 @@ public class Template {
                 String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName();
                 // GROSS hack
                 try {
                 String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName();
                 // GROSS hack
                 try {
-                    t.prev = (Template)t.xwt.resolveString(tagname, false).call(null, null, null, null, 9999);
+                    t.prev = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
@@ -268,11 +265,11 @@ public class Template {
 
         public void endElement(XML.Element c) throws XML.Exn, IOException {
             switch(state) {
 
         public void endElement(XML.Element c) throws XML.Exn, IOException {
             switch(state) {
-                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_XWT_NODE; return;
-                case STATE_IN_XWT_NODE: return;
+                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_Ibex_NODE; return;
+                case STATE_IN_Ibex_NODE: return;
                 case STATE_IN_TEMPLATE_NODE: {
                     if (t.content != null) { t.script = parseScript(t.content, t.content_start); t.content = null; }
                 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_XWT_NODE; return; }
+                    if (nodeStack.size() == 0) { state = STATE_IN_Ibex_NODE; return; }
                     Template oldt = t;
                     t = (Template)nodeStack.lastElement();
                     nodeStack.setSize(nodeStack.size() - 1);
                     Template oldt = t;
                     t = (Template)nodeStack.lastElement();
                     nodeStack.setSize(nodeStack.size() - 1);
@@ -285,7 +282,7 @@ public class Template {
 
         public void characters(char[] ch, int start, int length) throws XML.Exn {
             for (int i=0; length >i; i++) if (ch[start+i] == '\t')
 
         public void characters(char[] ch, int start, int length) throws XML.Exn {
             for (int i=0; length >i; i++) if (ch[start+i] == '\t')
-                Log.error(Template.class, "tabs are not allowed in XWT files ("+getLine()+":"+getCol()+")");
+                Log.error(Template.class, "tabs are not allowed in Ibex files ("+getLine()+":"+getCol()+")");
             switch(state) {
                 case STATE_IN_TEMPLATE_NODE:
                     if (t.content == null) {
             switch(state) {
                 case STATE_IN_TEMPLATE_NODE:
                     if (t.content == null) {
@@ -294,7 +291,7 @@ public class Template {
                     }
                     t.content.append(ch, start, length);
                     return;
                     }
                     t.content.append(ch, start, length);
                     return;
-                case STATE_IN_XWT_NODE:
+                case STATE_IN_Ibex_NODE:
                     if (static_content == null) {
                         static_content_start = getLine();
                         static_content = new StringBuffer();
                     if (static_content == null) {
                         static_content_start = getLine();
                         static_content = new StringBuffer();
@@ -308,7 +305,7 @@ public class Template {
     }
 
     private static class PerInstantiationScope extends JSScope {
     }
 
     private static class PerInstantiationScope extends JSScope {
-        XWT xwt = null;
+        Ibex ibex = null;
         PerInstantiationScope parentBoxPis = null;
         JSScope myStatic = null;
         void putDollar(String key, Box target) throws JSExn {
         PerInstantiationScope parentBoxPis = null;
         JSScope myStatic = null;
         void putDollar(String key, Box target) throws JSExn {
@@ -316,16 +313,16 @@ public class Template {
             declare("$" + key);
             put("$" + key, target);
         }
             declare("$" + key);
             put("$" + key, target);
         }
-        public PerInstantiationScope(JSScope parentScope, XWT xwt, PerInstantiationScope parentBoxPis, JSScope myStatic) {
+        public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JSScope myStatic) {
             super(parentScope);
             this.parentBoxPis = parentBoxPis;
             super(parentScope);
             this.parentBoxPis = parentBoxPis;
-            this.xwt = xwt;
+            this.ibex = ibex;
             this.myStatic = myStatic;
         }
         public Object get(Object key) throws JSExn {
             if (super.has(key)) return super.get(key);
             this.myStatic = myStatic;
         }
         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.get("");
+            if (key.equals("ibex")) return ibex;
+            if (key.equals("")) return ibex.get("");
             if (key.equals("static")) return myStatic;
             return super.get(key);
         }
             if (key.equals("static")) return myStatic;
             return super.get(key);
         }