annotate artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java @ 6931:2c8e5bad8699

Fix NPE in case the artifact does not even have the master attribute Started happening with the new other.wqkms.w attribute condition and official lines in waterlevel calculations
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 27 Aug 2013 18:35:51 +0200
parents af13ceeba52a
children e4606eae8ea5
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
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.apache.log4j.Logger;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 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
24 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
25 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
26 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
27 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
28
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 * @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
31 *
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 * 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
33 *
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
34 */
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 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
36
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 private static Logger logger = Logger.getLogger(ThemeFactory.class);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
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
39 /** 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
40 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
41 }
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 * 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
46 *
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 * @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
48 * 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
49 * @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
50 *
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 * @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
52 */
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 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
54 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
55 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
56
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 logger.debug("Create new theme: " + 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
58
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 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
60
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 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
62 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
63 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
64
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 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
66 }
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
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
69 /**
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
70 * 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
71 *
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
72 * @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
73 * @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
74 * @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
75 *
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 * @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
77 */
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
78 public static Theme getTheme(
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
79 RiverContext c,
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
80 String name,
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
81 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
82 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
83 String groupName)
1828
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
84 {
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
85 if (logger.isDebugEnabled()) {
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
86 logger.debug(
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
87 "Search theme for: " + name + " - pattern: " + pattern);
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
88 }
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
89
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
90 if (c == null || name == 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
91 logger.warn("Cannot search for theme.");
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
92 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
93 }
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
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
95 // Fetch mapping and themes.
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
96 @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
97 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
98 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
99
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
100 @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
101 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
102 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
103
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
104 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
105 for (ThemeGroup tg: tgs) {
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
106 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
107 group = tg;
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
108 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
109 }
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 if (group == null) {
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
113 logger.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
114 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
115 }
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 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
118
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5866
diff changeset
119 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
120
3555
b1912514e0f5 s/container.size() == 0/container.isEmpty()/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3464
diff changeset
121 if (map == null || map.isEmpty() || t == null || t.isEmpty()) {
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
122 logger.warn("No mappings or themes found. Cannot retrieve theme!");
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
123 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
124 }
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
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
126 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
127
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
128 if (mapping == null) {
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
129 logger.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
130 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
131 }
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
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
133 // 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
134 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
135 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
136 && 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
137 && tm.masterAttrMatches(artifact)
9562ca537143 Added new optional condition for theme-mappings: the output name.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1822
diff changeset
138 && 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
139 {
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
140 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
141
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
142 logger.debug("Found theme '" + target + "'");
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3555
diff changeset
143 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
144 }
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 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
148 "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
149 "' 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
150
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 logger.warn(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
152
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 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
154 }
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
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
157 @SuppressWarnings("unchecked")
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
158 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
159 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
160 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
161 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
162 }
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
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents: 3155
diff changeset
165 @SuppressWarnings("unchecked")
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
166 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
167 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
168 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
169 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
170 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
171 }
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 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
174 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
175 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
176 }
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 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
178 }
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
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
180 protected static String getName(Node config) {
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
181 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
182 }
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 protected static String getDescription(Node config) {
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
186 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
187 }
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 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
191 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
192 }
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 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
195 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
196 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
197 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
198 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
199 ) {
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
200 logger.debug("ThemeFactory.parseInherits");
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
202 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
203
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
204 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
205
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 if (num == 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
207 logger.debug("Theme does not inherit from other 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
208 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
209 }
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 logger.debug("Theme inherits from " + num + " other 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
212
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
213 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
214 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
215 }
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
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
217 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
218 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
219 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
220
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
221 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
222
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
223 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
224 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
225 }
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
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
228 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
229 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
230 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
231
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
232 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
233 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
234
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 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
236 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
237 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
238 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
239 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
240 }
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
241 }
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
242 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
243 }
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 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
247 if (config == null || theme == null) {
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 logger.warn("Parsing fields without node or theme is senseless!");
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249 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
250 }
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
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
252 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
253
2742
faf73245ec73 Improved startup performance.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2737
diff changeset
254 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
255
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 logger.debug("Found " + num + " own fields in this 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
257
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 if (num == 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
259 logger.debug("Theme has no own fields.");
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
260 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
261 }
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 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
264 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
265
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 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
267 }
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 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
272 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
273
3155
74c974b10c75 Output code to trackdown the linecolor problem
Christian Lins <christian.lins@intevation.de>
parents: 2742
diff changeset
274 logger.debug("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
275
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 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
277
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 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
279
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 if (num == 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
281 logger.warn("This field has no attributes.");
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
282 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
283 }
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 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
286
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 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
288 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
289
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 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
291 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
292
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 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
294 }
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 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
297 }
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 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
301 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
302
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 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
304
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 if (num == 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
306 logger.debug("Theme has no attributes set.");
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
307 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
308 }
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 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
311 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
312
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 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
314 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
315
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 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
317 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org