comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ManagedDomFacet.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 5642a83420f2
children 58bdf95df5e4
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.model;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7 import org.w3c.dom.Node;
8
9 import de.intevation.artifacts.ArtifactNamespaceContext;
10
11
12 /**
13 * Use an Element (DOM) to store the information about a facet.
14 * The intent of this facet type is to represent a facet
15 * stored in an Collection attribute. Different facets can have different
16 * attributes that we need to parse, but the only thing ManagedFacets need
17 * to do, is to adjust the attributes "active" and "position". So, those
18 * values are set directly on the Element, the other attributes aren't
19 * touched.
20 */
21 public class ManagedDomFacet extends ManagedFacet {
22
23 protected Element facet;
24
25 private static Logger logger = Logger.getLogger(ManagedDomFacet.class);
26
27
28 public ManagedDomFacet(Element facet) {
29 super(null, -1, null, null, -1, -1, -1);
30
31 this.facet = facet;
32 }
33
34
35 @Override
36 public int getIndex() {
37 if (this.index < 0) {
38 String index = facet.getAttributeNS(
39 ArtifactNamespaceContext.NAMESPACE_URI, "index");
40
41 if (index != null && index.length() > 0) {
42 this.index = Integer.parseInt(index);
43 }
44 }
45
46 return this.index;
47 }
48
49
50 @Override
51 public String getName() {
52 if (this.name == null || this.name.length() == 0) {
53 String name = facet.getAttributeNS(
54 ArtifactNamespaceContext.NAMESPACE_URI, "facet");
55
56 this.name = name;
57 }
58
59 return this.name;
60 }
61
62
63 @Override
64 public String getDescription() {
65 if (this.description == null || this.description.length() == 0) {
66 String description = facet.getAttributeNS(
67 ArtifactNamespaceContext.NAMESPACE_URI, "description");
68
69 this.description = description;
70 }
71
72 return this.description;
73 }
74
75
76 @Override
77 public int getPosition() {
78 if (this.position < 0) {
79 String position = facet.getAttributeNS(
80 ArtifactNamespaceContext.NAMESPACE_URI,
81 "pos");
82
83 if (position != null && position.length() > 0) {
84 this.position = Integer.parseInt(position);
85 }
86 }
87
88 return this.position;
89 }
90
91
92 @Override
93 public void setPosition(int position) {
94 this.position = position;
95
96 // TODO Evaluate whether other set/getAttributes also need
97 // to use the NAMESPACE_PREFIX.
98 facet.setAttributeNS(
99 ArtifactNamespaceContext.NAMESPACE_URI,
100 ArtifactNamespaceContext.NAMESPACE_PREFIX + ":" + "pos",
101 String.valueOf(position));
102 }
103
104
105 @Override
106 public int getActive() {
107 if (this.active < 0) {
108 String active = facet.getAttributeNS(
109 ArtifactNamespaceContext.NAMESPACE_URI, "active");
110
111 if (active != null && active.length() > 0) {
112 this.active = Integer.parseInt(active);
113 }
114 }
115
116 return this.active;
117 }
118
119
120 @Override
121 public void setActive(int active) {
122 this.active = active;
123
124 facet.setAttributeNS(
125 ArtifactNamespaceContext.NAMESPACE_URI,
126 "art:active",
127 String.valueOf(active));
128 }
129
130
131 @Override
132 public int getVisible() {
133 if (this.visible < 0) {
134 String visible = facet.getAttributeNS(
135 ArtifactNamespaceContext.NAMESPACE_URI, "visible");
136
137 if (visible != null && visible.length() > 0) {
138 this.visible = Integer.parseInt(visible);
139 }
140 }
141
142 return this.visible;
143 }
144
145
146 @Override
147 public void setVisible(int visible) {
148 this.visible = visible;
149
150 facet.setAttributeNS(
151 ArtifactNamespaceContext.NAMESPACE_URI,
152 "visible",
153 String.valueOf(getVisible()));
154 }
155
156
157 @Override
158 public String getArtifact() {
159 if (this.uuid == null || this.uuid.length() == 0) {
160 String uuid = facet.getAttributeNS(
161 ArtifactNamespaceContext.NAMESPACE_URI, "artifact");
162
163 this.uuid = uuid;
164 }
165
166 return this.uuid;
167 }
168
169
170 /**
171 * Import into document.
172 * @param doc Document to be imported to.
173 */
174 @Override
175 public Node toXML(Document doc) {
176 return doc.importNode(facet, true);
177 }
178 }
179 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org