X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=40648f64e5a72aeffb3a34c4af30bb41dabf14c7;hb=8ad8837b741bd77cd8aeef1881159ad839ce3828;hp=ba1c4ee56b39e955f64f78f05c844080ec8910a7;hpb=7056081c7716d88a532dfe846d642b00e3d6a6b4;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index ba1c4ee..40648f6 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -26,22 +26,19 @@ public class Template { // Instance Members /////////////////////////////////////////////////////// - String id = null; ///< the id of this box - String redirect = null; ///< the id of the redirect target; only meaningful on a root node - private String[] keys; ///< keys to be "put" to instances of this template; elements correspond to those of vals - private Object[] vals; ///< values to be "put" to instances of this template; elements correspond to those of keys - private Vec children = new Vec(); ///< during XML parsing, this holds the list of currently-parsed children; null otherwise - private int numunits = -1; ///< see numUnits(); -1 means that this value has not yet been computed - - private JS script = null; ///< the script on this node - private String fileName = "unknown"; ///< the filename this node came from; used only for debugging - private Vec preapply = new Vec(); ///< templates that should be preapplied (in the order of application) + String id = null; ///< the id of this box + String redirect = null; ///< the id of the redirect target; only meaningful on a root node + private String[] keys; ///< keys to be "put" to instances of this template; elements correspond to those of vals + private Object[] vals; ///< values to be "put" to instances of this template; elements correspond to those of keys + 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 + private String tagname = null; ///< template to preapply (if any) // Instance Members that are only meaningful on root Template ////////////////////////////////////// private JSScope staticScope = null; ///< the scope in which the static block is executed - private JS staticscript = null; ///< the script on the static node of this template, null already performed + private JS staticscript = null; ///< the script on the static node of this template, null already performed // Only used during parsing ///////////////////////////////////////////////////////////////// @@ -54,44 +51,18 @@ public class Template { // Static data/methods /////////////////////////////////////////////////////////////////// - public Template(InputStream is, XWT xwt) { - this.xwt = xwt; - try { - new TemplateHelper().parseit(is, this); - } catch (Exception e) { - throw new RuntimeException(e.toString()); - } - } - - public Template(XWT xwt) { - this.xwt = xwt; - } - - public static JS resolveStringToResource(String str, XWT xwt, boolean permitAbsolute) throws JSExn { - // URL - /* FIXME - if (str.indexOf("://") != -1) { - if (permitAbsolute) return (Stream)xwt.url2res(str); - throw new JSExn("absolute URL " + str + " not permitted here"); - } - */ - // root-relative - JS ret = (JS)xwt.getAndTriggerTraps(""); - while(str.indexOf('.') != -1) { - String path = str.substring(0, str.indexOf('.')); - str = str.substring(str.indexOf('.') + 1); - ret = (JS)ret.get(path); - } - ret = (JS)ret.get(str); - return ret; + // for non-root nodes + private Template(XWT xwt) { this.xwt = xwt; } + public Template(InputStream is, XWT xwt) throws IOException, JSExn, XML.Exn { + this.xwt = xwt; new TemplateHelper().parseit(is, this); } - + // Methods to apply templates //////////////////////////////////////////////////////// /** called before this template is applied or its static object can be externally referenced */ JSScope getStatic() throws JSExn { - if (staticScope == null) staticScope = new PerInstantiationJSScope(null, xwt, null, null); + if (staticScope == null) staticScope = new PerInstantiationScope(null, xwt, null, null); if (staticscript == null) return staticScope; JS temp = staticscript; staticscript = null; @@ -119,18 +90,16 @@ public class Template { } } - private void apply(Box b, PerInstantiationJSScope parentPis) throws JSExn, IOException { + private void apply(Box b, PerInstantiationScope parentPis) throws JSExn, IOException { getStatic(); + // FIXME this dollar stuff is all wrong if (id != null) parentPis.putDollar(id, b); - for(int i=0; i 0) - thisscript = JS.fromReader(t.fileName + (isstatic ? "._" : ""), - t.content_start, - new StringReader(contentString)); + thisscript = JS.fromReader("FIXME", t.content_start, new StringReader(contentString)); t.content = null; t.content_start = 0; return thisscript; @@ -370,16 +323,16 @@ public class Template { public void whitespace(char[] ch, int start, int length) throws XML.Exn { } } - private static class PerInstantiationJSScope extends JSScope { + private static class PerInstantiationScope extends JSScope { XWT xwt = null; - PerInstantiationJSScope parentBoxPis = null; + PerInstantiationScope parentBoxPis = null; JSScope myStatic = null; void putDollar(String key, Box target) throws JSExn { if (parentBoxPis != null) parentBoxPis.putDollar(key, target); declare("$" + key); put("$" + key, target); } - public PerInstantiationJSScope(JSScope parentScope, XWT xwt, PerInstantiationJSScope parentBoxPis, JSScope myStatic) { + public PerInstantiationScope(JSScope parentScope, XWT xwt, PerInstantiationScope parentBoxPis, JSScope myStatic) { super(parentScope); this.parentBoxPis = parentBoxPis; this.xwt = xwt;