annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 5892:9a3ca7532f2a

Datacage: Repaired and simplified dc:filter code.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 02 May 2013 21:23:44 +0200
parents 6ea004d51203
children 95cb104a871b
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 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
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
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
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;
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
20 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
21 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
22 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
23 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
24 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
25 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
26
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
27 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
28 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
29
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 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
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.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
33 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
34 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
35 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
36 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
37
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 import org.apache.log4j.Logger;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
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
40 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
41 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
42 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
43 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
44 import org.w3c.dom.NodeList;
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
45 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
46
4526
1f38fa929986 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4353
diff changeset
47
4897
9c388de4b4d5 Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4896
diff changeset
48 /** 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
49 public class Builder
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 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
52
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 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
54 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
55
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
56 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
57 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
58
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 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
60 "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
61
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 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
63 XMLUtils.newDocument();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 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
66 XPathFactory.newInstance();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 protected Document template;
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 Map<String, CompiledStatement> compiledStatements;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
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
72 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
73
4526
1f38fa929986 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4353
diff changeset
74 /** 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
75 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
76
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
77 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
78 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
79 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
80
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
81 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
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
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
84 public NamedConnection(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1890
diff changeset
85 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
86 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
87 ) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
88 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
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
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
91 public NamedConnection(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1890
diff changeset
92 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
93 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
94 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
95 ) {
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
96 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
97 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
98 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
99 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
100 } // 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
101
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 public class BuildHelper
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 {
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 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
117 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
118 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
119 Map<String, Object> parameters
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 ) {
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
121 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
122 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
123 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
124
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
125 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
126 connectionsStack =
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 public void build() throws SQLException {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 try {
5779
ebec12def170 Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5532
diff changeset
141 // 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
142 //synchronized (template) {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 for (Node current: rootsToList()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 build(output, current);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 }
5779
ebec12def170 Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5532
diff changeset
146 //}
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 finally {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 closeStatements();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 }
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 protected void closeStatements() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 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
155 csi.close();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 statements.clear();
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
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
160 /**
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
161 * Return first statement node in NodeList, respecting
4897
9c388de4b4d5 Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4896
diff changeset
162 * 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
163 */
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
164 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
165 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
166
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 // 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
168 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
169 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
170 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
171 // 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
172 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
173 && 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
174 && (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
175 && 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
176 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
177 }
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 // 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
179 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
180 && 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
181 && (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
182 && 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
183
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 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
185 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
186 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
187 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
188 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
189 }
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 }
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 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
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
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 /**
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
198 * Handle a dc:context node.
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
199 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 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
201 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 {
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
203 log.debug("dc:context");
998
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 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
206 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
207 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
208
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 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
210 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
211 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
214 String stmntText = stmntNode.getTextContent();
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
215
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
216 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
217
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 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
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 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
221
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 if (csi == null) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 CompiledStatement cs = compiledStatements.get(stmntText);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 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
225 statements.put(key, csi);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
228 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
229 ? 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
230 : connectionsStack.peek().getA();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
232 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
233 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
234 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
235 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
236 break;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
239 }
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
240
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
241 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
242 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
243 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
244 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
245
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
246 // 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
247 if (!rd.isEmpty()) {
4051
58bdf95df5e4 More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3571
diff changeset
248 connectionsStack.push(
58bdf95df5e4 More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3571
diff changeset
249 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
250 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
251 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
252 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
253 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254 }
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
255 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
256 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
257 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 }
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
259 }
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
260
5433
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
261 public boolean hasResult() {
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
262 return !connectionsStack.isEmpty()
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
263 && !connectionsStack.peek().getB().isEmpty();
df32d7518f55 Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5432
diff changeset
264 }
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
265
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
266 protected ResultData createFilteredResultData(
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
267 ResultData rd,
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
268 String filter
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
269 ) {
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
270 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
271
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
272 XPathExpression x;
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
273 try {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
274 x = getXPathExpression(filter);
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
275 }
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
276 catch (XPathExpressionException xee) {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
277 log.warn("Invalid filter expression '" + filter + "'.");
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
278 return rd;
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
279 }
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
280
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
281 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
282 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
283
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
284 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
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 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
287 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
288 try {
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.put(columns, row);
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
290 Object result = x.evaluate(
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
291 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
292
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
293 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
294 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
295 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
296 }
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
297 catch (XPathExpressionException xee) {
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
298 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
299 filter + "' to dataset.");
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
300 }
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
301 finally {
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
302 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
303 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
304 }
5892
9a3ca7532f2a Datacage: Repaired and simplified dc:filter code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5890
diff changeset
305 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
306 }
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
307
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
308 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
309 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
310 {
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 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
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 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
314 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
315 }
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
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 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
318 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
319 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
320 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
321 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
322 }
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
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 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
325 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
326
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 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
328 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
329 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
330 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
331 }
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
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 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
334 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
335 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
336 }
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 }
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 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
339 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
340 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
341 }
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 }
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
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
345 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
346 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
347 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
348 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
349 ) {
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
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 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
352 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
353
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 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
355 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
356 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
357 }
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 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
359 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
360 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
361 }
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 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
364
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 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
366
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 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
368 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
369 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
370 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
371
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 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
373
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 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
375
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 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
377 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
378 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
379 }
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 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
382 }
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 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
384 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
385 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
386 }
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 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
388 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
389 }
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 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
392 }
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 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
395 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
396 {
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 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
398
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 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
400 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
401 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
402 }
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 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
405 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
406
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 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
408 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
409 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
410 }
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 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
413 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
414
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 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
416 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
417
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 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
419
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 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
421 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
422
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 String [] columns = orig.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
424
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 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
426 for (Map.Entry<Object, ResultData> entry: groups.entrySet()) {
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 ResultData rd = entry.getValue();
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
428 pair.setB(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
429 groupExprStack.push(entry.getKey());
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 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
431 for (Object [] row: 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
432 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
433 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
434 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
435 for (int i = 0; i < S; ++i) {
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
436 build(parent, subs.item(i));
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
437 }
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 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
440 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
441 }
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 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
445 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
446 }
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 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
450 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
451 }
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 }
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
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 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
455 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
456 ? 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
457 : 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
458 }
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
459
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
460 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
461 * Kind of foreach over results of a statement within a context.
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
462 */
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
463 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
464 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
465 {
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
466 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
467
1818
e3eb1ea885a7 Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
468 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
469 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
470 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
471 }
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
472
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
473 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
474 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
475
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
476 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
477 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
478 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
479 }
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
480
5305
e60f65540cc2 Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents: 4897
diff changeset
481 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
482 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
483
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
484 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
485
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
486 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
487
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
488 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
489 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
490 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
491 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
492 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
493 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
494 }
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
495 }
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
496 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
497 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
498 }
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
499 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
500 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
501
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
502 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
503 * Create element.
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
504 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
505 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
506 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
507 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
508 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
509
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
510 if (log.isDebugEnabled()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
511 log.debug("dc:element -> '" + attr + "'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
512 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
513
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
514 if (attr.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
515 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
516 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
517 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
518
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
519 Element element = owner.createElement(attr);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
520
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
521 NodeList children = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
522 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
523 build(element, children.item(i));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
524 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
525
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
526 parent.appendChild(element);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
527 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
528
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
529 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
530 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
531 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
532 log.debug("dc:text");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
533 String value = expand(current.getTextContent());
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
534 parent.appendChild(owner.createTextNode(value));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
535 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
536
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
537 /**
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
538 * Add attribute to an element
3571
64a59cca1887 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
539 * @see Element
1890
9144e5a5027b (Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1859
diff changeset
540 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
541 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
542
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
543 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
544 log.warn("need element here");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
545 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
546 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
547
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
548 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
549 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
550
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
551 Element element = (Element)parent;
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 element.setAttribute(name, value);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
554 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
555
4893
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
556 /**
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
557 * Call-Macro node.
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
558 * Evaluate child-nodes of the given macro element (not its text).
54762b8ef016 Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4891
diff changeset
559 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
560 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
561 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
562 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
563 String name = current.getAttribute("name");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
564
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
565 if (name.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
566 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
567 return;
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
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
570 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
571
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
572 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
573 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
574 try {
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
575 NodeList subs = macro.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
576 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
577 build(parent, subs.item(j));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
578 }
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
579 }
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
580 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
581 macroBodies.pop();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
582 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
583 }
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
584 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
585 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
586 }
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
587 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
588
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
589 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
590 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
591 {
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
592 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
593 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
594 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
595 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
596 }
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
597 }
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
598 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
599 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
600 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
601 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
602
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
603 /** 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
604 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
605 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
606 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
607
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
608 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
609
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
610 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
611 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
612 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
613 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
614 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
615 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
616 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
617
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
618 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
619 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
620 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
621 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
622 }
27d58b7b5edd Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4893
diff changeset
623
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
624 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
625 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
626 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
627 String test = current.getAttribute("test");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
628
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
629 if (test.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
630 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
631 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
632 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
633
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
634 Boolean result = evaluateXPathToBoolean(test);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
635
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
636 if (result != null && result.booleanValue()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
637 NodeList subs = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
638 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
639 build(parent, subs.item(i));
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
640 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
641 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
642 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
643
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
644 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
645 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
646 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
647 Node branch = null;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
648
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
649 NodeList children = current.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
650 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
651 Node child = children.item(i);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
652 String ns = child.getNamespaceURI();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
653 if (ns == null
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
654 || !ns.equals(DC_NAMESPACE_URI)
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
655 || child.getNodeType() != Node.ELEMENT_NODE
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
656 ) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
657 continue;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
658 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
659 String name = child.getLocalName();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
660 if ("when".equals(name)) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
661 Element when = (Element)child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
662 String test = when.getAttribute("test");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
663 if (test.length() == 0) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
664 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
665 continue;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
666 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
667
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
668 Boolean result = evaluateXPathToBoolean(test);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
669 if (result != null && result.booleanValue()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
670 branch = child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
671 break;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
672 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
673
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
674 continue;
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 else if ("otherwise".equals(name)) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
677 branch = child;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
678 // No break here.
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
679 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
680 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
681
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
682 if (branch != null) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
683 NodeList subs = branch.getChildNodes();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
684 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
685 build(parent, subs.item(i));
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 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
688 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
689
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
690 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
691 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
692 {
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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700 }
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
701 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
702 }
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
703
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
704 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
705
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
706 if (log.isDebugEnabled()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
707 log.debug("evaluate: '" + expr + "'");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
708 }
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 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
711 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
712 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
713 }
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
714 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
715 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
716 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
717 return null;
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
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
720 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
721
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
722 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
723
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
724 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
725 ? (Boolean)result
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
726 : null;
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
727 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
728
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
729 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
730
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
731 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
732 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
733
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
734 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
735
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
736 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
737 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
738 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
739 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
740 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
741
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
742
4891
089bc08f720e Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4890
diff changeset
743 /** 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
744 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
745
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
746 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
747 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
748 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
749
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
750 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
751 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
752 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
753 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
754 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
755 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
756 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
757 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
758 }
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
759
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
760 protected String expand(String s) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
761 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
762
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
763 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
764
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
765 StringBuffer sb = new StringBuffer();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
766 while (m.find()) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
767 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
768 result[0] = null;
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
769 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
770 m.appendReplacement(
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
771 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
772 }
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
773 else {
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
774 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
775 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
776 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
777 m.appendTail(sb);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
778 return sb.toString();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
779 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
780
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
781 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
782 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
783 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
784 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
785 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
786 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
787 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
788 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
789 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
790 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
791 }
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
792 else {
5532
55529f586962 Fixed replacement for unresolved variables in templating builder.
Raimund Renkert <rrenkert@intevation.de>
parents: 5531
diff changeset
793 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
794 }
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
795 }
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
796 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
797 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
798 }
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
799 }
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
800
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
801 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
802 throws SQLException
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
803 {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
804 String ns = current.getNamespaceURI();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
805 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
806 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
807 log.warn("need elements here");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
808 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
809 else {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
810 String localName = current.getLocalName();
5517
5800a9497b0b Fix syntax error in builder.
Andre Heinecke <aheinecke@intevation.de>
parents: 5509
diff changeset
811 Element curr = (Element)current;
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
812 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
813 attribute(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
814 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
815 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
816 context(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
817 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
818 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
819 ifClause(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
820 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
821 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
822 choose(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
823 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
824 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
825 callMacro(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
826 }
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
827 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
828 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
829 }
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
830 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
831 || "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
832 || "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
833 // Simply ignore them.
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
834 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
835 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
836 element(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
837 }
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
838 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
839 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
840 }
627584bc0586 Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5494
diff changeset
841 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
842 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
843 }
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
844 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
845 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
846 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
847 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
848 text(parent, curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
849 }
4737
718adea968e2 Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4614
diff changeset
850 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
851 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
852 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
853 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
854 convert(curr);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
855 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
856 else {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
857 log.warn("unknown '" + localName + "' -> ignore");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
858 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
859 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
860 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
861 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
862
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
863 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
864 String txt = current.getNodeValue();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
865 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
866 return;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
867 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
868 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
869
4353
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
870 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
871 // Ignore XML comments
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
872 return;
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
873 }
daf0919df76d Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4051
diff changeset
874
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
875 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
876
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
877 NodeList children = current.getChildNodes();
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
878 for (int i = 0, N = children.getLength(); i < N; ++i) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
879 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
880 }
5494
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
881 if (copy.getNodeType() == Node.ELEMENT_NODE) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
882 NamedNodeMap nnm = ((Element)copy).getAttributes();
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
883 for (int i = 0, N = nnm.getLength(); i < N; ++i) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
884 Node n = nnm.item(i);
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
885 if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
886 evaluateAttributeValue((Attr)n);
773899d00234 Fix new attribute evaluation
Andre Heinecke <aheinecke@intevation.de>
parents: 5485
diff changeset
887 }
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
888 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
889 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
890 parent.appendChild(copy);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
891 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
892 } // class BuildHelper
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
893
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
894
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
895 public Builder() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
896 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
897 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
898 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
899
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
900 public Builder(Document template) {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
901 this();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
902 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
903 extractMacros();
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
904 compileStatements();
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
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
907 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
908 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
909 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
910 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
911 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
912 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
913 }
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
914
4614
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4526
diff changeset
915 /** Handle <dc:statement> elements. */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
916 protected void compileStatements() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
917
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
918 NodeList nodes = template.getElementsByTagNameNS(
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
919 DC_NAMESPACE_URI, "statement");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
920
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
921 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
922 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
923 String stmnt = trimStatement(stmntElement.getTextContent());
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
924 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
925 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
926 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
927 CompiledStatement cs = new CompiledStatement(stmnt);
1029
3f3988bb6284 Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1023
diff changeset
928 // 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
929 stmnt = "s" + i;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
930 stmntElement.setTextContent(stmnt);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
931 compiledStatements.put(stmnt, cs);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
932 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
933 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
934
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
935 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
936 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
937 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
938
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
939 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
940 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
941 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
942 }
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 }
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
944
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
945 protected List<Node> rootsToList() {
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
946
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
947 NodeList roots = template.getElementsByTagNameNS(
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
948 DC_NAMESPACE_URI, "template");
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
949
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
950 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
951
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
952 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
953 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
954 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
955 Node child = rootChildren.item(j);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
956 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
957 elements.add(child);
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
958 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
959 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
960 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
961
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
962 return elements;
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
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
965 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
966 if (stmnt == null) return null;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
967 //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
968 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
969 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
970
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
971 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
972 Document document = node.getOwnerDocument();
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
973 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
974 }
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
975
1011
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
976 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
977 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
978 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
979 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
980 )
aca3b46160cb Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
981 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
982 {
5887
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
983 long startTime = System.currentTimeMillis();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
984 try {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
985 BuildHelper helper =
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
986 new BuildHelper(output, connections, parameters);
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
987 helper.build();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
988 }
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
989 finally {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
990 if (log.isDebugEnabled()) {
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
991 long stopTime = System.currentTimeMillis();
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
992 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
993 (stopTime-startTime)/1000f + " secs.");
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
994 }
88fca576e9e6 Datacage: Added some time meassuremnt for templating.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
995 }
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
996 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org