Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultThemeField.java @ 6987:4126ff35beb8 interaktive-karte
Closing branch 'interaktive-karte', the contents must have been merged (without hg tracking it) to default long ago because it is in there.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 11 Sep 2013 11:41:29 +0200 |
parents | e32b822f3cfa |
children |
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 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.HashMap; |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.Map; |
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 |
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 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
|
7 import org.w3c.dom.Element; |
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 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
|
10 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
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 |
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 |
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 * @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
|
15 */ |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 public class DefaultThemeField implements ThemeField { |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
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 protected 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
|
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 protected Map<String, Object> attr; |
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 |
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 public DefaultThemeField(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
|
24 this.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
|
25 this.attr = new HashMap<String, Object>(); |
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 } |
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 public String getName() { |
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 return 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
|
31 } |
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 |
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 public String getType() { |
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 return (String) getAttribute("type"); |
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 |
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 Object getValue() { |
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 return getAttribute("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
|
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 public void setValue(Object 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
|
45 setAttribute("value", 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
|
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 |
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 |
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 public Object getAttribute(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
|
50 return attr.get(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
|
51 } |
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 public void setAttribute(String name, Object 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
|
55 if (name == null || value == 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
|
56 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
|
57 } |
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 attr.put(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
|
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 |
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 |
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 public Document toXML() { |
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 Document doc = XMLUtils.newDocument(); |
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 |
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 ElementCreator cr = new ElementCreator(doc, null, 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
|
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 Element field = cr.create("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
|
69 |
3731
e32b822f3cfa
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
340
diff
changeset
|
70 for (Map.Entry<String, Object> entry: attr.entrySet()) { |
e32b822f3cfa
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
340
diff
changeset
|
71 cr.addAttr(field, entry.getKey(), (String)entry.getValue()); |
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
|
72 } |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 doc.appendChild(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
|
75 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 return doc; |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 } |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |