From cb1a5438e2216c357fdfcf53b182b78875f782ab Mon Sep 17 00:00:00 2001 From: david Date: Fri, 30 Jan 2004 06:59:15 +0000 Subject: [PATCH] 2003/04/24 14:33:28 darcs-hash:20040130065915-0c9ea-184b936b44f827ad4844c5f288feb1ccd0d8d613.gz --- src/org/xwt/Template.java | 265 +++++-------- src/org/xwt/XML.java | 971 --------------------------------------------- src/org/xwt/XMLRPC.java | 39 +- 3 files changed, 117 insertions(+), 1158 deletions(-) delete mode 100644 src/org/xwt/XML.java diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 324fea1..ba542fd 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -95,6 +95,9 @@ public class Template { // Static data/methods /////////////////////////////////////////////////////////////////// + /** maximum length of a line */ + private static final int MAX_COLUMN = 150; + /** a template cache so that only one Template object is created for each xwt */ private static Hashtable cache = new Hashtable(1000); @@ -115,19 +118,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 +146,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 +413,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 +467,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