X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=22c994c2f78586a6640dd2f515392ece4e8acb5c;hb=bc0d2f2d898adb7b0e207ac4d9ddfde1b408230a;hp=7ff09ce1033ab932484760c98a4b9804303c8f76;hpb=fea7f27cc252c8feaafb8a5c0d4b9f391f03975d;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 7ff09ce..22c994c 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -90,6 +90,8 @@ public class Template { /** number of lines in content */ private int content_lines = 0; + /** the line number that this element starts on */ + private int startLine = -1; // Static data/methods /////////////////////////////////////////////////////////////////// @@ -113,19 +115,19 @@ public class Template { } public static Template buildTemplate(InputStream is, String nodeName) { + return buildTemplate(is, nodeName, new TemplateHelper()); + } + + public static Template buildTemplate(InputStream is, String nodeName, TemplateHelper t) { try { - return new Template(is, nodeName); - } catch (XML.SAXParseException e) { - if (Log.on) Log.log(Template.class, "error parsing template at " + nodeName + ":" + e.getLineNumber() + "," + e.getColumnNumber()); - if (Log.on) Log.log(Template.class, e); - return null; - } catch (XML.SAXException e) { + return new Template(is, nodeName, t); + } catch (XML.SchemaException e) { if (Log.on) Log.log(Template.class, "error parsing template " + nodeName); - if (Log.on) Log.log(Template.class, e); + if (Log.on) Log.log(Template.class, e.getMessage()); return null; - } catch (TemplateException te) { - if (Log.on) Log.log(Template.class, "error parsing template " + nodeName); - if (Log.on) Log.log(Template.class, te); + } catch (XML.XMLException e) { + if (Log.on) Log.log(Template.class, "error parsing template at " + nodeName + ":" + 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 " + nodeName + " -- this should never happen"); @@ -137,11 +139,13 @@ public class Template { // Methods to apply templates //////////////////////////////////////////////////////// - private Template() { } - private Template(InputStream is, String nodeName) throws XML.SAXException, IOException { + private Template(String nodeName) { this.nodeName = nodeName; cache.put(nodeName, this); - new TemplateHelper().parseit(is, this); + } + private Template(InputStream is, String nodeName, TemplateHelper th) throws XML.XMLException, IOException { + this(nodeName); + th.parseit(is, this); } /** calculates, caches, and returns an integer approximation of how long it will take to apply this template, including pre/post and children */ @@ -161,7 +165,9 @@ public class Template { * @param pboxes a vector of all box parents on which to put $-references * @param ptemplates a vector of the nodeNames to recieve private references on the pboxes */ - void apply(Box b, Vec pboxes, Vec ptemplates) { + void apply(Box b, Vec pboxes, Vec ptemplates, Function callback, int numerator, int denominator) { + + int original_numerator = numerator; if (pboxes == null) { pboxes = new Vec(); @@ -185,10 +191,15 @@ public class Template { link(); for(int i=0; _preapply != null && i<_preapply.length; i++) - if (_preapply[i] != null) _preapply[i].apply(b, null, null); + if (_preapply[i] != null) { + _preapply[i].apply(b, null, null, callback, numerator, denominator); + numerator += _preapply[i].numUnits(); + } - for (int i=0; children != null && iroot */ - void parseit(InputStream is, Template root) throws XML.SAXException, IOException { + void parseit(InputStream is, Template root) throws XML.XMLException, IOException { + rootNodeHasBeenEncountered = false; + templateNodeHasBeenEncountered = false; + staticNodeHasBeenEncountered = false; + templateNodeHasBeenFinished = false; + nameOfHeaderNodeBeingProcessed = null; + + nodeStack.setSize(0); + importlist.setSize(0); + preapply.setSize(0); + postapply.setSize(0); + + importlist.fromArray(defaultImportList); + t = root; - parse(new TabAndMaxColumnEnforcingReader(new InputStreamReader(is), root.nodeName)); + parse(new InputStreamReader(is)); } /** parsing state: true iff we have already encountered the open-tag */ @@ -411,78 +464,78 @@ public class Template { /** the template we're currently working on */ Template t = null; - public void startElement(String name, String[] keys, Object[] vals, int line, int col) throws XML.SAXException { - + public void startElement(XML.Element c) throws XML.SchemaException { if (templateNodeHasBeenFinished) { - throw new XML.SAXException("no elements may appear after the