X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=22c994c2f78586a6640dd2f515392ece4e8acb5c;hb=bc0d2f2d898adb7b0e207ac4d9ddfde1b408230a;hp=324fea1b37057d8233a5a9207a9add789f58b9fc;hpb=66fa691f3f037006be09e5abfe747bcbbe4fe2c1;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 324fea1..22c994c 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -115,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"); @@ -143,9 +143,9 @@ public class Template { this.nodeName = nodeName; cache.put(nodeName, this); } - private Template(InputStream is, String nodeName) throws XML.SAXException, IOException { + private Template(InputStream is, String nodeName, TemplateHelper th) throws XML.XMLException, IOException { this(nodeName); - new TemplateHelper().parseit(is, this); + 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 */ @@ -410,16 +410,27 @@ public class Template { // XML Parsing ///////////////////////////////////////////////////////////////// /** handles XML parsing; builds a Template tree as it goes */ - private static class TemplateHelper extends XML { + static final class TemplateHelper extends XML { - TemplateHelper() { - for(int i=0; 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 */ @@ -453,79 +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