# HG changeset patch # User Sascha L. Teichmann # Date 1359395755 -3600 # Node ID bf38ea4cb0f73ee0af3796fb408e146d0aa26bc1 # Parent 8118f9b0ee7b811b9c48435b4374d1f876d3edbd Added bodies to macros. Use the bodies of as in tthe macro. Example: Earth Result: Earth diff -r 8118f9b0ee7b -r bf38ea4cb0f7 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Mon Jan 28 16:33:05 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Mon Jan 28 18:55:55 2013 +0100 @@ -92,6 +92,7 @@ protected List connections; protected Map statements; protected Deque> connectionsStack; + protected Deque macroBodies; public BuildHelper( Node output, @@ -110,6 +111,7 @@ owner = getOwnerDocument(output); statements = new HashMap(); + macroBodies = new ArrayDeque(); } public void build() throws SQLException { @@ -323,18 +325,45 @@ NodeList macros = template.getElementsByTagNameNS( DC_NAMESPACE_URI, "macro"); + Element macro = null; + for (int i = 0, N = macros.getLength(); i < N; ++i) { - Element macro = (Element) macros.item(i); - if (name.equals(macro.getAttribute("name"))) { + Element m = (Element) macros.item(i); + if (name.equals(m.getAttribute("name"))) { + macro = m; + break; + } + } + + if (macro != null) { + macroBodies.push(current.getChildNodes()); + try { NodeList subs = macro.getChildNodes(); for (int j = 0, M = subs.getLength(); j < M; ++j) { build(parent, subs.item(j)); } - return; + } + finally { + macroBodies.pop(); } } + else { + log.warn("no macro '" + name + "' found."); + } + } - log.warn("no macro '" + name + "' found."); + protected void macroBody(Node parent, Element current) + throws SQLException + { + if (!macroBodies.isEmpty()) { + NodeList children = macroBodies.peek(); + for (int i = 0, N = children.getLength(); i < N; ++i) { + build(parent, children.item(i)); + } + } + else { + log.warn("no current macro"); + } } protected void ifClause(Node parent, Element current) @@ -506,6 +535,9 @@ else if ("call-macro".equals(localName)) { callMacro(parent, (Element)current); } + else if ("macro-body".equals(localName)) { + macroBody(parent, (Element)current); + } else if ("macro".equals(localName)) { // Simply ignore the definition. }