changed .classpath to relative PATH ECLIPSE_HOME
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / tidy / DOMElementImpl.java
1 /*
2  * @(#)DOMElementImpl.java   1.11 2000/08/16
3  *
4  */
5
6 package net.sourceforge.phpdt.tidy;
7
8 import org.w3c.dom.DOMException;
9
10 /**
11  *
12  * DOMElementImpl
13  *
14  * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
15  * See Tidy.java for the copyright notice.
16  * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
17  * HTML Tidy Release 4 Aug 2000</a>
18  *
19  * @author  Dave Raggett <dsr@w3.org>
20  * @author  Andy Quick <ac.quick@sympatico.ca> (translation to Java)
21  * @version 1.4, 1999/09/04 DOM Support
22  * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
23  * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
24  * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
25  * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
26  * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
27  * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
28  * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
29  */
30
31 public class DOMElementImpl extends DOMNodeImpl
32                             implements org.w3c.dom.Element {
33
34     protected DOMElementImpl(Node adaptee)
35     {
36         super(adaptee);
37     }
38
39
40     /* --------------------- DOM ---------------------------- */
41
42     /**
43      * @see org.w3c.dom.Node#getNodeType
44      */
45     public short getNodeType()
46     {
47         return org.w3c.dom.Node.ELEMENT_NODE;
48     }
49
50     /**
51      * @see org.w3c.dom.Element#getTagName
52      */
53     public String             getTagName()
54     {
55         return super.getNodeName();
56     }
57
58     /**
59      * @see org.w3c.dom.Element#getAttribute
60      */
61     public String             getAttribute(String name)
62     {
63         if (this.adaptee == null)
64             return null;
65
66         AttVal att = this.adaptee.attributes;
67         while (att != null) {
68             if (att.attribute.equals(name)) break;
69             att = att.next;
70         }
71         if (att != null)
72             return att.value;
73         else
74             return "";
75     }
76
77     /**
78      * @see org.w3c.dom.Element#setAttribute
79      */
80     public void               setAttribute(String name, 
81                                            String value)
82                                            throws DOMException
83     {
84         if (this.adaptee == null)
85             return;
86
87         AttVal att = this.adaptee.attributes;
88         while (att != null) {
89             if (att.attribute.equals(name)) break;
90             att = att.next;
91         }
92         if (att != null) {
93             att.value = value;
94         } else {
95             att = new AttVal(null, null, (int)'"', name, value);
96             att.dict =
97               AttributeTable.getDefaultAttributeTable().findAttribute(att);
98             if (this.adaptee.attributes == null) {
99                 this.adaptee.attributes = att;
100             } else {
101                 att.next = this.adaptee.attributes;
102                 this.adaptee.attributes = att;
103             }
104         }
105     }
106
107     /**
108      * @see org.w3c.dom.Element#removeAttribute
109      */
110     public void               removeAttribute(String name)
111                                               throws DOMException
112     {
113         if (this.adaptee == null)
114             return;
115
116         AttVal att = this.adaptee.attributes;
117         AttVal pre = null;
118         while (att != null) {
119             if (att.attribute.equals(name)) break;
120             pre = att;
121             att = att.next;
122         }
123         if (att != null) {
124             if (pre == null) {
125                 this.adaptee.attributes = att.next;
126             } else {
127                 pre.next = att.next;
128             }
129         }
130     }
131
132     /**
133      * @see org.w3c.dom.Element#getAttributeNode
134      */
135     public org.w3c.dom.Attr   getAttributeNode(String name)
136     {
137         if (this.adaptee == null)
138             return null;
139
140         AttVal att = this.adaptee.attributes;
141         while (att != null) {
142             if (att.attribute.equals(name)) break;
143             att = att.next;
144         }
145         if (att != null)
146             return att.getAdapter();
147         else
148             return null;
149     }
150
151     /**
152      * @see org.w3c.dom.Element#setAttributeNode
153      */
154     public org.w3c.dom.Attr   setAttributeNode(org.w3c.dom.Attr newAttr)
155                                                throws DOMException
156     {
157         if (newAttr == null)
158             return null;
159         if (!(newAttr instanceof DOMAttrImpl)) {
160             throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR,
161                                        "newAttr not instanceof DOMAttrImpl");
162         }
163
164         DOMAttrImpl newatt = (DOMAttrImpl)newAttr;
165         String name = newatt.avAdaptee.attribute;
166         org.w3c.dom.Attr result = null;
167
168         AttVal att = this.adaptee.attributes;
169         while (att != null) {
170             if (att.attribute.equals(name)) break;
171             att = att.next;
172         }
173         if (att != null) {
174             result = att.getAdapter();
175             att.adapter = newAttr;
176         } else {
177             if (this.adaptee.attributes == null) {
178                 this.adaptee.attributes = newatt.avAdaptee;
179             } else {
180                 newatt.avAdaptee.next = this.adaptee.attributes;
181                 this.adaptee.attributes = newatt.avAdaptee;
182             }
183         }
184         return result;
185     }
186
187     /**
188      * @see org.w3c.dom.Element#removeAttributeNode
189      */
190     public org.w3c.dom.Attr   removeAttributeNode(org.w3c.dom.Attr oldAttr)
191                                                   throws DOMException
192     {
193         if (oldAttr == null)
194             return null;
195
196         org.w3c.dom.Attr result = null;
197         AttVal att = this.adaptee.attributes;
198         AttVal pre = null;
199         while (att != null) {
200             if (att.getAdapter() == oldAttr) break;
201             pre = att;
202             att = att.next;
203         }
204         if (att != null) {
205             if (pre == null) {
206                 this.adaptee.attributes = att.next;
207             } else {
208                 pre.next = att.next;
209             }
210             result = oldAttr;
211         } else {
212             throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR,
213                                        "oldAttr not found");
214         }
215         return result;
216     }
217
218     /**
219      * @see org.w3c.dom.Element#getElementsByTagName
220      */
221     public org.w3c.dom.NodeList getElementsByTagName(String name)
222     {
223         return new DOMNodeListByTagNameImpl(this.adaptee, name);
224     }
225
226     /**
227      * @see org.w3c.dom.Element#normalize
228      */
229     public void               normalize()
230     {
231         // NOT SUPPORTED
232     }
233
234     /**
235      * DOM2 - not implemented.
236      */
237     public String getAttributeNS(String namespaceURI, String localName)
238     {
239         return null;
240     }
241
242     /**
243      * DOM2 - not implemented.
244      * @exception   org.w3c.dom.DOMException
245      */
246     public void setAttributeNS(String namespaceURI,
247                                String qualifiedName,
248                                String value)
249         throws org.w3c.dom.DOMException
250     {
251     }
252
253     /**
254      * DOM2 - not implemented.
255      * @exception   org.w3c.dom.DOMException
256      */
257     public void removeAttributeNS(String namespaceURI, String localName)
258         throws org.w3c.dom.DOMException
259     {
260     }
261
262     /**
263      * DOM2 - not implemented.
264      */
265     public org.w3c.dom.Attr getAttributeNodeNS(String namespaceURI,
266                                                String localName)
267     {
268         return null;
269     }
270
271     /**
272      * DOM2 - not implemented.
273      * @exception   org.w3c.dom.DOMException
274      */
275     public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
276         throws org.w3c.dom.DOMException
277     {
278         return null;
279     }
280
281     /**
282      * DOM2 - not implemented.
283      */
284     public org.w3c.dom.NodeList getElementsByTagNameNS(String namespaceURI,
285                                                        String localName)
286     {
287         return null;
288     }
289
290     /**
291      * DOM2 - not implemented.
292      */
293     public boolean hasAttribute(String name)
294     {
295         return false;
296     }
297
298     /**
299      * DOM2 - not implemented.
300      */
301     public boolean hasAttributeNS(String namespaceURI, 
302                                   String localName)
303     {
304         return false;
305     }
306
307 }