[Dive4elements-commits] [PATCH 6 of 6] Builder: When looking for a statement in contexts, also search in macro definitions
Wald Commits
scm-commit at wald.intevation.org
Tue Jan 29 10:47:07 CET 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1359453177 -3600
# Node ID 27d58b7b5eddca97be5a7cfde73d8fb1166085e0
# Parent 065a78d6500774a879b39053504c4239ac7e353e
Builder: When looking for a statement in contexts, also search in macro definitions.
diff -r 065a78d65007 -r 27d58b7b5edd 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 17:31:49 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Tue Jan 29 10:52:57 2013 +0100
@@ -135,6 +135,43 @@
}
/**
+ * Return first statement node in NodeList, respecting
+ * macros.
+ */
+ private Node findStatementNode(NodeList nodes) {
+ int S = nodes.getLength();
+
+ // Check direct children and take special care of macros.
+ for (int i = 0; i < S; ++i) {
+ Node node = nodes.item(i);
+ String ns;
+ // Regular statement node.
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && node.getLocalName().equals("statement")
+ && (ns = node.getNamespaceURI()) != null
+ && ns.equals(DC_NAMESPACE_URI)) {
+ return node;
+ }
+ // Macro node. Descend.
+ else if (node.getNodeType() == Node.ELEMENT_NODE
+ && node.getLocalName().equals("call-macro")
+ && (ns = node.getNamespaceURI()) != null
+ && ns.equals(DC_NAMESPACE_URI)) {
+
+ String macroName = ((Element)node).getAttribute("name");
+ Node inMacroNode =
+ findStatementNode(getMacroChildren(macroName));
+ if (inMacroNode != null) {
+ return inMacroNode;
+ }
+ }
+
+ }
+
+ return null;
+ }
+
+ /**
* Handle a \<context\> node.
*/
protected void context(Node parent, Element current)
@@ -143,22 +180,9 @@
log.debug("dc:context");
NodeList subs = current.getChildNodes();
+ Node stmntNode = findStatementNode(subs);
int S = subs.getLength();
- // Check only direct children.
- Node stmntNode = null;
- for (int i = 0; i < S; ++i) {
- Node node = subs.item(i);
- String ns;
- if (node.getNodeType() == Node.ELEMENT_NODE
- && node.getLocalName().equals("statement")
- && (ns = node.getNamespaceURI()) != null
- && ns.equals(DC_NAMESPACE_URI)) {
- stmntNode = node;
- break;
- }
- }
-
if (stmntNode == null) {
log.warn("dc:context: cannot find statement");
return;
@@ -370,6 +394,27 @@
}
}
+ /** Get macro node children, not resolving bodies. */
+ protected NodeList getMacroChildren(String name) {
+ NodeList macros = template.getElementsByTagNameNS(
+ DC_NAMESPACE_URI, "macro");
+
+ Element macro = null;
+
+ for (int i = 0, N = macros.getLength(); i < N; ++i) {
+ Element m = (Element) macros.item(i);
+ if (name.equals(m.getAttribute("name"))) {
+ macro = m;
+ break;
+ }
+ }
+
+ if (macro != null) {
+ return macro.getChildNodes();
+ }
+ return null;
+ }
+
protected void ifClause(Node parent, Element current)
throws SQLException
{
More information about the Dive4elements-commits
mailing list