From: megacz Date: Fri, 30 Jan 2004 07:36:18 +0000 (+0000) Subject: 2003/09/25 10:10:52 X-Git-Tag: RC3~583 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=5ef18e2b3993d3c515a0b51a1326b2ad11285f4a 2003/09/25 10:10:52 darcs-hash:20040130073618-2ba56-05059dd0eba4c83891d8759afb45dd0863aa5851.gz --- diff --git a/src/org/xwt/Box.java.pp b/src/org/xwt/Box.java.pp index f18182c..4a1c07a 100644 --- a/src/org/xwt/Box.java.pp +++ b/src/org/xwt/Box.java.pp @@ -473,42 +473,6 @@ public final class Box extends JS.Scope { return redirect.callMethod(method, args, checkOnly); } return new Integer(b.getIndexInParent()); - - } else if ("apply".equals(method)) { - if (checkOnly) return Boolean.TRUE; - if (args.elementAt(0) instanceof Res) { - Res res = (Res)args.elementAt(0); - // res = res.addExtension(".xwt"); - Template t = Template.getTemplate(res); - if (ThreadMessage.suspendThread()) try { - JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1); - - // FIXME!!! needs to be xwt.apply(template, box) - t.apply(this, callback, 0, t.numUnits(), null); - } finally { - ThreadMessage.resumeThread(); - } - } else if (args.elementAt(0) instanceof String) { - String templatename = (String)args.elementAt(0); - // FIXME - Template t = Template.getTemplate(null); - if (t == null) { - if (Log.on) Log.logJS(this, "template " + templatename + " not found"); - } else { - if (ThreadMessage.suspendThread()) try { - JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1); - // FIXME!!! needs to be xwt.apply(template, box) - t.apply(this, callback, 0, t.numUnits(), null); - } finally { - ThreadMessage.resumeThread(); - } - } - } else if (args.elementAt(0) instanceof JS && !(args.elementAt(0) instanceof Box)) { - JS s = (JS)args.elementAt(0); - Object[] keys = s.keys(); - for(int j=0; jcontent */ - 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 content_lines = 0; ///< number of lines in content + private int startLine = -1; ///< the line number that this element starts on + final Res r; ///< the resource we came from // 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()); + r.t = new Template(r); 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()); + } catch (Exception e) { + if (Log.on) Log.log(r.t.fileName, e); 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); + } + } + + public static Res resolveStringToResource(String str, XWT xwt, boolean permitAbsolute) { + // URL + if (str.indexOf("://") != -1) { + if (permitAbsolute) return str; + Log.log("absolute URL " + str + " not permitted here"); return null; } + + // root-relative + Res ret = xwt.rr; + while(str.indexOf('.') != -1) { + String path = str.substring(0, str.indexOf('.')); + str = str.substring(str.indexOf('.') + 1); + ret = (Res)ret.get(path); + } + ret = (Res)ret.get(str); + return ret; } // 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 && iroot */ void parseit(InputStream is, Template root) throws XML.XMLException, IOException { - rootNodeHasBeenEncountered = false; - templateNodeHasBeenEncountered = false; - staticNodeHasBeenEncountered = false; - templateNodeHasBeenFinished = false; + 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