1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 package org.w3c.tidy;
55
56 import org.w3c.dom.DOMException;
57
58
59 /**
60 * Tidy implementation of org.w3c.dom.NamedNodeMap.
61 * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
62 * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
63 * @author Fabrizio Giustina
64 * @version $Revision: 779 $ ($Author: fgiust $)
65 */
66 public class DOMAttrMapImpl implements org.w3c.dom.NamedNodeMap
67 {
68
69 /**
70 * wrapped org.w3c.tidy.AttVal.
71 */
72 private AttVal first;
73
74 /**
75 * instantiates a new DOMAttrMapImpl for the given AttVal.
76 * @param firstAttVal wrapped AttVal
77 */
78 protected DOMAttrMapImpl(AttVal firstAttVal)
79 {
80 this.first = firstAttVal;
81 }
82
83 /**
84 * @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String)
85 */
86 public org.w3c.dom.Node getNamedItem(String name)
87 {
88 AttVal att = this.first;
89 while (att != null)
90 {
91 if (att.attribute.equals(name))
92 {
93 break;
94 }
95 att = att.next;
96 }
97 if (att != null)
98 {
99 return att.getAdapter();
100 }
101
102 return null;
103 }
104
105 /**
106 * @see org.w3c.dom.NamedNodeMap#item
107 */
108 public org.w3c.dom.Node item(int index)
109 {
110 int i = 0;
111 AttVal att = this.first;
112 while (att != null)
113 {
114 if (i >= index)
115 {
116 break;
117 }
118 i++;
119 att = att.next;
120 }
121 if (att != null)
122 {
123 return att.getAdapter();
124 }
125
126 return null;
127 }
128
129 /**
130 * @see org.w3c.dom.NamedNodeMap#getLength
131 */
132 public int getLength()
133 {
134 int len = 0;
135 AttVal att = this.first;
136 while (att != null)
137 {
138 len++;
139 att = att.next;
140 }
141 return len;
142 }
143
144 /**
145 * @todo DOM level 2 setNamedItem() Not implemented. Throws NOT_SUPPORTED_ERR.
146 * @see org.w3c.dom.NamedNodeMap#setNamedItem
147 */
148 public org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg) throws DOMException
149 {
150 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
151 }
152
153 /**
154 * @see org.w3c.dom.NamedNodeMap#removeNamedItem
155 */
156 public org.w3c.dom.Node removeNamedItem(String name) throws DOMException
157 {
158 AttVal att = this.first;
159 AttVal previous = null;
160
161 while (att != null)
162 {
163 if (att.attribute.equals(name))
164 {
165 if (previous == null)
166 {
167 this.first = att.getNext();
168 }
169 else
170 {
171 previous.setNext(att.getNext());
172 }
173
174 break;
175 }
176 previous = att;
177 att = att.next;
178 }
179
180 if (att != null)
181 {
182 return att.getAdapter();
183 }
184
185 throw new DOMException(DOMException.NOT_FOUND_ERR, "Named item " + name + "Not found");
186 }
187
188 /**
189 * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
190 * @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String)
191 */
192 public org.w3c.dom.Node getNamedItemNS(String namespaceURI, String localName)
193 {
194
195
196 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
197 }
198
199 /**
200 * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
201 * @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node)
202 */
203 public org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg) throws org.w3c.dom.DOMException
204 {
205
206
207 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
208 }
209
210 /**
211 * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
212 * @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String)
213 */
214 public org.w3c.dom.Node removeNamedItemNS(String namespaceURI, String localName) throws org.w3c.dom.DOMException
215 {
216
217
218 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
219 }
220
221 }