X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FTemplate.java;h=ed91cd3e572ce46341563178c803a013fe09beff;hb=07f137d5694c7d52a6a2c28e051546232b353f5d;hp=edd93342a2d11ac4330fe064a1c41317b0c51dfb;hpb=2994937ce9c79076df13f1ed2d0601f81b72c06e;p=org.ibex.core.git diff --git a/src/org/ibex/Template.java b/src/org/ibex/Template.java index edd9334..ed91cd3 100644 --- a/src/org/ibex/Template.java +++ b/src/org/ibex/Template.java @@ -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 ///////////////////////////////////////////////////////////////// @@ -123,9 +123,9 @@ public class Template { // XML Parsing ///////////////////////////////////////////////////////////////// - public static Template buildTemplate(InputStream is, Ibex ibex) { + public static Template buildTemplate(String sourceName, Object s, Ibex ibex) { try { - return new TemplateHelper(is, ibex).t; + return new TemplateHelper(sourceName, s, ibex).t; } catch (Exception e) { Log.error(Template.class, e); return null; @@ -135,9 +135,10 @@ public class Template { /** handles XML parsing; builds a Template tree as it goes */ static final class TemplateHelper extends XML { + 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; @@ -148,8 +149,17 @@ public class Template { int meta = 0; Ibex ibex; - public TemplateHelper(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); @@ -159,7 +169,7 @@ public class Template { private JS parseScript(StringBuffer content, int content_start) throws IOException { if (content == null) return null; String contentString = content.toString(); - if (contentString.trim().length() > 0) return JS.fromReader("FIXME", content_start, new StringReader(contentString)); + if (contentString.trim().length() > 0) return JS.fromReader(sourceName, content_start, new StringReader(contentString)); return null; } @@ -171,10 +181,12 @@ public class Template { throw new XML.Exn("root element was not ", 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; + if (c.getUri("ui") == null) c.addUri("ui", "ibex://ui"); + if (c.getUri("") == null) c.addUri("", initial_uri); + state = STATE_IN_ROOT_NODE; return; - case STATE_IN_Ibex_NODE: - if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; } + case STATE_IN_ROOT_NODE: + 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; @@ -184,7 +196,7 @@ public class Template { 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 { @@ -265,11 +277,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); @@ -291,7 +303,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();