// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
+package org.ibex;
import java.io.*;
-import java.util.zip.*;
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
- * .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
* 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 {
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
- 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 ////////////////////////////////////////////////////////
// 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]);
- 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
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?
}
// XML Parsing /////////////////////////////////////////////////////////////////
- public static Template buildTemplate(InputStream is, XWT xwt) {
+ public static Template buildTemplate(InputStream is, Ibex ibex) {
try {
- return new TemplateHelper(is, xwt).t;
+ return new TemplateHelper(is, ibex).t;
} catch (Exception e) {
Log.error(Template.class, e);
return null;
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;
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);
- 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);
}
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;
- 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;
- 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);
- t = new Template(xwt);
+ t = new Template(ibex);
break;
}
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);
}
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; }
- 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);
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) {
}
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();
}
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 {
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;
- this.xwt = xwt;
+ this.ibex = ibex;
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);
}