annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 6050:06450ef553cc

DC: fixed dc:group
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 21 May 2013 16:30:14 +0200
parents af13ceeba52a
children c7777feea223
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5974
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5974
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5779
diff changeset
9 package org.dive4elements.river.artifacts.datacage.templating;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5779
diff changeset
11 import org.dive4elements.artifacts.common.utils.XMLUtils;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5779
diff changeset
13 import org.dive4elements.river.utils.Pair;
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
14
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
15 import java.sql.Connection;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
16 import java.sql.SQLException;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
17
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
18 import java.util.ArrayDeque;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
19 import java.util.ArrayList;
5974
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
20 import java.util.Arrays;
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
21 import java.util.Collection;
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
22 import java.util.Collections;
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
23 import java.util.Deque;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
24 import java.util.HashMap;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
25 import java.util.List;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
26 import java.util.Map;
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
27 import java.util.TreeMap;
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
28
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
29 import java.util.regex.Matcher;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
30 import java.util.regex.Pattern;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
31
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
32 import javax.xml.namespace.QName;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
33
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
34 import javax.xml.xpath.XPath;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
35 import javax.xml.xpath.XPathConstants;
5449
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
36 import javax.xml.xpath.XPathExpression;
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
37 import javax.xml.xpath.XPathExpressionException;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
38 import javax.xml.xpath.XPathFactory;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
39
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 import org.apache.log4j.Logger;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
42 import org.w3c.dom.Attr;
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
43 import org.w3c.dom.Document;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
44 import org.w3c.dom.Element;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
45 import org.w3c.dom.Node;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
46 import org.w3c.dom.NodeList;
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
47 import org.w3c.dom.NamedNodeMap;
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
48
4526
1f38fa929986 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4353
diff changeset
49
4897
9c388de4b4d5 Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4896
diff changeset
50 /** Handles and evaluate meta-data template against dbs. */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public class Builder
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 private static Logger log = Logger.getLogger(Builder.class);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public static final Pattern STRIP_LINE_INDENT =
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 Pattern.compile("\\s*\\r?\\n\\s*");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
58 public static final Pattern BRACKET_XPATH =
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
59 Pattern.compile("\\{([^}]+)\\}");
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
60
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public static final String DC_NAMESPACE_URI =
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 "http://www.intevation.org/2011/Datacage";
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 private static final Document EVAL_DOCUMENT =
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 XMLUtils.newDocument();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 private static final XPathFactory XPATH_FACTORY =
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 XPathFactory.newInstance();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 protected Document template;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 protected Map<String, CompiledStatement> compiledStatements;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
74 protected Map<String, Element> macros;
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
75
4526
1f38fa929986 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4353
diff changeset
76 /** Connection to either of the databases. */
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
77 public static class NamedConnection {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
78
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
79 protected String name;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
80 protected Connection connection;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
81 protected boolean cached;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
82
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
83 public NamedConnection() {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
84 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
85
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
86 public NamedConnection(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1890
diff changeset
87 String name,
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
88 Connection connection
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
89 ) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
90 this(name, connection, true);
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
91 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
92
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
93 public NamedConnection(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1890
diff changeset
94 String name,
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
95 Connection connection,
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
96 boolean cached
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
97 ) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
98 this.name = name;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
99 this.connection = connection;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
100 this.cached = cached;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
101 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
102 } // class NamedConnection
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
103
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 public class BuildHelper
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 {
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
106 protected Node output;
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
107 protected Document owner;
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
108 protected StackFrames frames;
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
109 protected List<NamedConnection> connections;
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
110 protected Map<String, CompiledStatement.Instance> statements;
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
111 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack;
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
112 protected Deque<NodeList> macroBodies;
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
113 protected Deque<Object> groupExprStack;
5442
9575264f801d Only create one FunctionResolver per BuildHelper. Creatin new ones over and over again is excessive.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5433
diff changeset
114 protected FunctionResolver functionResolver;
5449
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
115 protected Map<String, XPathExpression> expressions;
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
116
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 public BuildHelper(
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
119 Node output,
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
120 List<NamedConnection> connections,
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
121 Map<String, Object> parameters
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 ) {
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
123 if (connections.isEmpty()) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
124 throw new IllegalArgumentException("no connections given.");
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
125 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
126
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
127 this.connections = connections;
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
128 connectionsStack =
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
129 new ArrayDeque<Pair<NamedConnection, ResultData>>();
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
130 this.output = output;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
131 frames = new StackFrames(parameters);
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
132 owner = getOwnerDocument(output);
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
133 macroBodies = new ArrayDeque<NodeList>();
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
134 groupExprStack = new ArrayDeque<Object>();
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
135 functionResolver = new FunctionResolver(this);
5449
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
136 expressions = new HashMap<String, XPathExpression>();
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
137 statements =
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
138 new HashMap<String, CompiledStatement.Instance>();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 public void build() throws SQLException {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 try {
5779
ebec12def170 Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5532
diff changeset
143 // XXX: Thread safety is now established by the builder pool.
ebec12def170 Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5532
diff changeset
144 //synchronized (template) {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 for (Node current: rootsToList()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 build(output, current);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 }
5779
ebec12def170 Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5532
diff changeset
148 //}
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 finally {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 closeStatements();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 protected void closeStatements() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 for (CompiledStatement.Instance csi: statements.values()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 csi.close();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 statements.clear();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
162 /**
4896
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
163 * Return first statement node in NodeList, respecting
4897
9c388de4b4d5 Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4896
diff changeset
164 * macros but not doing evaluation (e.g. of <dc:if>s).
4896
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
165 */
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
166 private Node findStatementNode(NodeList nodes) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
167 int S = nodes.getLength();
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
168
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
169 // Check direct children and take special care of macros.
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
170 for (int i = 0; i < S; ++i) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
171 Node node = nodes.item(i);
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
172 String ns;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
173 // Regular statement node.
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
174 if (node.getNodeType() == Node.ELEMENT_NODE
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
175 && node.getLocalName().equals("statement")
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
176 && (ns = node.getNamespaceURI()) != null
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
177 && ns.equals(DC_NAMESPACE_URI)) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
178 return node;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
179 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
180 // Macro node. Descend.
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
181 else if (node.getNodeType() == Node.ELEMENT_NODE
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
182 && node.getLocalName().equals("call-macro")
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
183 && (ns = node.getNamespaceURI()) != null
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
184 && ns.equals(DC_NAMESPACE_URI)) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
185
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
186 String macroName = ((Element)node).getAttribute("name");
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
187 Node inMacroNode =
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
188 findStatementNode(getMacroChildren(macroName));
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
189 if (inMacroNode != null) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
190 return inMacroNode;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
191 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
192 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
193
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
194 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
195
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
196 return null;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
197 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
198
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
199 /**
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
200 * Handle a dc:context node.
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
201 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 protected void context(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 {
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
205 log.debug("dc:context");
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
207 NodeList subs = current.getChildNodes();
4896
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
208 Node stmntNode = findStatementNode(subs);
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
209 int S = subs.getLength();
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
210
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
211 if (stmntNode == null) {
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
212 log.warn("dc:context: cannot find statement");
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
216 String stmntText = stmntNode.getTextContent();
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
217
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
218 String con = current.getAttribute("connection");
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
219
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
220 String key = con + "-" + stmntText;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
221
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
222 CompiledStatement.Instance csi = statements.get(key);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 if (csi == null) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 CompiledStatement cs = compiledStatements.get(stmntText);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 csi = cs.new Instance();
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
227 statements.put(key, csi);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
230 NamedConnection connection = connectionsStack.isEmpty()
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
231 ? connections.get(0)
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
232 : connectionsStack.peek().getA();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
234 if (con.length() > 0) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
235 for (NamedConnection nc: connections) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
236 if (con.equals(nc.name)) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
237 connection = nc;
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
238 break;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 }
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
241 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
242
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
243 ResultData rd = csi.execute(
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
244 connection.connection,
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
245 frames,
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
246 connection.cached);
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
247
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
248 // only descent if there are results
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
249 if (!rd.isEmpty()) {
4051
58bdf95df5e4 More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3571
diff changeset
250 connectionsStack.push(
58bdf95df5e4 More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3571
diff changeset
251 new Pair<NamedConnection, ResultData>(connection, rd));
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
252 try {
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
253 for (int i = 0; i < S; ++i) {
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
254 build(parent, subs.item(i));
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
255 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256 }
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
257 finally {
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
258 connectionsStack.pop();
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
259 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260 }
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
261 }
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
262
5433
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
263 public boolean hasResult() {
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
264 return !connectionsStack.isEmpty()
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
265 && !connectionsStack.peek().getB().isEmpty();
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
266 }
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
267
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
268 protected ResultData createFilteredResultData(
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
269 ResultData rd,
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
270 String filter
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
271 ) {
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
272 if (filter == null) return rd;
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
273
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
274 XPathExpression x;
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
275 try {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
276 x = getXPathExpression(filter);
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
277 }
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
278 catch (XPathExpressionException xee) {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
279 log.warn("Invalid filter expression '" + filter + "'.");
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
280 return rd;
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
281 }
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
282
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
283 List<Object []> rows = rd.getRows();
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
284 String [] columns = rd.getColumnLabels();
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
285
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
286 List<Object []> filtered = new ArrayList<Object[]>(rows.size());
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
287
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
288 for (Object [] row: rows) {
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
289 frames.enter();
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
290 try {
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
291 frames.put(columns, row);
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
292 Object result = x.evaluate(
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
293 EVAL_DOCUMENT, XPathConstants.BOOLEAN);
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
294
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
295 if (result instanceof Boolean && (Boolean)result) {
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
296 filtered.add(row);
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
297 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
298 }
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
299 catch (XPathExpressionException xee) {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
300 log.warn("unable to apply filter expression '" +
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
301 filter + "' to dataset.");
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
302 }
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
303 finally {
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
304 frames.leave();
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
305 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
306 }
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
307 return new ResultData(columns, filtered);
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
308 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
309
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
310 protected void filter(Node parent, Element current)
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
311 throws SQLException
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
312 {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
313 String expr = current.getAttribute("expr");
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
314
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
315 if ((expr = expr.trim()).length() == 0) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
316 expr = null;
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
317 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
318
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
319 NodeList subs = current.getChildNodes();
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
320 int S = subs.getLength();
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
321 if (S == 0) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
322 log.debug("dc:filter has no children");
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
323 return;
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
324 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
325
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
326 ResultData orig = null;
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
327 Pair<Builder.NamedConnection, ResultData> pair = null;
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
328
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
329 if (expr != null && !connectionsStack.isEmpty()) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
330 pair = connectionsStack.peek();
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
331 orig = pair.getB();
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
332 pair.setB(createFilteredResultData(orig, expr));
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
333 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
334
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
335 try {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
336 for (int i = 0; i < S; ++i) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
337 build(parent, subs.item(i));
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
338 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
339 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
340 finally {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
341 if (orig != null) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
342 pair.setB(orig);
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
343 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
344 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
345 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
346
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
347 protected Map<Object, ResultData> createGroupedResultData(
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
348 ResultData rd,
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
349 String expr,
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
350 String type
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
351 ) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
352 List<Object []> rows = rd.getRows();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
353 String [] columns = rd.getColumnLabels();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
354
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
355 XPathExpression x;
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
356 try {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
357 x = getXPathExpression(expr);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
358 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
359 catch (XPathExpressionException xee) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
360 log.warn("Invalid expression '" + expr + "'.");
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
361 return Collections.<Object, ResultData>emptyMap();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
362 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
363
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
364 QName returnType = typeToQName(type);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
365
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
366 Map<Object, ResultData> groups = new TreeMap<Object, ResultData>();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
367
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
368 for (Object [] row: rows) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
369 frames.enter();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
370 try {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
371 frames.put(columns, row);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
372
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
373 Object key = x.evaluate(EVAL_DOCUMENT, returnType);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
374
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
375 ResultData group = groups.get(key);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
376
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
377 if (group == null) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
378 group = new ResultData(rd.getColumnLabels());
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
379 groups.put(key, group);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
380 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
381
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
382 group.add(row);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
383 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
384 catch (XPathExpressionException xxe) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
385 log.warn("unable to apply expression '" +
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
386 expr + "' to dataset.");
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
387 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
388 finally {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
389 frames.leave();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
390 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
391 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
392 return groups;
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
393 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
394
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
395 protected void group(Node parent, Element current)
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
396 throws SQLException
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
397 {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
398 log.debug("dc:group");
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
399
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
400 if (connectionsStack.isEmpty()) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
401 log.debug("dc:group without having results");
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
402 return;
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
403 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
404
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
405 NodeList subs = current.getChildNodes();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
406 int S = subs.getLength();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
407
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
408 if (S == 0) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
409 log.debug("dc:group has no children");
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
410 return;
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
411 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
412
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
413 String expr = current.getAttribute("expr").trim();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
414 String type = current.getAttribute("type").trim();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
415
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
416 Pair<Builder.NamedConnection, ResultData> pair =
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
417 connectionsStack.peek();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
418
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
419 ResultData orig = connectionsStack.peek().getB();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
420
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
421 Map<Object, ResultData> groups =
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
422 createGroupedResultData(orig, expr, type);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
423
6050
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
424 boolean debug = log.isDebugEnabled();
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
425
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
426 try {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
427 for (Map.Entry<Object, ResultData> entry: groups.entrySet()) {
6050
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
428 Object key = entry.getKey();
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
429 ResultData rd = entry.getValue();
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
430 pair.setB(rd);
6050
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
431 groupExprStack.push(key);
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
432 if (debug) {
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
433 log.debug("group key: " + key);
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
434 }
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
435 try {
6050
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
436 for (int i = 0; i < S; ++i) {
06450ef553cc DC: fixed dc:group
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
437 build(parent, subs.item(i));
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
438 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
439 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
440 finally {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
441 groupExprStack.pop();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
442 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
443 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
444 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
445 finally {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
446 pair.setB(orig);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
447 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
448 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
449
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
450 public Object getGroupKey() {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
451 return groupExprStack.isEmpty()
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
452 ? null
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
453 : groupExprStack.peek();
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
454 }
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
455
5974
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
456 protected void iterate(Node parent, Element current)
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
457 throws SQLException
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
458 {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
459 log.debug("dc:iterate");
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
460 String container = expand(current.getAttribute("container"));
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
461 String var = expand(current.getAttribute("var")).toUpperCase();
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
462
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
463 if (container.isEmpty()) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
464 log.warn("'container' not set.");
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
465 return;
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
466 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
467
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
468 if (var.isEmpty()) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
469 log.warn("'var' not set.");
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
470 return;
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
471 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
472
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
473 Object [] result = new Object[1];
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
474
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
475 if (frames.getStore(container, result)) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
476 Object c = result[0];
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
477 if (c instanceof Object []) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
478 c = Arrays.asList((Object [])c);
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
479 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
480 if (c instanceof Collection) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
481 frames.enter();
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
482 try {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
483 Collection<?> col = (Collection<?>)c;
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
484 for (Object o: col) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
485 if (o instanceof String) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
486 o = ((String)o).toLowerCase();
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
487 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
488 frames.put(var, o);
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
489 NodeList subs = current.getChildNodes();
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
490 for (int i = 0, N = subs.getLength(); i < N; ++i) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
491 build(parent, subs.item(i));
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
492 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
493 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
494 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
495 finally {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
496 frames.leave();
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
497 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
498 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
499 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
500 }
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
501
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
502
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
503 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
504 * Kind of foreach over results of a statement within a context.
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
505 */
5522
eeac800eb4cd Datacage: Rename <dc:elements> to <dc:for-each>. We should have done this much earlier.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5517
diff changeset
506 protected void foreach(Node parent, Element current)
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
507 throws SQLException
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
508 {
5522
eeac800eb4cd Datacage: Rename <dc:elements> to <dc:for-each>. We should have done this much earlier.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5517
diff changeset
509 log.debug("dc:for-each");
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
510
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
511 if (connectionsStack.isEmpty()) {
5525
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
512 log.debug("dc:for-each without having results");
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
513 return;
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
514 }
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
515
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
516 NodeList subs = current.getChildNodes();
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
517 int S = subs.getLength();
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
518
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
519 if (S == 0) {
5522
eeac800eb4cd Datacage: Rename <dc:elements> to <dc:for-each>. We should have done this much earlier.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5517
diff changeset
520 log.debug("dc:for-each has no children");
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
521 return;
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
522 }
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
523
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
524 Pair<Builder.NamedConnection, ResultData> pair =
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
525 connectionsStack.peek();
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
526
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
527 ResultData rd = pair.getB();
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
528
5525
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
529 String [] columns = rd.getColumnLabels();
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
530
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
531 for (Object [] row: rd.getRows()) {
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
532 frames.enter();
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
533 try {
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
534 frames.put(columns, row);
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
535 for (int i = 0; i < S; ++i) {
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
536 build(parent, subs.item(i));
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
537 }
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
538 }
5525
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
539 finally {
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
540 frames.leave();
fcf28185ca30 Datacage: Removed 'filter' attribute from <dc:for-each> because there is the <dc:filter> element now.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5522
diff changeset
541 }
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
542 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
543 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
544
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
545 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
546 * Create element.
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
547 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
548 protected void element(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
549 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
550 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
551 String attr = expand(current.getAttribute("name"));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
552
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
553 if (log.isDebugEnabled()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
554 log.debug("dc:element -> '" + attr + "'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
555 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
556
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
557 if (attr.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
558 log.warn("no name attribute found");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
559 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
560 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
561
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
562 Element element = owner.createElement(attr);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
563
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
564 NodeList children = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
565 for (int i = 0, N = children.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
566 build(element, children.item(i));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
567 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
568
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
569 parent.appendChild(element);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
570 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
571
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
572 protected void text(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
573 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
574 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
575 log.debug("dc:text");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
576 String value = expand(current.getTextContent());
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
577 parent.appendChild(owner.createTextNode(value));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
578 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
579
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
580 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
581 * Add attribute to an element
3571
64a59cca1887 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
582 * @see Element
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
583 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
584 protected void attribute(Node parent, Element current) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
585
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
586 if (parent.getNodeType() != Node.ELEMENT_NODE) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
587 log.warn("need element here");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
588 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
589 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
590
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
591 String name = expand(current.getAttribute("name"));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
592 String value = expand(current.getAttribute("value"));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
593
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
594 Element element = (Element)parent;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
595
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
596 element.setAttribute(name, value);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
597 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
598
4893
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
599 /**
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
600 * Call-Macro node.
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
601 * Evaluate child-nodes of the given macro element (not its text).
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
602 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
603 protected void callMacro(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
604 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
605 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
606 String name = current.getAttribute("name");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
607
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
608 if (name.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
609 log.warn("missing 'name' attribute in 'call-macro'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
610 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
611 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
612
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
613 Element macro = macros.get(name);
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
614
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
615 if (macro != null) {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
616 macroBodies.push(current.getChildNodes());
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
617 try {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
618 NodeList subs = macro.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
619 for (int j = 0, M = subs.getLength(); j < M; ++j) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
620 build(parent, subs.item(j));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
621 }
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
622 }
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
623 finally {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
624 macroBodies.pop();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
625 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
626 }
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
627 else {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
628 log.warn("no macro '" + name + "' found.");
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
629 }
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
630 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
631
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
632 protected void macroBody(Node parent, Element current)
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
633 throws SQLException
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
634 {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
635 if (!macroBodies.isEmpty()) {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
636 NodeList children = macroBodies.peek();
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
637 for (int i = 0, N = children.getLength(); i < N; ++i) {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
638 build(parent, children.item(i));
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
639 }
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
640 }
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
641 else {
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
642 log.warn("no current macro");
bf38ea4cb0f7 Added bodies to macros. Use the bodies of <dc:call-macro><body></dc:call-macro> as <dc:macro-body/> in tthe macro. Example:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
643 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
644 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
645
4896
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
646 /** Get macro node children, not resolving bodies. */
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
647 protected NodeList getMacroChildren(String name) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
648 NodeList macros = template.getElementsByTagNameNS(
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
649 DC_NAMESPACE_URI, "macro");
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
650
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
651 Element macro = null;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
652
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
653 for (int i = 0, N = macros.getLength(); i < N; ++i) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
654 Element m = (Element) macros.item(i);
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
655 if (name.equals(m.getAttribute("name"))) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
656 macro = m;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
657 break;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
658 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
659 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
660
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
661 if (macro != null) {
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
662 return macro.getChildNodes();
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
663 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
664 return null;
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
665 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
666
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
667 protected void ifClause(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
668 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
669 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
670 String test = current.getAttribute("test");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
671
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
672 if (test.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
673 log.warn("missing 'test' attribute in 'if'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
674 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
675 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
676
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
677 Boolean result = evaluateXPathToBoolean(test);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
678
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
679 if (result != null && result.booleanValue()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
680 NodeList subs = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
681 for (int i = 0, N = subs.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
682 build(parent, subs.item(i));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
683 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
684 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
685 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
686
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
687 protected void choose(Node parent, Element current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
688 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
689 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
690 Node branch = null;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
691
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
692 NodeList children = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
693 for (int i = 0, N = children.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
694 Node child = children.item(i);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
695 String ns = child.getNamespaceURI();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
696 if (ns == null
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
697 || !ns.equals(DC_NAMESPACE_URI)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
698 || child.getNodeType() != Node.ELEMENT_NODE
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
699 ) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
700 continue;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
701 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
702 String name = child.getLocalName();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
703 if ("when".equals(name)) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
704 Element when = (Element)child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
705 String test = when.getAttribute("test");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
706 if (test.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
707 log.warn("no 'test' attribute found for when");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
708 continue;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
709 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
710
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
711 Boolean result = evaluateXPathToBoolean(test);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
712 if (result != null && result.booleanValue()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
713 branch = child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
714 break;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
715 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
716
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
717 continue;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
718 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
719 else if ("otherwise".equals(name)) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
720 branch = child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
721 // No break here.
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
722 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
723 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
724
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
725 if (branch != null) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
726 NodeList subs = branch.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
727 for (int i = 0, N = subs.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
728 build(parent, subs.item(i));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
729 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
730 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
731 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
732
5449
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
733 protected XPathExpression getXPathExpression(String expr)
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
734 throws XPathExpressionException
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
735 {
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
736 XPathExpression x = expressions.get(expr);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
737 if (x == null) {
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
738 XPath xpath = XPATH_FACTORY.newXPath();
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
739 xpath.setXPathVariableResolver(frames);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
740 xpath.setXPathFunctionResolver(functionResolver);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
741 x = xpath.compile(expr);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
742 expressions.put(expr, x);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
743 }
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
744 return x;
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
745 }
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
746
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
747 protected Object evaluateXPath(String expr, QName returnType) {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
748
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
749 if (log.isDebugEnabled()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
750 log.debug("evaluate: '" + expr + "'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
751 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
752
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
753 try {
5449
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
754 XPathExpression x = getXPathExpression(expr);
504a62887217 Datacage: Compile XPath expressions and reuse them. With the introduction of filters in dc:elements XPath expressions are evalutated very often so compiling them should reduce the overhead significantly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5443
diff changeset
755 return x.evaluate(EVAL_DOCUMENT, returnType);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
756 }
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
757 catch (XPathExpressionException xpee) {
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
758 log.error("expression: " + expr, xpee);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
759 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
760 return null;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
761 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
762
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
763 protected Boolean evaluateXPathToBoolean(String expr) {
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
764
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
765 Object result = evaluateXPath(expr, XPathConstants.BOOLEAN);
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
766
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
767 return result instanceof Boolean
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
768 ? (Boolean)result
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
769 : null;
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
770 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
771
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
772 protected void convert(Element current) {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
773
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
774 String variable = expand(current.getAttribute("var"));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
775 String type = expand(current.getAttribute("type"));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
776
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
777 Object [] result = new Object[1];
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
778
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
779 if (frames.getStore(variable, result)) {
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
780 Object object = TypeConverter.convert(result[0], type);
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
781 frames.put(variable.toUpperCase(), object);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
782 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
783 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
784
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
785
4891
089bc08f720e Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4890
diff changeset
786 /** Put <dc:variable> content as variable on stackframes. */
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
787 protected void variable(Element current) {
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
788
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
789 String varName = expand(current.getAttribute("name"));
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
790 String expr = current.getAttribute("expr");
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
791 String type = current.getAttribute("type");
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
792
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
793 if (varName.length() == 0 || expr.length() == 0) {
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
794 log.error("dc:variable 'name' or 'expr' empty.");
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
795 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
796 else {
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
797 frames.put(
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
798 varName.toUpperCase(),
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
799 evaluateXPath(expr, typeToQName(type)));
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
800 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
801 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
802
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
803 protected String expand(String s) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
804 Matcher m = CompiledStatement.VAR.matcher(s);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
805
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
806 Object [] result = new Object[1];
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
807
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
808 StringBuffer sb = new StringBuffer();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
809 while (m.find()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
810 String key = m.group(1);
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
811 result[0] = null;
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
812 if (frames.getStore(key, result)) {
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
813 m.appendReplacement(
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
814 sb, result[0] != null ? result[0].toString() : "");
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
815 }
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
816 else {
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
817 m.appendReplacement(sb, "\\${" + key + "}");
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
818 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
819 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
820 m.appendTail(sb);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
821 return sb.toString();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
822 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
823
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
824 protected void evaluateAttributeValue(Attr attr) {
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
825 String value = attr.getValue();
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
826 if (value.indexOf('{') >= 0) {
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
827 StringBuffer sb = new StringBuffer();
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
828 Matcher m = BRACKET_XPATH.matcher(value);
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
829 while (m.find()) {
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
830 String expr = m.group(1);
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
831 Object result = evaluateXPath(expr, XPathConstants.STRING);
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
832 if (result instanceof String) {
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
833 m.appendReplacement(sb, (String)result);
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
834 }
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
835 else {
5532
55529f586962 Fixed replacement for unresolved variables in templating builder.
Raimund Renkert <rrenkert@intevation.de>
parents: 5531
diff changeset
836 m.appendReplacement(sb, "");
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
837 }
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
838 }
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
839 m.appendTail(sb);
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
840 attr.setValue(sb.toString());
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
841 }
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
842 }
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
843
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
844 protected void build(Node parent, Node current)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
845 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
846 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
847 String ns = current.getNamespaceURI();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
848 if (ns != null && ns.equals(DC_NAMESPACE_URI)) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
849 if (current.getNodeType() != Node.ELEMENT_NODE) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
850 log.warn("need elements here");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
851 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
852 else {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
853 String localName = current.getLocalName();
5517
5800a9497b0b Fix syntax error in builder.
Andre Heinecke <aheinecke@intevation.de>
parents: 5509
diff changeset
854 Element curr = (Element)current;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
855 if ("attribute".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
856 attribute(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
857 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
858 else if ("context".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
859 context(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
860 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
861 else if ("if".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
862 ifClause(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
863 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
864 else if ("choose".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
865 choose(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
866 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
867 else if ("call-macro".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
868 callMacro(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
869 }
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
870 else if ("macro-body".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
871 macroBody(parent, curr);
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:
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4740
diff changeset
872 }
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
873 else if ("macro".equals(localName)
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
874 || "comment".equals(localName)
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
875 || "statement".equals(localName)) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
876 // Simply ignore them.
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
877 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
878 else if ("element".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
879 element(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
880 }
5522
eeac800eb4cd Datacage: Rename <dc:elements> to <dc:for-each>. We should have done this much earlier.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5517
diff changeset
881 else if ("for-each".equals(localName)) {
eeac800eb4cd Datacage: Rename <dc:elements> to <dc:for-each>. We should have done this much earlier.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5517
diff changeset
882 foreach(parent, curr);
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
883 }
5974
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
884 else if ("iterate".equals(localName)) {
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
885 iterate(parent, curr);
95cb104a871b Add dc:iterate function
Andre Heinecke <aheinecke@intevation.de>
parents: 5892
diff changeset
886 }
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
887 else if ("filter".equals(localName)) {
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
888 filter(parent, curr);
1023
5cb84ceee2a0 Datacage: Templates now can nest <dc:elements> into other elements in the body of <dc:context>
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
889 }
5890
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
890 else if ("group".equals(localName)) {
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
891 group(parent, curr);
6ea004d51203 Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5887
diff changeset
892 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
893 else if ("text".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
894 text(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
895 }
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
896 else if ("variable".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
897 variable(curr);
1017
8637756275e5 Added a <dc:comment> tag to place comments in the meta data templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1015
diff changeset
898 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
899 else if ("convert".equals(localName)) {
5509
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
900 convert(curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
901 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
902 else {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
903 log.warn("unknown '" + localName + "' -> ignore");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
904 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
905 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
906 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
907 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
908
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
909 if (current.getNodeType() == Node.TEXT_NODE) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
910 String txt = current.getNodeValue();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
911 if (txt != null && txt.trim().length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
912 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
913 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
914 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
915
4353
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
916 if (current.getNodeType() == Node.COMMENT_NODE) {
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
917 // Ignore XML comments
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
918 return;
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
919 }
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
920
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
921 Node copy = owner.importNode(current, false);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
922
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
923 NodeList children = current.getChildNodes();
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
924 for (int i = 0, N = children.getLength(); i < N; ++i) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
925 build(copy, children.item(i));
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
926 }
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
927 if (copy.getNodeType() == Node.ELEMENT_NODE) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
928 NamedNodeMap nnm = ((Element)copy).getAttributes();
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
929 for (int i = 0, N = nnm.getLength(); i < N; ++i) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
930 Node n = nnm.item(i);
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
931 if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
932 evaluateAttributeValue((Attr)n);
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
933 }
5485
3b5e1535a459 Datacage: Experimental support for '{XPath}' expressions in attributes similiar to XSLT. Using this feature you can shorten the written template a lot because it reduces the necessity to create dynamic attributes with <dc:attribute>.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5449
diff changeset
934 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
935 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
936 parent.appendChild(copy);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
937 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
938 } // class BuildHelper
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
939
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
940
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
941 public Builder() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
942 compiledStatements = new HashMap<String, CompiledStatement>();
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
943 macros = new HashMap<String, Element>();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
944 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
945
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
946 public Builder(Document template) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
947 this();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
948 this.template = template;
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
949 extractMacros();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
950 compileStatements();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
951 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
952
4740
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
953 protected static QName typeToQName(String type) {
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
954 if ("number" .equals(type)) return XPathConstants.NUMBER;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
955 if ("bool" .equals(type)) return XPathConstants.BOOLEAN;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
956 if ("node" .equals(type)) return XPathConstants.NODE;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
957 if ("nodeset".equals(type)) return XPathConstants.NODESET;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
958 return XPathConstants.STRING;
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
959 }
fb135e1dfa35 Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4737
diff changeset
960
4614
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4526
diff changeset
961 /** Handle <dc:statement> elements. */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
962 protected void compileStatements() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
963
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
964 NodeList nodes = template.getElementsByTagNameNS(
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
965 DC_NAMESPACE_URI, "statement");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
966
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
967 for (int i = 0, N = nodes.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
968 Element stmntElement = (Element)nodes.item(i);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
969 String stmnt = trimStatement(stmntElement.getTextContent());
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
970 if (stmnt == null || stmnt.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
971 throw new IllegalArgumentException("found empty statement");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
972 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
973 CompiledStatement cs = new CompiledStatement(stmnt);
1029
3f3988bb6284 Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1023
diff changeset
974 // For faster lookup store a shortend string into the template.
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
975 stmnt = "s" + i;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
976 stmntElement.setTextContent(stmnt);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
977 compiledStatements.put(stmnt, cs);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
978 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
979 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
980
5443
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
981 protected void extractMacros() {
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
982 NodeList ms = template.getElementsByTagNameNS(
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
983 DC_NAMESPACE_URI, "macro");
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
984
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
985 for (int i = 0, N = ms.getLength(); i < N; ++i) {
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
986 Element m = (Element)ms.item(i);
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
987 macros.put(m.getAttribute("name"), m);
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
988 }
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
989 }
3d7e552cc396 Datacage: Index macros with a map. Reduces excessive linear scanning for macros when calling them.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5442
diff changeset
990
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
991 protected List<Node> rootsToList() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
992
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
993 NodeList roots = template.getElementsByTagNameNS(
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
994 DC_NAMESPACE_URI, "template");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
995
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
996 List<Node> elements = new ArrayList<Node>();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
997
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
998 for (int i = 0, N = roots.getLength(); i < N; ++i) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
999 NodeList rootChildren = roots.item(i).getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1000 for (int j = 0, M = rootChildren.getLength(); j < M; ++j) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1001 Node child = rootChildren.item(j);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1002 if (child.getNodeType() == Node.ELEMENT_NODE) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1003 elements.add(child);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1004 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1005 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1006 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1007
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1008 return elements;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1009 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1010
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1011 protected static final String trimStatement(String stmnt) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1012 if (stmnt == null) return null;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1013 //XXX: Maybe a bit to radical for multiline strings?
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1014 return STRIP_LINE_INDENT.matcher(stmnt.trim()).replaceAll(" ");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1015 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1016
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1017 protected static Document getOwnerDocument(Node node) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1018 Document document = node.getOwnerDocument();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1019 return document != null ? document : (Document)node;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1020 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1021
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1022 public void build(
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1023 List<NamedConnection> connections,
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1024 Node output,
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1025 Map<String, Object> parameters
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1026 )
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1027 throws SQLException
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
1028 {
5887
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1029 long startTime = System.currentTimeMillis();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1030 try {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1031 BuildHelper helper =
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1032 new BuildHelper(output, connections, parameters);
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1033 helper.build();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1034 }
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1035 finally {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1036 if (log.isDebugEnabled()) {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1037 long stopTime = System.currentTimeMillis();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1038 log.debug("Building the datacage result took " +
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1039 (stopTime-startTime)/1000f + " secs.");
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1040 }
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
1041 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1042 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1043 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1044 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org