Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultThemeField.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | b36fd8f21e6a |
children | e32b822f3cfa |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.themes; | |
2 | |
3 import java.util.HashMap; | |
4 import java.util.Iterator; | |
5 import java.util.Map; | |
6 | |
7 import org.w3c.dom.Document; | |
8 import org.w3c.dom.Element; | |
9 | |
10 import de.intevation.artifacts.common.utils.XMLUtils; | |
11 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
12 | |
13 | |
14 /** | |
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
16 */ | |
17 public class DefaultThemeField implements ThemeField { | |
18 | |
19 protected String name; | |
20 | |
21 protected Map<String, Object> attr; | |
22 | |
23 | |
24 public DefaultThemeField(String name) { | |
25 this.name = name; | |
26 this.attr = new HashMap<String, Object>(); | |
27 } | |
28 | |
29 | |
30 public String getName() { | |
31 return name; | |
32 } | |
33 | |
34 | |
35 public String getType() { | |
36 return (String) getAttribute("type"); | |
37 } | |
38 | |
39 | |
40 public Object getValue() { | |
41 return getAttribute("value"); | |
42 } | |
43 | |
44 | |
45 public void setValue(Object value) { | |
46 setAttribute("value", value); | |
47 } | |
48 | |
49 | |
50 public Object getAttribute(String name) { | |
51 return attr.get(name); | |
52 } | |
53 | |
54 | |
55 public void setAttribute(String name, Object value) { | |
56 if (name == null || value == null) { | |
57 return; | |
58 } | |
59 | |
60 attr.put(name, value); | |
61 } | |
62 | |
63 | |
64 public Document toXML() { | |
65 Document doc = XMLUtils.newDocument(); | |
66 | |
67 ElementCreator cr = new ElementCreator(doc, null, null); | |
68 | |
69 Element field = cr.create("field"); | |
70 | |
71 Iterator<String> iter = attr.keySet().iterator(); | |
72 | |
73 while (iter.hasNext()) { | |
74 String name = iter.next(); | |
75 String value = (String) getAttribute(name); | |
76 | |
77 cr.addAttr(field, name, value); | |
78 } | |
79 | |
80 doc.appendChild(field); | |
81 | |
82 return doc; | |
83 } | |
84 } | |
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |