comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/ManagedDomFacet.java @ 5838:5aa05a7a34b7

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

http://dive4elements.wald.intevation.org