X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=03dd337e7c10368342fe0f1b2a292c59db0b451b;hb=16ad8b9430571d806f2aeb18ec472a277ff69423;hp=95846c1ce446f132c2be6b627c1401701191d223;hpb=8235361e8601ae7b36ab707058de3b52225d15a2;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 95846c1..03dd337 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -1,4 +1,4 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import java.io.*; @@ -6,6 +6,7 @@ import java.util.zip.*; import java.util.*; import java.lang.*; import org.xwt.js.*; +import org.xwt.translators.*; import org.xwt.util.*; /** @@ -21,115 +22,51 @@ import org.xwt.util.*; * See the XWT reference for information on the order in which * templates are applied, attributes are put, and scripts are run. */ - -// FIXME imports public class Template { // Instance Members /////////////////////////////////////////////////////// - /** the id of this box */ - String id = null; - - /** the id of the redirect target; only meaningful on a root node */ - String redirect = null; - - /** templates that should be preapplied (in the order of application); only meaningful on a root node */ - private Template[] preapply; - - /** templates that should be postapplied (in the order of application); only meaningful on a root node */ - private Template[] postapply; - - /** keys to be "put" to instances of this template; elements correspond to those of vals */ - private String[] keys; - - /** values to be "put" to instances of this template; elements correspond to those of keys */ - private Object[] vals; + 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) - /** child template objects */ - private Template[] children; - /** see numUnits(); -1 means that this value has not yet been computed */ - private int numunits = -1; + // Instance Members that are only meaningful on root Template ////////////////////////////////////// - /** the scope in which the static block is executed */ - private JS.Scope staticScope = null; - - /** the script on the static node of this template, null if it has already been executed */ - private JS.CompiledFunction staticscript = null; - - /** the script on this node */ - private JS.CompiledFunction script = null; - - /** the filename this node came from; used only for debugging */ - private String fileName = "unknown"; + 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 // Only used during parsing ///////////////////////////////////////////////////////////////// - /** during XML parsing, this holds the list of currently-parsed children; null otherwise */ - private Vec childvect = new Vec(); - - /** during XML parsing, this holds partially-read character data; null otherwise */ - private StringBuffer content = null; - - /** line number of the first line of content */ - private int content_start = 0; - - /** number of lines in content */ - private int content_lines = 0; - - /** the line number that this element starts on */ - private int startLine = -1; + 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 content + private int startLine = -1; ///< the line number that this element starts on + private XWT xwt; // Static data/methods /////////////////////////////////////////////////////////////////// - private Template(String fileName) { this.fileName = fileName; } - - public static Template getTemplate(Res r) { - try { - if (r.t != null) return r.t; - r.t = new Template(r.getDescriptiveName()); - new TemplateHelper().parseit(r.getInputStream(), r.t); - return r.t; - } catch (XML.SchemaException e) { - if (Log.on) Log.log(Template.class, "error parsing template " + r.t.fileName); - if (Log.on) Log.log(Template.class, e.getMessage()); - return null; - } catch (XML.XMLException e) { - if (Log.on) Log.log(Template.class, "error parsing template at " + r.t.fileName + ":" + e.getLine() + "," + e.getCol()); - if (Log.on) Log.log(Template.class, e.getMessage()); - return null; - } catch (IOException e) { - if (Log.on) Log.log(Template.class, "IOException while parsing template " + r.t.fileName + " -- this should never happen"); - if (Log.on) Log.log(Template.class, e); - return null; - } + // 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 //////////////////////////////////////////////////////// - /** calculates, caches, and returns an integer approximation of how long it will take to apply this template, - * including pre/post and children */ - int numUnits() { - if (numunits != -1) return numunits; - numunits = 1; - for(int i=0; preapply != null && i 0) { + switch (((String)val).charAt(0)) { + case '$': + val = pis.get(val); + if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute"); + break; + case '.': + val = xwt.resolveStringToResource(((String)val).substring(1), false); + // FIXME: url case + // FIXME: should we be resolving all of these in the XML-parsing code? + } + } - for(int i=0; postapply != null && iroot */ - void parseit(InputStream is, Template root) throws XML.XMLException, IOException { - rootNodeHasBeenEncountered = false; - templateNodeHasBeenEncountered = false; - staticNodeHasBeenEncountered = false; - templateNodeHasBeenFinished = false; + void parseit(InputStream is, Template root) throws XML.Exn, IOException { + state = STATE_INITIAL; nameOfHeaderNodeBeingProcessed = null; - nodeStack.setSize(0); - preapply.setSize(0); - postapply.setSize(0); - t = root; parse(new InputStreamReader(is)); } - /** parsing state: true iff we have already encountered the open-tag */ - boolean rootNodeHasBeenEncountered = false; - - /** parsing state: true iff we have already encountered the