annotate artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
9 package org.dive4elements.river.themes;
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
11 import org.dive4elements.artifacts.common.utils.XMLUtils;
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5866
diff changeset
12 import org.dive4elements.river.artifacts.D4EArtifact;
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
13 import org.dive4elements.river.artifacts.context.RiverContext;
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
14
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
15 import java.util.ArrayList;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
16 import java.util.HashMap;
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
17 import java.util.List;
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
18 import java.util.Map;
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
19
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import javax.xml.xpath.XPathConstants;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8707
diff changeset
22 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8707
diff changeset
23 import org.apache.logging.log4j.LogManager;
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import org.w3c.dom.Document;
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
25 import org.w3c.dom.Element;
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import org.w3c.dom.NamedNodeMap;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 import org.w3c.dom.Node;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 import org.w3c.dom.NodeList;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 /**
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
32 *
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
33 * Mapping-matching rules:
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
34 *
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 */
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 public class ThemeFactory {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8707
diff changeset
38 private static Logger log = LogManager.getLogger(ThemeFactory.class);
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
40 /** Trivial, hidden constructor. */
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 private ThemeFactory() {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 /**
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 * Creates a new theme from <i>config</i>.
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 *
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 * @param themeCfg The theme config document that is used to fetch parent
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 * themes.
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 * @param config The theme config node.
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 *
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * @return a new theme.
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 */
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static Theme createTheme(Document themeCfg, Node config) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 String name = getName(config);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 String desc = getDescription(config);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
58 log.trace("Create new theme: " + name);
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 Theme theme = new DefaultTheme(name, desc);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 parseInherits(themeCfg, config, theme);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 parseFields(config, theme);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 parseAttrs(config, theme);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return theme;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
70 /**
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
71 * Get first matching theme for facet.
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
72 *
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
73 * @param name Name to match "from" of theme mapping.
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
74 * @param pattern String to 'compare' to pattern in mapping.
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
75 * @param output Name of the current output
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
76 *
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
77 * @return First matching theme.
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
78 */
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
79 public static Theme getTheme(
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
80 RiverContext c,
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
81 String name,
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
82 String pattern,
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
83 String output,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
84 String groupName)
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
85 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
86 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
87 log.debug(
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
88 "Search theme for: " + name + " - pattern: " + pattern);
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
89 }
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
90
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
91 if (c == null || name == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
92 log.warn("Cannot search for theme.");
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
93 return null;
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
94 }
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
95
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
96 // Fetch mapping and themes.
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
97 @SuppressWarnings("unchecked")
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
98 Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>)
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
99 c.get(RiverContext.THEME_MAPPING);
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
100
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
101 @SuppressWarnings("unchecked")
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
102 List<ThemeGroup> tgs = (List<ThemeGroup>)
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
103 c.get(RiverContext.THEMES);
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
104
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
105 ThemeGroup group = null;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
106 for (ThemeGroup tg: tgs) {
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
107 if (tg.getName().equals(groupName)) {
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
108 group = tg;
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
109 break;
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
110 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
111 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
112
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
113 if (group == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
114 log.warn("No theme group found: '" + groupName + "'");
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
115 return null;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
116 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
117
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
118 Map<String, Theme> t = group.getThemes();
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
119
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5866
diff changeset
120 D4EArtifact artifact = (D4EArtifact) c.get(RiverContext.ARTIFACT_KEY);
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
121
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
122 if (map == null || map.isEmpty() || t == null || t.isEmpty()) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
123 log.warn("No mappings or themes found. Cannot retrieve theme!");
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
124 return null;
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
125 }
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
126
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
127 List<ThemeMapping> mapping = map.get(name);
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
128
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
129 if (mapping == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
130 log.warn("No theme found for mapping: " + name);
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
131 return null;
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
132 }
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
133
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
134 // Take first mapping of which all conditions are satisfied.
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
135 for (ThemeMapping tm: mapping) {
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
136 if (name.equals(tm.getFrom())
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
137 && tm.applyPattern(pattern)
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
138 && tm.masterAttrMatches(artifact)
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
139 && tm.outputMatches(output))
1822
6ed439ff61bf Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1747
diff changeset
140 {
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
141 String target = tm.getTo();
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3781
diff changeset
142
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
143 log.debug("Found theme '" + target + "'");
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
144 return t.get(target);
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
145 }
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
146 }
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
147
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
148 String msg =
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
149 "No theme found for '" + name +
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
150 "' with pattern '" + pattern + "' and output " + output + ".";
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
151
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
152 log.warn(msg);
1747
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
153
d2a17e990c70 Improved the Themes: we now support special themes for facets which need to match a given pattern string.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 345
diff changeset
154 return null;
345
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
155 }
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
156
88a669785863 Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 342
diff changeset
157
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
158 @SuppressWarnings("unchecked")
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
159 public static List<ThemeGroup> getThemeGroups(RiverContext c) {
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
160 List<ThemeGroup> tgs = (List<ThemeGroup>)
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
161 c.get(RiverContext.THEMES);
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
162 return tgs;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
163 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
164
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
165
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
166 @SuppressWarnings("unchecked")
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
167 public static List<Theme> getThemes (RiverContext c, String name) {
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
168 List<ThemeGroup> tgs = (List<ThemeGroup>)
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
169 c.get(RiverContext.THEMES);
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
170 if (tgs == null) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
171 return null;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
172 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
173
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
174 List<Theme> themes = new ArrayList<Theme>();
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
175 for (ThemeGroup tg: tgs) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
176 themes.add(tg.getThemeByName(name));
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
177 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
178 return themes;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
179 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
180
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 protected static String getName(Node config) {
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
182 return ((Element)config).getAttribute("name");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 protected static String getDescription(Node config) {
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
187 return ((Element)config).getAttribute("desc");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 protected static void parseInherits(Document themeCfg, Node cfg, Theme t) {
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
192 parseInherits(themeCfg, cfg, t, null);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
193 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
194
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
195 protected static void parseInherits(
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
196 Document themeCfg,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
197 Node cfg,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
198 Theme t,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
199 Map<String, Node> themes
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
200 ) {
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
201 log.trace("ThemeFactory.parseInherits");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
203 NodeList inherits = ((Element)cfg).getElementsByTagName("inherit");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
205 int num = inherits.getLength();
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 if (num == 0) {
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
208 log.trace("Theme does not inherit from other themes.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 return;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
212 log.trace("Theme inherits from " + num + " other themes.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
214 if (themes == null) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
215 themes = buildThemeMap(themeCfg);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
216 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
217
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 for (int i = 0; i < num; i++) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 Node inherit = inherits.item(i);
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
220 String from = ((Element)inherit).getAttribute("from");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
222 Node tmp = themes.get(from);
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
224 parseInherits(themeCfg, tmp, t, themes);
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 parseFields(tmp, t);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
229 protected static Map<String, Node> buildThemeMap(Document themeCfg) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
230 Map<String, Node> map = new HashMap<String, Node>();
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
231 String xpath = "/themes/themegroup/theme";
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
233 NodeList nodes = (NodeList)XMLUtils.xpath(
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
234 themeCfg, xpath, XPathConstants.NODESET);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
235
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
236 if (nodes != null) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
237 for (int i = 0, N = nodes.getLength(); i < N; ++i) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
238 Node node = nodes.item(i);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
239 String name = ((Element)node).getAttribute("name");
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
240 map.put(name, node);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
241 }
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 }
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
243 return map;
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 protected static void parseFields(Node config, Theme theme) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248 if (config == null || theme == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
249 log.warn("Parsing fields without node or theme is senseless!");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250 return;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
251 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
253 NodeList fields = ((Element)config).getElementsByTagName("field");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
255 int num = fields.getLength();
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
257 log.trace("Found " + num + " own fields in this theme.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
259 if (num == 0) {
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
260 log.trace("Theme has no own fields.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
261 return;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
262 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
263
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264 for (int i = 0; i < num; i++) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265 Node field = fields.item(i);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 addField(theme, field);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272 protected static void addField(Theme theme, Node field) {
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1886
diff changeset
273 String name = ((Element)field).getAttribute("name");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
274
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
275 log.trace("Add field " + name + " to theme " + theme.getName());
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 NamedNodeMap attrs = field.getAttributes();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
278
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
279 int num = attrs != null ? attrs.getLength() : 0;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
281 if (num == 0) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
282 log.warn("This field has no attributes.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
283 return;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
284 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
285
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
286 ThemeField theField = new DefaultThemeField(name);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
287
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
288 for (int i = 0; i < num; i++) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
289 Node attr = attrs.item(i);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
290
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
291 String key = attr.getNodeName();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
292 String value = attr.getNodeValue();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
293
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
294 theField.setAttribute(key, value);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
295 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
296
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
297 theme.addField(name, theField);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
298 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
299
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
300
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
301 protected static void parseAttrs(Node config, Theme theme) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
302 NamedNodeMap attrs = config.getAttributes();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
303
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
304 int num = attrs != null ? attrs.getLength() : 0;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
305
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
306 if (num == 0) {
8707
f0ea2063b58e Change some debugs to trace in theme factory
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
307 log.trace("Theme has no attributes set.");
340
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
308 return;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
309 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311 for (int i = 0; i < num; i++) {
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
312 Node attr = attrs.item(i);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
313
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
314 String name = attr.getNodeName();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
315 String value = attr.getNodeValue();
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
316
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
317 theme.addAttribute(name, value);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
318 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
319 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
320 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
321 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org