annotate flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java @ 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. flys-artifacts/trunk@1747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 26 Apr 2011 13:17:08 +0000
parents f72c63713099
children d2a17e990c70
rev   line source
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
1 package de.intevation.flys.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
2
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
3 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
4
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
5 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
6
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 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
8
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.w3c.dom.Document;
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 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
11 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
12 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
13
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.utils.XMLUtils;
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
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
16 import de.intevation.flys.artifacts.context.FLYSContext;
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
17
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
18
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 /**
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 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
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 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
23
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 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
25
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 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
27 }
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 /**
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 * 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
32 *
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 * @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
34 * 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
35 * @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
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 * @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
38 */
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 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
40 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
41 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
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 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
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 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
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 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
48 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
49 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
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 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
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
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
55 /**
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
56 * Returns the theme for a specified output type and facet.
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
57 *
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
58 * @param c The FLYSContext that stores the mappings and themes.
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
59 * @param name The name of the mapping.
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
60 *
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
61 * @return a 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
62 */
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
63 public static Theme getTheme(FLYSContext c, String name) {
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
64 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
65 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
66 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
67 }
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
68
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 Map<String, String> map = (Map<String, String>)
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 c.get(FLYSContext.THEME_MAPPING);
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
71
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
72 Map<String, Theme> t = (Map<String, 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
73 c.get(FLYSContext.THEMES);
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
74
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
75 if (map == null || map.size() == 0 || t == null || t.size() == 0) {
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
76 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
77 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
78 }
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
79
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
80 String themeName = map.get(name);
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
81
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
82 if (themeName == 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
83 logger.warn("No theme found for mapping: " + name);
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
84 }
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
85
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
86 return t.get(themeName);
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
87 }
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
88
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
89
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
90 protected static String getName(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
91 return (String) XMLUtils.xpath(config, "@name", XPathConstants.STRING);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 protected static String getDescription(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
96 return (String) XMLUtils.xpath(config, "@desc", XPathConstants.STRING);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 protected static void parseInherits(Document themeCfg, Node cfg, Theme 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
101 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
102
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 NodeList inherits = (NodeList) XMLUtils.xpath(
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 cfg, "inherits/inherit", XPathConstants.NODESET);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 int num = inherits != null ? inherits.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
107
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 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
109 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
110 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
111 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 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
114
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 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
116 Node inherit = inherits.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
117 String from = (String) XMLUtils.xpath(
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 inherit, "@from", XPathConstants.STRING);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 Node tmp = getThemeNode(themeCfg, from);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 parseInherits(themeCfg, 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
123 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
124 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 protected static Node getThemeNode(Document themeCfg, String 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
129 if (name == 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
130 logger.warn("Cannot search theme config without 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
131 return 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
132 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 logger.debug("Search for 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
135
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 String xpath = "/themes/theme[@name='" + 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
137
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 return (Node) XMLUtils.xpath(themeCfg, xpath, XPathConstants.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
139 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 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
143 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
144 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
145 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
146 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 NodeList fields = (NodeList) XMLUtils.xpath(
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 config, "fields/field", XPathConstants.NODESET);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 int num = fields != null ? fields.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
152
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 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
154
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 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
156 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
157 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
158 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 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
161 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
162
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 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
164 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 protected static void addField(Theme theme, Node 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
169 String name = (String) XMLUtils.xpath(
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 field, "@name", XPathConstants.STRING);
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 logger.debug("Add field: " + 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
173
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 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
175
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 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
177
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 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
179 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
180 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
181 }
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 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
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 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
186 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
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 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
189 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
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 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
192 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 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
195 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 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
199 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
200
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 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
202
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 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
204 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
205 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
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
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 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
209 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
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 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
212 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
213
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 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
215 }
b36fd8f21e6a Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 }
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 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org