Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/themes/DefaultThemeField.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/themes/DefaultThemeField.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
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 | |
9 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
10 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
11 | |
12 | |
13 /** | |
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
15 */ | |
16 public class DefaultThemeField implements ThemeField { | |
17 | |
18 protected String name; | |
19 | |
20 protected Map<String, Object> attr; | |
21 | |
22 | |
23 public DefaultThemeField(String name) { | |
24 this.name = name; | |
25 this.attr = new HashMap<String, Object>(); | |
26 } | |
27 | |
28 | |
29 public String getName() { | |
30 return name; | |
31 } | |
32 | |
33 | |
34 public String getType() { | |
35 return (String) getAttribute("type"); | |
36 } | |
37 | |
38 | |
39 public Object getValue() { | |
40 return getAttribute("value"); | |
41 } | |
42 | |
43 | |
44 public void setValue(Object value) { | |
45 setAttribute("value", value); | |
46 } | |
47 | |
48 | |
49 public Object getAttribute(String name) { | |
50 return attr.get(name); | |
51 } | |
52 | |
53 | |
54 public void setAttribute(String name, Object value) { | |
55 if (name == null || value == null) { | |
56 return; | |
57 } | |
58 | |
59 attr.put(name, value); | |
60 } | |
61 | |
62 | |
63 public Document toXML() { | |
64 Document doc = XMLUtils.newDocument(); | |
65 | |
66 ElementCreator cr = new ElementCreator(doc, null, null); | |
67 | |
68 Element field = cr.create("field"); | |
69 | |
70 for (Map.Entry<String, Object> entry: attr.entrySet()) { | |
71 cr.addAttr(field, entry.getKey(), (String)entry.getValue()); | |
72 } | |
73 | |
74 doc.appendChild(field); | |
75 | |
76 return doc; | |
77 } | |
78 } | |
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |