[Dive4elements-commits] [PATCH] Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Wald Commits
scm-commit at wald.intevation.org
Mon Jan 28 18:56:00 CET 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1359395755 -3600
# Node ID bf38ea4cb0f73ee0af3796fb408e146d0aa26bc1
# Parent 8118f9b0ee7b811b9c48435b4374d1f876d3edbd
Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
<dc:macro name="greet"><hello><dc:macro-body/></hello></dc:macro>
<dc:call-macro name="greet"><planet>Earth</planet></dc:call-macro>
Result:
<hello><panet>Earth</planet></hello>
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<NamedConnection> connections;
protected Map<String, CompiledStatement.Instance> statements;
protected Deque<Pair<NamedConnection, ResultData>> connectionsStack;
+ protected Deque<NodeList> macroBodies;
public BuildHelper(
Node output,
@@ -110,6 +111,7 @@
owner = getOwnerDocument(output);
statements =
new HashMap<String, CompiledStatement.Instance>();
+ macroBodies = new ArrayDeque<NodeList>();
}
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.
}
More information about the Dive4elements-commits
mailing list