X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FTemplate.java;h=2f3e2acef89baddfa7cbe2619bb22bcead772540;hb=b1568b13f53ca805911fcd7737daf79492d6be1f;hp=00e580a707a1f5515e05ae02606b8e9dce977992;hpb=3591b88b94a6bb378af3d4abe6eb5233ce583104;p=org.ibex.core.git diff --git a/src/org/ibex/Template.java b/src/org/ibex/Template.java index 00e580a..2f3e2ac 100644 --- a/src/org/ibex/Template.java +++ b/src/org/ibex/Template.java @@ -32,7 +32,9 @@ 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 + Template prev2; + JSScope staticScope = null; ///< the scope in which the static block is executed + JS staticObject = null; // Only used during parsing ///////////////////////////////////////////////////////////////// @@ -61,12 +63,12 @@ public class Template { try { apply(b, null); } catch (IOException e) { - b.clear(b.VISIBLE); + b.clear(Box.VISIBLE); b.mark_for_repack(); Log.warn(this, e); throw new JSExn(e.toString()); } catch (JSExn e) { - b.clear(b.VISIBLE); + b.clear(Box.VISIBLE); b.mark_for_repack(); Log.warn(this, e); throw e; @@ -75,12 +77,14 @@ public class Template { private void apply(Box b, PerInstantiationScope parentPis) throws JSExn, IOException { if (prev != null) prev.apply(b, null); + if (prev2 != null) prev2.apply(b, null); // FIXME this dollar stuff is all wrong if (id != null) parentPis.putDollar(id, b); - PerInstantiationScope pis = new PerInstantiationScope(b, ibex, parentPis, staticScope); + PerInstantiationScope pis = new PerInstantiationScope(b, ibex, parentPis, staticObject); for(int i=0; i 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 +186,13 @@ 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 || "".equals(c.getUri("ui"))) c.addUri("ui", "ibex://ui"); + if (c.getUri("meta") == null || "".equals(c.getUri("meta"))) c.addUri("meta", "ibex://meta"); + if (c.getUri("") == null || "".equals(c.getUri(""))) 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,11 +202,12 @@ 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 { - t.prev = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); + // GROSSER hack + t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); } catch (Exception e) { Log.error(Template.class, e); } @@ -202,8 +221,10 @@ public class Template { while(uriEnumeration.hasMoreElements()) { String key = (String)uriEnumeration.nextElement(); String val = (String)urimap.get(key); + if (val.equals("ibex://ui")) continue; + if (val.equals("ibex://meta")) continue; 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++; } @@ -213,11 +234,10 @@ public class Template { // process attributes into Vecs, dealing with any XML Namespaces in the process ATTR: for (int i=0; i < c.getAttrLen(); i++) { - //#switch(c.getAttrKey(i)) - case "id": + if (c.getAttrKey(i).equals("id")) { t.id = c.getAttrVal(i).toString().intern(); continue ATTR; - //#end + } // treat value starting with '.' as resource reference String uri = c.getAttrUri(i); if (!uri.equals("")) uri = '.' + uri; @@ -265,16 +285,17 @@ 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); t.children.addElement(oldt); int oldt_lines = getLine() - oldt.startLine; + if (t.content == null) t.content = new StringBuffer(); for (int i=0; oldt_lines > i; i++) t.content.append('\n'); } } @@ -291,7 +312,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(); @@ -307,13 +328,13 @@ public class Template { private static class PerInstantiationScope extends JSScope { Ibex ibex = null; PerInstantiationScope parentBoxPis = null; - JSScope myStatic = null; + JS myStatic = null; void putDollar(String key, Box target) throws JSExn { if (parentBoxPis != null) parentBoxPis.putDollar(key, target); declare("$" + key); put("$" + key, target); } - public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JSScope myStatic) { + public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) { super(parentScope); this.parentBoxPis = parentBoxPis; this.ibex = ibex;