Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java @ 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>.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 28 Mar 2013 08:03:14 +0100 |
parents | 504a62887217 |
children | 773899d00234 |
rev | line source |
---|---|
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.datacage.templating; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.artifacts.common.utils.XMLUtils; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
1818
e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
5 import de.intevation.flys.utils.Pair; |
e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
6 |
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
|
7 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
|
8 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
|
9 |
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
|
10 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
|
11 import java.util.ArrayList; |
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
|
12 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
|
13 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
|
14 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
|
15 import java.util.Map; |
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 |
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 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
|
18 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
|
19 |
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
|
20 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
|
21 |
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 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 import org.apache.log4j.Logger; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 import org.w3c.dom.NodeList; |
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 |
4526
1f38fa929986
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4353
diff
changeset
|
36 |
4897
9c388de4b4d5
Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4896
diff
changeset
|
37 /** 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
|
38 public class Builder |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 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
|
41 |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1011
diff
changeset
|
42 public static final String CONNECTION_USER = "user"; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1011
diff
changeset
|
43 public static final String CONNECTION_SYSTEM = "system"; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1011
diff
changeset
|
44 public static final String DEFAULT_CONNECTION_NAME = CONNECTION_SYSTEM; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1011
diff
changeset
|
45 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
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
|
49 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
|
50 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
|
51 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 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
|
53 "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
|
54 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 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
|
56 XMLUtils.newDocument(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 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
|
59 XPathFactory.newInstance(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 protected Document template; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 protected Map<String, CompiledStatement> compiledStatements; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
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
|
65 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
|
66 |
4526
1f38fa929986
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4353
diff
changeset
|
67 /** 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
|
68 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
|
69 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
74 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
|
75 } |
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 public NamedConnection( |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
78 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
|
79 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
|
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 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
|
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 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
|
88 ) { |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 } |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
93 } // 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
|
94 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 public class BuildHelper |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 { |
1818
e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 protected Deque<NodeList> macroBodies; |
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
|
104 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
|
105 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
|
106 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 Map<String, Object> parameters |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 ) { |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
113 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
|
114 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
|
115 } |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
116 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
117 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
|
118 connectionsStack = |
e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 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
|
123 macroBodies = new ArrayDeque<NodeList>(); |
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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 public void build() throws SQLException { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 try { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 synchronized (template) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 for (Node current: rootsToList()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 build(output, current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
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 finally { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 closeStatements(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 protected void closeStatements() { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 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
|
145 csi.close(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 statements.clear(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
150 /** |
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
|
151 * Return first statement node in NodeList, respecting |
4897
9c388de4b4d5
Builder: Doc, comments.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4896
diff
changeset
|
152 * 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
|
153 */ |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
154 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
|
155 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
|
156 |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
157 // 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
|
158 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
|
159 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
|
160 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
|
161 // 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
|
162 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
|
163 && 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
|
164 && (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
|
165 && 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
|
166 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
|
167 } |
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 // 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
|
169 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
|
170 && 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
|
171 && (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
|
172 && 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
|
173 |
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 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
180 } |
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 |
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 } |
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 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
|
185 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
186 |
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 /** |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
188 * Handle a \<context\> node. |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
189 */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 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
|
191 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 { |
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
|
193 log.debug("dc:context"); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 |
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
|
195 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
|
196 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
|
197 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
|
198 |
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
|
199 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
|
200 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
|
201 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
204 String stmntText = stmntNode.getTextContent(); |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
205 |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
206 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
|
207 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
208 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
|
209 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
210 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
|
211 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 if (csi == null) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 CompiledStatement cs = compiledStatements.get(stmntText); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 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
|
215 statements.put(key, csi); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
218 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
|
219 ? 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
|
220 : connectionsStack.peek().getA(); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 break; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 } |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
229 } |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
230 |
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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 |
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
|
236 // 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
|
237 if (!rd.isEmpty()) { |
4051
58bdf95df5e4
More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3571
diff
changeset
|
238 connectionsStack.push( |
58bdf95df5e4
More dead code removal. Minor code clean ups.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3571
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
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
|
245 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
|
246 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
|
247 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
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
|
249 } |
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 |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
251 public boolean hasResult() { |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
252 return !connectionsStack.isEmpty() |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
253 && !connectionsStack.peek().getB().isEmpty(); |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
254 } |
5305
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
255 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
256 protected ResultData createFilteredResultData(ResultData rd, String filter) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
257 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
|
258 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
259 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
|
260 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
|
261 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
262 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
|
263 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
264 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
|
265 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
|
266 try { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
267 frames.put(columns, row); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
268 boolean traverse = filter == null; |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
269 |
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 (!traverse) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
271 Boolean b = evaluateXPathToBoolean(filter); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
272 traverse = b != null && b; |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
273 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
274 if (traverse) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
275 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
|
276 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
277 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
278 finally { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
279 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
|
280 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
281 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
282 return new ResultData(rd.getColumnLabels(), filtered); |
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 |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
285 /** |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
286 * Kind of foreach over results of a statement within a context. |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
287 */ |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
288 protected void elements(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
|
289 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
|
290 { |
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
|
291 log.debug("dc:elements"); |
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
|
292 |
1818
e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
293 if (connectionsStack.isEmpty()) { |
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
|
294 log.warn("dc:elements without having 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
|
295 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
|
296 } |
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
|
297 |
5305
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
298 String filter = current.getAttribute("filter"); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
299 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
300 if ((filter = filter.trim()).length() == 0) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
301 filter = null; |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
302 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
303 |
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
|
304 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
|
305 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
|
306 |
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
|
307 if (S == 0) { |
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
|
308 log.debug("dc:elements has no children"); |
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
|
309 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
|
310 } |
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
|
311 |
5305
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
312 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
|
313 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
|
314 |
5305
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
315 ResultData rd = connectionsStack.peek().getB(); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
316 ResultData orig = rd; |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
317 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
318 if (filter != null) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
319 ResultData rdCopy = createFilteredResultData(rd, filter); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
320 pair.setB(rdCopy); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
321 rd = rdCopy; |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
322 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
323 try { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
324 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
|
325 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
326 //if (log.isDebugEnabled()) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
327 // log.debug("pushing vars: " |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
328 // + java.util.Arrays.toString(columns)); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
329 //} |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
330 |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
331 for (Object [] row: 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
|
332 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
|
333 try { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
334 frames.put(columns, row); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
335 //if (log.isDebugEnabled()) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
336 // log.debug("current vars: " + frames.dump()); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
337 //} |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
338 for (int i = 0; i < S; ++i) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
339 build(parent, subs.item(i)); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
340 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
341 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
342 finally { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
343 frames.leave(); |
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
|
344 } |
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
|
345 } |
5305
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
346 } |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
347 finally { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
348 if (filter != null) { |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
349 pair.setB(orig); |
e60f65540cc2
Added filter to elements in datacage templating. (most work done by Sascha T.).
Raimund Renkert <rrenkert@intevation.de>
parents:
4897
diff
changeset
|
350 } |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
351 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
353 |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
354 /** |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
355 * Create element. |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
356 */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
357 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
|
358 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
359 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
360 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
|
361 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
362 if (log.isDebugEnabled()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
363 log.debug("dc:element -> '" + attr + "'"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
364 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
365 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
366 if (attr.length() == 0) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
367 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
|
368 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
369 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
371 Element element = owner.createElement(attr); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
373 NodeList children = current.getChildNodes(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 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
|
375 build(element, children.item(i)); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
376 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
377 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
378 parent.appendChild(element); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
380 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 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
|
382 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
384 log.debug("dc:text"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 String value = expand(current.getTextContent()); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 parent.appendChild(owner.createTextNode(value)); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
387 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
388 |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
389 /** |
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
390 * Add attribute to an element |
3571
64a59cca1887
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
391 * @see Element |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1859
diff
changeset
|
392 */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
393 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
|
394 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
395 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
|
396 log.warn("need element here"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
400 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
|
401 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
|
402 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 Element element = (Element)parent; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
405 element.setAttribute(name, value); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 |
4893
54762b8ef016
Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4891
diff
changeset
|
408 /** |
54762b8ef016
Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4891
diff
changeset
|
409 * Call-Macro node. |
54762b8ef016
Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4891
diff
changeset
|
410 * Evaluate child-nodes of the given macro element (not its text). |
54762b8ef016
Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4891
diff
changeset
|
411 */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
412 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
|
413 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 String name = current.getAttribute("name"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 if (name.length() == 0) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
418 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
|
419 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
420 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 |
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
|
422 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
|
423 |
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
|
424 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
|
425 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
|
426 try { |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
427 NodeList subs = macro.getChildNodes(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
428 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
|
429 build(parent, subs.item(j)); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 } |
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
|
431 } |
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
|
432 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
|
433 macroBodies.pop(); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
434 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
435 } |
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
|
436 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
|
437 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
|
438 } |
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
|
439 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
440 |
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
|
441 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
|
442 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
|
443 { |
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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 } |
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
|
449 } |
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
|
450 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
|
451 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
|
452 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
453 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
454 |
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
|
455 /** 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
|
456 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
|
457 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
|
458 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
|
459 |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
460 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
|
461 |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
468 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
469 |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
470 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
|
471 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
|
472 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
473 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
|
474 } |
27d58b7b5edd
Builder: When looking for a statement in contexts, also search in macro definitions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4893
diff
changeset
|
475 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
476 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
|
477 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
478 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
479 String test = current.getAttribute("test"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
480 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
481 if (test.length() == 0) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
482 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
|
483 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
484 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
485 |
4737
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
486 Boolean result = evaluateXPathToBoolean(test); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
487 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
488 if (result != null && result.booleanValue()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
489 NodeList subs = current.getChildNodes(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
490 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
|
491 build(parent, subs.item(i)); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
492 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
493 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
494 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
495 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
496 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
|
497 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
498 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
499 Node branch = null; |
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 NodeList children = current.getChildNodes(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
502 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
|
503 Node child = children.item(i); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
504 String ns = child.getNamespaceURI(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
505 if (ns == null |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
506 || !ns.equals(DC_NAMESPACE_URI) |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
507 || child.getNodeType() != Node.ELEMENT_NODE |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
508 ) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
509 continue; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
510 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
511 String name = child.getLocalName(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
512 if ("when".equals(name)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
513 Element when = (Element)child; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
514 String test = when.getAttribute("test"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
515 if (test.length() == 0) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
516 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
|
517 continue; |
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 |
4737
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
520 Boolean result = evaluateXPathToBoolean(test); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
521 if (result != null && result.booleanValue()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
522 branch = child; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
523 break; |
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 continue; |
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 else if ("otherwise".equals(name)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
529 branch = child; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
530 // No break here. |
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 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
533 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
534 if (branch != null) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
535 NodeList subs = branch.getChildNodes(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
536 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
|
537 build(parent, subs.item(i)); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
538 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
539 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
540 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
541 |
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
|
542 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
|
543 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
|
544 { |
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
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 } |
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
|
553 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
|
554 } |
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
|
555 |
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
|
556 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
|
557 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
558 if (log.isDebugEnabled()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
559 log.debug("evaluate: '" + expr + "'"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
560 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
561 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 } |
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
|
566 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
|
567 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
|
568 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
569 return null; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
570 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
571 |
4737
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
572 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
|
573 |
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
|
574 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
|
575 |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
576 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
|
577 ? (Boolean)result |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
578 : null; |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
579 } |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
580 |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
581 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
|
582 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
583 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
|
584 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
|
585 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
586 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
|
587 |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
592 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
593 |
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
|
594 |
4891
089bc08f720e
Builder: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4890
diff
changeset
|
595 /** 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
|
596 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
|
597 |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
598 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
|
599 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
|
600 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
|
601 |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
602 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
|
603 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
|
604 } |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 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
|
609 } |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
610 } |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
611 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
612 protected String expand(String s) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
613 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
|
614 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
615 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
|
616 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
617 StringBuffer sb = new StringBuffer(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
618 while (m.find()) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
619 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
|
620 result[0] = null; |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
621 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
|
622 m.appendReplacement( |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
623 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
|
624 } |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
625 else { |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
626 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
|
627 } |
998
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 m.appendTail(sb); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
630 return sb.toString(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
631 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
632 |
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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 } |
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
|
644 else { |
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
|
645 m.appendReplacement(sb, "{" + expr + "}"); |
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
|
646 } |
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
|
647 } |
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
|
648 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
|
649 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
|
650 } |
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
|
651 } |
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
|
652 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
653 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
|
654 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
655 { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
656 String ns = current.getNamespaceURI(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
657 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
|
658 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
|
659 log.warn("need elements here"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
660 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
661 else { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
662 String localName = current.getLocalName(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
663 if ("attribute".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
664 attribute(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
665 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
666 else if ("context".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
667 context(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
668 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
669 else if ("if".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
670 ifClause(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
671 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
672 else if ("choose".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
673 choose(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
674 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
675 else if ("call-macro".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
676 callMacro(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
677 } |
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
|
678 else if ("macro-body".equals(localName)) { |
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
|
679 macroBody(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
|
680 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
681 else if ("macro".equals(localName)) { |
1029
3f3988bb6284
Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1023
diff
changeset
|
682 // Simply ignore the definition. |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
683 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
684 else if ("element".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
685 element(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
686 } |
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
|
687 else if ("elements".equals(localName)) { |
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
|
688 elements(parent, (Element)current); |
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
|
689 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
690 else if ("text".equals(localName)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
691 text(parent, (Element)current); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
692 } |
4737
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
693 else if ("variable".equals(localName)) { |
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
694 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
|
695 } |
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
|
696 else if ("comment".equals(localName) |
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
|
697 || "statement".equals(localName)) { |
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
|
698 // ignore comments and statements in output |
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
|
699 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
700 else if ("convert".equals(localName)) { |
4737
718adea968e2
Add <dc:variable name="variable" expr="xpath"/> construct to datacage language.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4614
diff
changeset
|
701 convert((Element)current); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
702 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
703 else { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
704 log.warn("unknown '" + localName + "' -> ignore"); |
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 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
707 return; |
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 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
|
711 String txt = current.getNodeValue(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
712 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
|
713 return; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
714 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
715 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
716 |
4353
daf0919df76d
Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4051
diff
changeset
|
717 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
|
718 // Ignore XML comments |
daf0919df76d
Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4051
diff
changeset
|
719 return; |
daf0919df76d
Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4051
diff
changeset
|
720 } |
daf0919df76d
Ignore comments in meta data xml template
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4051
diff
changeset
|
721 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
722 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
|
723 |
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
|
724 if (copy.getNodeType() == Node.ATTRIBUTE_NODE) { |
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
|
725 evaluateAttributeValue((Attr)copy); |
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
|
726 } |
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
|
727 else { |
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
|
728 NodeList children = current.getChildNodes(); |
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
|
729 for (int i = 0, N = children.getLength(); i < N; ++i) { |
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
|
730 build(copy, children.item(i)); |
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
|
731 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
732 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
733 parent.appendChild(copy); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
734 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
735 } // class BuildHelper |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
736 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
737 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
738 public Builder() { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
739 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
|
740 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
|
741 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
742 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
743 public Builder(Document template) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
744 this(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
745 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
|
746 extractMacros(); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
747 compileStatements(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
748 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
749 |
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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 } |
fb135e1dfa35
Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4737
diff
changeset
|
757 |
4614 | 758 /** Handle <dc:statement> elements. */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
759 protected void compileStatements() { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
760 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
761 NodeList nodes = template.getElementsByTagNameNS( |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
762 DC_NAMESPACE_URI, "statement"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
763 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
764 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
|
765 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
|
766 String stmnt = trimStatement(stmntElement.getTextContent()); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
767 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
|
768 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
|
769 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
770 CompiledStatement cs = new CompiledStatement(stmnt); |
1029
3f3988bb6284
Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1023
diff
changeset
|
771 // 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
|
772 stmnt = "s" + i; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
773 stmntElement.setTextContent(stmnt); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
774 compiledStatements.put(stmnt, cs); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
775 } |
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 |
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
|
778 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
|
779 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
|
780 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
|
781 |
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
|
782 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
|
783 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
|
784 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
|
785 } |
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
|
786 } |
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
|
787 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
788 protected List<Node> rootsToList() { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
789 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
790 NodeList roots = template.getElementsByTagNameNS( |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
791 DC_NAMESPACE_URI, "template"); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
792 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
793 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
|
794 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
795 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
|
796 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
|
797 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
|
798 Node child = rootChildren.item(j); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
799 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
|
800 elements.add(child); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
801 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
802 } |
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 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
805 return elements; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
806 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
807 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
808 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
|
809 if (stmnt == null) return null; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
810 //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
|
811 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
|
812 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
813 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
814 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
|
815 Document document = node.getOwnerDocument(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
816 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
|
817 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
818 |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
819 private static final List<NamedConnection> wrap(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
|
820 List<NamedConnection> list = new ArrayList<NamedConnection>(1); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1011
diff
changeset
|
821 list.add(new NamedConnection(DEFAULT_CONNECTION_NAME, connection)); |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
822 return list; |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
823 } |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
824 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
825 public void build( |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
826 Connection connection, |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
827 Node output, |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
828 Map<String, Object> parameters |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
829 ) |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
830 throws SQLException |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
831 { |
1011
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
832 build(wrap(connection), output, parameters); |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
833 } |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
834 |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
835 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
|
836 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
|
837 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
|
838 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
|
839 ) |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
840 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
|
841 { |
aca3b46160cb
Added support for more than one db connection in datacage templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
842 BuildHelper helper = new BuildHelper(output, connections, parameters); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
843 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
844 helper.build(); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
845 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
846 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
847 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |