Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/themes/DefaultTheme.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultTheme.java@8e66293c5369 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.themes; | |
2 | |
3 import java.util.HashMap; | |
4 import java.util.Map; | |
5 | |
6 import org.w3c.dom.Document; | |
7 import org.w3c.dom.Element; | |
8 import org.w3c.dom.Node; | |
9 | |
10 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
11 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
12 | |
13 | |
14 /** | |
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
16 */ | |
17 public class DefaultTheme implements Theme { | |
18 | |
19 /** The name of the theme.*/ | |
20 protected String name; | |
21 | |
22 /** The description of the theme.*/ | |
23 protected String description; | |
24 | |
25 protected String facet; | |
26 | |
27 protected int index; | |
28 | |
29 | |
30 /** The map storing the fields of this theme.*/ | |
31 protected Map<String, ThemeField> fields; | |
32 | |
33 /** The map storing the attributes of this theme.*/ | |
34 protected Map<String, String> attr; | |
35 | |
36 | |
37 /** | |
38 * Initializes the components of this Theme. | |
39 */ | |
40 public DefaultTheme(String name, String description) { | |
41 this.name = name; | |
42 this.description = description; | |
43 this.fields = new HashMap<String, ThemeField>(); | |
44 this.attr = new HashMap<String, String>(); | |
45 } | |
46 | |
47 | |
48 public void init(Node config) { | |
49 } | |
50 | |
51 | |
52 public String getName() { | |
53 return name; | |
54 } | |
55 | |
56 | |
57 public String getDescription() { | |
58 return description; | |
59 } | |
60 | |
61 | |
62 public String getFacet() { | |
63 return facet; | |
64 } | |
65 | |
66 | |
67 public void setFacet(String facet) { | |
68 this.facet = facet; | |
69 } | |
70 | |
71 | |
72 public int getIndex() { | |
73 return index; | |
74 } | |
75 | |
76 | |
77 public void setIndex(int index) { | |
78 this.index = index; | |
79 } | |
80 | |
81 | |
82 public void addAttribute(String name, String value) { | |
83 if (name != null && value != null) { | |
84 attr.put(name, value); | |
85 } | |
86 } | |
87 | |
88 | |
89 public String getAttribute(String name) { | |
90 return attr.get(name); | |
91 } | |
92 | |
93 | |
94 public void addField(String name, ThemeField field) { | |
95 if (name != null && field != null) { | |
96 fields.put(name, field); | |
97 } | |
98 } | |
99 | |
100 | |
101 public void setFieldValue(String name, Object value) { | |
102 if (name != null && value != null) { | |
103 ThemeField field = fields.get(name); | |
104 | |
105 if (field != null) { | |
106 field.setValue(value); | |
107 } | |
108 } | |
109 } | |
110 | |
111 | |
112 public ThemeField getField(String name) { | |
113 return fields.get(name); | |
114 } | |
115 | |
116 | |
117 public String getFieldType(String name) { | |
118 ThemeField field = fields.get(name); | |
119 | |
120 return field != null ? field.getType() : null; | |
121 } | |
122 | |
123 | |
124 public Object getFieldValue(String name) { | |
125 ThemeField field = fields.get(name); | |
126 | |
127 return field != null ? field.getValue() : null; | |
128 } | |
129 | |
130 | |
131 public Document toXML() { | |
132 Document doc = XMLUtils.newDocument(); | |
133 | |
134 ElementCreator cr = new ElementCreator(doc, null, null); | |
135 | |
136 Element theme = cr.create("theme"); | |
137 theme.setAttribute("facet", facet); | |
138 theme.setAttribute("index", String.valueOf(index)); | |
139 | |
140 appendAttributes(cr, theme); | |
141 appendFields(cr, theme); | |
142 | |
143 doc.appendChild(theme); | |
144 | |
145 return doc; | |
146 } | |
147 | |
148 | |
149 /** | |
150 * Appends the attributes configured for this theme. | |
151 * | |
152 * @param cr The ElementCreator. | |
153 * @param theme The document root element. | |
154 */ | |
155 protected void appendAttributes(ElementCreator cr, Element theme) { | |
156 | |
157 for (Map.Entry<String, String> entry: attr.entrySet()) { | |
158 String key = entry.getKey(); | |
159 String val = entry.getValue(); | |
160 | |
161 if (key != null && val != null) { | |
162 cr.addAttr(theme, key, val); | |
163 } | |
164 } | |
165 } | |
166 | |
167 | |
168 /** | |
169 * Appends the fields configured for this theme. | |
170 * | |
171 * @param cr The ElementCreator. | |
172 * @param theme The document root element. | |
173 */ | |
174 protected void appendFields(ElementCreator cr, Element theme) { | |
175 | |
176 for (ThemeField field: fields.values()) { | |
177 Document doc = field.toXML(); | |
178 Node root = doc.getFirstChild(); | |
179 | |
180 theme.appendChild(theme.getOwnerDocument().importNode(root, true)); | |
181 } | |
182 } | |
183 } | |
184 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |