X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=22c994c2f78586a6640dd2f515392ece4e8acb5c;hb=bc0d2f2d898adb7b0e207ac4d9ddfde1b408230a;hp=859c39e3bbf7fa6269c7c119be3f23c2e4a3ace2;hpb=9a33358173f08013fdacd02c11f3823352bdae23;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 859c39e..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"); @@ -139,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 */ @@ -271,11 +273,8 @@ public class Template { } /** adds a theme mapping, retemplatizing as needed */ - public static void retheme(String from, String to) { - if (Log.on) Log.log(Template.class, "retheming from " + from + " to " + to); + public static void retheme(Function callback) { XWF.flushXWFs(); - Resources.mapFrom.addElement(from); - Resources.mapTo.addElement(to); // clear changed marker and relink Template[] t = new Template[cache.size()]; @@ -291,6 +290,17 @@ public class Template { Box b = ((Surface)Surface.allSurfaces.elementAt(i)).root; if (b != null) reapply(b); } + + if (callback != null) + try { + callback.call(Context.enter(), null, null, new Object[] { new Double(1.0), new Double(1.0) }); + } catch (EcmaError ex) { + if (Log.on) Log.log(Template.class, "WARNING: uncaught interpreter exception: " + ex.getMessage()); + if (Log.on) Log.log(Template.class, " thrown from within progress callback at " + ex.getSourceName() + ":" + ex.getLineNumber()); + } catch (JavaScriptException ex) { + if (Log.on) Log.log(Template.class, "WARNING: uncaught ecmascript exception: " + ex.getMessage()); + if (Log.on) Log.log(Template.class, " thrown from within progress callback at " + ex.sourceFile + ":" + ex.line); + } } /** template reapplication procedure */ @@ -303,8 +313,7 @@ public class Template { if (t != b.template) retemplatize = true; b.template = t; } - if (b.template != null && b.template.changed) - retemplatize = true; + if (b.template != null && b.template.changed) retemplatize = true; if (retemplatize) { @@ -359,7 +368,7 @@ public class Template { private void link(boolean force) { if (staticscript != null) try { - Scriptable s = Static.createStatic(nodeName); + Scriptable s = Static.createStatic(nodeName, false); if (staticscript != null) { Script temp = staticscript; ((InterpretedScript)temp).setParentScope(s); // so we know how to handle Static.get("xwt") @@ -401,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 */ @@ -444,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