Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultThemeField.java @ 1081:d10efbe2e5c0
Minor cosmetics.
flys-artifacts/trunk@2578 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 25 Aug 2011 10:47:55 +0000 |
parents | b36fd8f21e6a |
children | e32b822f3cfa |
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.Iterator; |
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 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
|
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.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
|
8 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
|
9 |
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; |
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 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
|
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 /** |
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 * @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
|
16 */ |
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 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
|
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 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
|
20 |
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 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
|
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 |
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 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
|
25 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
|
26 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
|
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 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
|
31 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
|
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 |
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 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
|
36 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
|
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 |
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 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
|
41 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
|
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 |
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 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
|
46 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
|
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 |
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 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
|
51 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
|
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 |
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 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
|
56 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
|
57 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
|
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 |
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 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
|
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 |
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 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
|
65 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
|
66 |
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 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
|
68 |
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 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
|
70 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 Iterator<String> iter = attr.keySet().iterator(); |
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 while (iter.hasNext()) { |
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 String name = iter.next(); |
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 String value = (String) getAttribute(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
|
76 |
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 cr.addAttr(field, 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
|
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 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 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
|
81 |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 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
|
83 } |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
b36fd8f21e6a
Implementation of interfaces and its default implementations and a factory to work with themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |