1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.dom;
20
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24 import java.util.Map.Entry;
25
26 import org.w3c.dom.Attr;
27 import org.w3c.dom.Element;
28 import org.w3c.dom.NamedNodeMap;
29 import org.w3c.dom.Node;
30 import org.w3c.dom.TypeInfo;
31
32
33
34
35
36
37
38
39
40
41 public abstract class AbstractPartialElementImpl extends
42 AbstractPartialNodeImpl implements Element {
43
44 private final Map<String, String> attributes = new HashMap<String, String>();
45
46
47 public static class AttrImpl extends AbstractPartialNodeImpl implements
48 Attr {
49
50 private final String name;
51
52 private final String value;
53
54 private final Element owner;
55
56
57
58
59
60
61
62
63
64
65
66 protected AttrImpl(final String nam, final String val,
67 final Element own) {
68 this.name = nam;
69 this.value = val;
70 this.owner = own;
71 }
72
73
74 public String getName() {
75 return this.name;
76 }
77
78
79 public Element getOwnerElement() {
80 return this.owner;
81 }
82
83
84 public TypeInfo getSchemaTypeInfo() {
85 throw new UnsupportedOperationException();
86 }
87
88
89 public boolean getSpecified() {
90 throw new UnsupportedOperationException();
91 }
92
93
94 public String getValue() {
95 return this.value;
96 }
97
98
99 @Override
100 public final String getNodeValue() {
101 return this.value;
102 }
103
104
105 public boolean isId() {
106 throw new UnsupportedOperationException();
107 }
108
109
110 public void setValue(final String val) {
111 throw new UnsupportedOperationException();
112 }
113
114
115 public String getNodeName() {
116 return this.name;
117 }
118
119
120 public short getNodeType() {
121 return Node.ATTRIBUTE_NODE;
122 }
123 }
124
125
126 public static class AttributeNodeMap implements NamedNodeMap {
127
128 private final Map<String, String> attributes;
129
130 private final Element owner;
131
132
133
134
135
136
137
138
139
140 protected AttributeNodeMap(final Map<String, String> attrs,
141 final Element parent) {
142 this.attributes = attrs;
143 this.owner = parent;
144 }
145
146
147 public int getLength() {
148 return this.attributes.size();
149 }
150
151
152 public Node getNamedItem(final String name) {
153 final String value = this.attributes.get(name);
154 if (value == null) {
155 return null;
156 } else {
157 return new AttrImpl(name, value, this.owner);
158 }
159 }
160
161
162 public Node getNamedItemNS(final String namespaceURI,
163 final String localName) {
164 return this.getNamedItem(localName);
165 }
166
167
168 public Node item(final int index) {
169
170 final Iterator<Entry<String, String>> it = this.attributes
171 .entrySet().iterator();
172 for (int i = 0; i < index; i++) {
173 it.next();
174 }
175 final Entry<String, String> found = it.next();
176 return new AttrImpl(found.getKey(), found.getValue(), this.owner);
177 }
178
179
180 public Node removeNamedItem(final String name) {
181 throw new UnsupportedOperationException();
182 }
183
184
185 public Node removeNamedItemNS(final String namespaceURI,
186 final String localName) {
187 throw new UnsupportedOperationException();
188 }
189
190
191 public Node setNamedItem(final Node arg) {
192 throw new UnsupportedOperationException();
193 }
194
195
196 public Node setNamedItemNS(final Node arg) {
197 throw new UnsupportedOperationException();
198 }
199 }
200
201
202 public final String getAttribute(final String name) {
203 return this.attributes.get(name);
204 }
205
206
207 public final String getAttributeNS(final String namespaceURI,
208 final String localName) {
209 return this.attributes.get(localName);
210 }
211
212
213 public void setAttribute(final String name, final String value) {
214 this.attributes.put(name, value);
215 }
216
217
218 public final Attr getAttributeNode(final String name) {
219 throw new UnsupportedOperationException("getAttributeNode");
220 }
221
222
223 public final Attr getAttributeNodeNS(final String namespaceURI,
224 final String localName) {
225 throw new UnsupportedOperationException("getAttributeNodeNS");
226 }
227
228
229 public final org.w3c.dom.NodeList getElementsByTagName(final String name) {
230 throw new UnsupportedOperationException("getElementsByTagName");
231 }
232
233
234 public final org.w3c.dom.NodeList getElementsByTagNameNS(
235 final String namespaceURI, final String localName) {
236 throw new UnsupportedOperationException("getElementsByTagNameNS");
237 }
238
239
240 public final TypeInfo getSchemaTypeInfo() {
241 throw new UnsupportedOperationException("getSchemaTypeInfo");
242 }
243
244
245 public final boolean hasAttribute(final String name) {
246 throw new UnsupportedOperationException("hasAttribute");
247 }
248
249
250 public final boolean hasAttributeNS(final String namespaceURI,
251 final String localName) {
252 throw new UnsupportedOperationException("hasAttributeNS");
253 }
254
255
256 public final void removeAttribute(final String name) {
257 throw new UnsupportedOperationException("removeAttribute");
258 }
259
260
261 public final void removeAttributeNS(final String namespaceURI,
262 final String localName) {
263 throw new UnsupportedOperationException("removeAttributeNS");
264 }
265
266
267 public final Attr removeAttributeNode(final Attr oldAttr) {
268 throw new UnsupportedOperationException("removeAttributeNode");
269 }
270
271
272 public final void setAttributeNS(final String namespaceURI,
273 final String qualifiedName, final String value) {
274 throw new UnsupportedOperationException("setAttributeNS");
275 }
276
277
278 public final Attr setAttributeNode(final Attr newAttr) {
279 throw new UnsupportedOperationException("setAttributeNode");
280 }
281
282
283 public final Attr setAttributeNodeNS(final Attr newAttr) {
284 throw new UnsupportedOperationException("setAttributeNodeNS");
285 }
286
287
288 public final void setIdAttribute(final String name, final boolean isId) {
289 throw new UnsupportedOperationException("setIdAttribute");
290 }
291
292
293 public final void setIdAttributeNS(final String namespaceURI,
294 final String localName, final boolean isId) {
295 throw new UnsupportedOperationException("setIdAttributeNS");
296 }
297
298
299 public final void setIdAttributeNode(final Attr idAttr, final boolean isId) {
300 throw new UnsupportedOperationException("setIdAttributeNode");
301 }
302
303
304 public final String getNodeName() {
305 return this.getTagName();
306 }
307
308
309 @Override
310 public NamedNodeMap getAttributes() {
311 return new AttributeNodeMap(this.attributes, this);
312 }
313
314
315 @Override
316 public final String getLocalName() {
317 return this.getTagName();
318 }
319
320
321 public final short getNodeType() {
322 return Node.ELEMENT_NODE;
323 }
324
325
326 @Override
327 public final String toString() {
328 final StringBuilder builder = new StringBuilder(this.getTagName());
329 for (final Map.Entry<String, String> attrs : this.attributes
330 .entrySet()) {
331 builder.append(" " + attrs.getKey() + "='" + attrs.getValue()
332 + "'");
333 }
334 return builder.toString();
335 }
336
337 }