// XML Parsing /////////////////////////////////////////////////////////////////
- public static Template buildTemplate(String sourceName, InputStream is, Ibex ibex) {
+ public static Template buildTemplate(String sourceName, Object s, Ibex ibex) {
try {
- return new TemplateHelper(sourceName, is, ibex).t;
+ return new TemplateHelper(sourceName, s, ibex).t;
} catch (Exception e) {
Log.error(Template.class, e);
return null;
int meta = 0;
Ibex ibex;
- public TemplateHelper(String sourceName, InputStream is, Ibex ibex) throws XML.Exn, IOException, JSExn {
+ String initial_uri = "";
+
+ public TemplateHelper(String sourceName, Object s, Ibex ibex) throws XML.Exn, IOException, JSExn {
this.sourceName = sourceName;
this.ibex = ibex;
+ InputStream is = Stream.getInputStream(s);
+ Ibex.Blessing b = Ibex.Blessing.getBlessing(s).parent;
+ while(b != null) {
+ initial_uri = (b.parentkey == null ? "" : (b.parentkey + ".")) + initial_uri;
+ b = b.parent;
+ }
parse(new InputStreamReader(is));
JS staticScript = parseScript(static_content, static_content_start);
t.staticScope = new PerInstantiationScope(null, ibex, null, null);
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());
+ if (c.getUri("ui") == null || "".equals(c.getUri("ui"))) c.addUri("ui", "ibex://ui");
+ if (c.getUri("") == null || "".equals(c.getUri(""))) c.addUri("", initial_uri);
state = STATE_IN_ROOT_NODE;
return;
case STATE_IN_ROOT_NODE:
- if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; }
+ if ("ibex://meta".equals(c.getUri())) { state = STATE_IN_META_NODE; meta = 0; return; }
state = STATE_IN_TEMPLATE_NODE;
t = (t == null) ? new Template(ibex) : new Template(t, getLine());
break;
break;
}
- if (!(/* "ui".equals(c.getPrefix()) && */ "box".equals(c.getLocalName()))) {
+ if (!("ibex://ui".equals(c.getUri()) && "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);
}
}
Hash urimap = c.getUriMap();
- t.urikeys = new String[urimap.size()];
- t.urivals = new String[urimap.size()];
+ t.urikeys = new String[urimap.size() - (urimap.get("ui") == null ? 0 : 1)];
+ t.urivals = new String[urimap.size() - (urimap.get("ui") == null ? 0 : 1)];
Enumeration uriEnumeration = urimap.keys();
int ii = 0;
while(uriEnumeration.hasMoreElements()) {
String key = (String)uriEnumeration.nextElement();
+ if (key.equals("ui")) continue;
String val = (String)urimap.get(key);
t.urikeys[ii] = key;
- if (val.charAt(0) == '.') val = val.substring(1);
+ if (val.length() > 0 && val.charAt(0) == '.') val = val.substring(1);
t.urivals[ii] = val;
ii++;
}
public void endElement(XML.Element c) throws XML.Exn, IOException {
switch(state) {
- case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_ROOT_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; }