# HG changeset patch # User Sascha L. Teichmann # Date 1311195073 0 # Node ID 2de1808503be64b4fde4087a43b9ef50d13255e9 # Parent 3ba4f5a88c202cc87b40de0c9b941e306cf48752 Datacage template: Added a macro mechanism. flys-artifacts/trunk@2381 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3ba4f5a88c20 -r 2de1808503be flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Jul 20 20:13:49 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Jul 20 20:51:13 2011 +0000 @@ -1,3 +1,23 @@ +2011-07-20 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java: + Added a macro mechanism: + + + '5' ist nicht in der Liste der Outs. + + + + + + Macros can be defined everywhere in the template + with 'macro'. There bodies can contain all valid elements + including other 'macro's and 'call-macro's. They are + called with their 'name' with 'call-macro'. The control flow + is continued inside the body of the called macro and + will continue right after the calling 'call-macro' when + the macro body is finished. + 2011-07-20 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java: diff -r 3ba4f5a88c20 -r 2de1808503be flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 20:13:49 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 20:51:13 2011 +0000 @@ -180,6 +180,33 @@ element.setAttribute(name, value); } + protected void callMacro(Node parent, Element current) + throws SQLException + { + String name = current.getAttribute("name"); + + if (name.length() == 0) { + log.warn("missing 'name' attribute in 'call-macro'"); + return; + } + + NodeList macros = template.getElementsByTagNameNS( + DC_NAMESPACE_URI, "macro"); + + for (int i = 0, N = macros.getLength(); i < N; ++i) { + Element macro = (Element)macros.item(i); + if (name.equals(macro.getAttribute("name"))) { + NodeList subs = macro.getChildNodes(); + for (int j = 0, M = subs.getLength(); j < M; ++j) { + build(parent, subs.item(j)); + } + return; + } + } + + log.warn("no macro '" + name + "' found."); + } + protected void ifClause(Node parent, Element current) throws SQLException { @@ -321,6 +348,12 @@ else if ("convert".equals(localName)) { convert(parent, (Element)current); } + else if ("call-macro".equals(localName)) { + callMacro(parent, (Element)current); + } + else if ("macro".equals(localName)) { + // simply ignore the definition. + } else { log.warn("unknown '" + localName + "' -> ignore"); }