Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultSection.java @ 382:a94bc2491b41
Added new XSLT processor.
artifacts/trunk@4279 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 19 Apr 2012 18:20:55 +0000 |
parents | f93edbfcf2bc |
children | ab3900303f25 |
rev | line source |
---|---|
359
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase.state; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.HashMap; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.util.Map; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import java.util.Set; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Document; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Element; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Node; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifactdatabase.state.Attribute; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifactdatabase.state.Section; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 /** |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 */ |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 public class DefaultSection implements Section { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 protected String id; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 protected List<Section> subsections; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 protected Map<String, Attribute> attributes; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 /** |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * Creates a new DefaultSection instance. <b>Note, that the <i>id</i> is used |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * as Node name of the new Element that is created in toXML().</b> |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 */ |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public DefaultSection(String id) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 this.id = id; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 this.attributes = new HashMap<String, Attribute>(); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 this.subsections = new ArrayList<Section>(); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 public String getId() { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 return id; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 public void addSubsection(Section subsection) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 if (subsection != null) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 subsections.add(subsection); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 public int getSubsectionCount() { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 return subsections.size(); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 public Section getSubsection(int pos) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 if (pos >= 0 && pos < getSubsectionCount()) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 return subsections.get(pos); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 return null; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 public void addAttribute(String key, Attribute attribute) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 if (key != null && key.length() > 0 && attribute != null) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 attributes.put(key, attribute); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 public Attribute getAttribute(String key) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 if (key == null || key.length() == 0) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 return null; |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 return attributes.get(key); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 public Set<String> getKeys() { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 return attributes.keySet(); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 @Override |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 public void toXML(Node parent) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 Document owner = parent.getOwnerDocument(); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 Element sectionEl = owner.createElement(getId()); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 parent.appendChild(sectionEl); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 for (String key: getKeys()) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 Attribute attr = getAttribute(key); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 attr.toXML(sectionEl); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 for (int i = 0, n = getSubsectionCount(); i < n; i++) { |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 Section subsection = getSubsection(i); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 subsection.toXML(sectionEl); |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 } |
f93edbfcf2bc
Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |