Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java @ 4890:bf38ea4cb0f7
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>
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 28 Jan 2013 18:55:55 +0100 |
parents | fb135e1dfa35 |
children | 089bc08f720e |
comparison
equal
deleted
inserted
replaced
4889:8118f9b0ee7b | 4890:bf38ea4cb0f7 |
---|---|
90 protected Document owner; | 90 protected Document owner; |
91 protected StackFrames frames; | 91 protected StackFrames frames; |
92 protected List<NamedConnection> connections; | 92 protected List<NamedConnection> connections; |
93 protected Map<String, CompiledStatement.Instance> statements; | 93 protected Map<String, CompiledStatement.Instance> statements; |
94 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack; | 94 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack; |
95 protected Deque<NodeList> macroBodies; | |
95 | 96 |
96 public BuildHelper( | 97 public BuildHelper( |
97 Node output, | 98 Node output, |
98 List<NamedConnection> connections, | 99 List<NamedConnection> connections, |
99 Map<String, Object> parameters | 100 Map<String, Object> parameters |
108 this.output = output; | 109 this.output = output; |
109 frames = new StackFrames(parameters); | 110 frames = new StackFrames(parameters); |
110 owner = getOwnerDocument(output); | 111 owner = getOwnerDocument(output); |
111 statements = | 112 statements = |
112 new HashMap<String, CompiledStatement.Instance>(); | 113 new HashMap<String, CompiledStatement.Instance>(); |
114 macroBodies = new ArrayDeque<NodeList>(); | |
113 } | 115 } |
114 | 116 |
115 public void build() throws SQLException { | 117 public void build() throws SQLException { |
116 try { | 118 try { |
117 synchronized (template) { | 119 synchronized (template) { |
321 } | 323 } |
322 | 324 |
323 NodeList macros = template.getElementsByTagNameNS( | 325 NodeList macros = template.getElementsByTagNameNS( |
324 DC_NAMESPACE_URI, "macro"); | 326 DC_NAMESPACE_URI, "macro"); |
325 | 327 |
328 Element macro = null; | |
329 | |
326 for (int i = 0, N = macros.getLength(); i < N; ++i) { | 330 for (int i = 0, N = macros.getLength(); i < N; ++i) { |
327 Element macro = (Element) macros.item(i); | 331 Element m = (Element) macros.item(i); |
328 if (name.equals(macro.getAttribute("name"))) { | 332 if (name.equals(m.getAttribute("name"))) { |
333 macro = m; | |
334 break; | |
335 } | |
336 } | |
337 | |
338 if (macro != null) { | |
339 macroBodies.push(current.getChildNodes()); | |
340 try { | |
329 NodeList subs = macro.getChildNodes(); | 341 NodeList subs = macro.getChildNodes(); |
330 for (int j = 0, M = subs.getLength(); j < M; ++j) { | 342 for (int j = 0, M = subs.getLength(); j < M; ++j) { |
331 build(parent, subs.item(j)); | 343 build(parent, subs.item(j)); |
332 } | 344 } |
333 return; | 345 } |
334 } | 346 finally { |
335 } | 347 macroBodies.pop(); |
336 | 348 } |
337 log.warn("no macro '" + name + "' found."); | 349 } |
350 else { | |
351 log.warn("no macro '" + name + "' found."); | |
352 } | |
353 } | |
354 | |
355 protected void macroBody(Node parent, Element current) | |
356 throws SQLException | |
357 { | |
358 if (!macroBodies.isEmpty()) { | |
359 NodeList children = macroBodies.peek(); | |
360 for (int i = 0, N = children.getLength(); i < N; ++i) { | |
361 build(parent, children.item(i)); | |
362 } | |
363 } | |
364 else { | |
365 log.warn("no current macro"); | |
366 } | |
338 } | 367 } |
339 | 368 |
340 protected void ifClause(Node parent, Element current) | 369 protected void ifClause(Node parent, Element current) |
341 throws SQLException | 370 throws SQLException |
342 { | 371 { |
504 choose(parent, (Element)current); | 533 choose(parent, (Element)current); |
505 } | 534 } |
506 else if ("call-macro".equals(localName)) { | 535 else if ("call-macro".equals(localName)) { |
507 callMacro(parent, (Element)current); | 536 callMacro(parent, (Element)current); |
508 } | 537 } |
538 else if ("macro-body".equals(localName)) { | |
539 macroBody(parent, (Element)current); | |
540 } | |
509 else if ("macro".equals(localName)) { | 541 else if ("macro".equals(localName)) { |
510 // Simply ignore the definition. | 542 // Simply ignore the definition. |
511 } | 543 } |
512 else if ("element".equals(localName)) { | 544 else if ("element".equals(localName)) { |
513 element(parent, (Element)current); | 545 element(parent, (Element)current); |