changed .classpath to relative PATH ECLIPSE_HOME
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / tidy / DOMDocumentImpl.java
1 /*
2  * @(#)DOMDocumentImpl.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  * DOMDocumentImpl
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 DOMDocumentImpl extends DOMNodeImpl implements org.w3c.dom.Document {
32
33     private TagTable tt;      // a DOM Document has its own TagTable.
34
35     protected DOMDocumentImpl(Node adaptee)
36     {
37         super(adaptee);
38         tt = new TagTable();
39     }
40
41     public void setTagTable(TagTable tt)
42     {
43         this.tt = tt;
44     }
45
46     /* --------------------- DOM ---------------------------- */
47
48     /**
49      * @see org.w3c.dom.Node#getNodeName
50      */
51     public String getNodeName()
52     {
53         return "#document";
54     }
55
56     /**
57      * @see org.w3c.dom.Node#getNodeType
58      */
59     public short getNodeType()
60     {
61         return org.w3c.dom.Node.DOCUMENT_NODE;
62     }
63
64     /**
65      * @see org.w3c.dom.Document#getDoctype
66      */
67     public org.w3c.dom.DocumentType       getDoctype()
68     {
69         Node node = adaptee.content;
70         while (node != null) {
71             if (node.type == Node.DocTypeTag) break;
72             node = node.next;
73         }
74         if (node != null)
75             return (org.w3c.dom.DocumentType)node.getAdapter();
76         else
77             return null;
78     }
79
80     /**
81      * @see org.w3c.dom.Document#getImplementation
82      */
83     public org.w3c.dom.DOMImplementation  getImplementation()
84     {
85         // NOT SUPPORTED
86         return null;
87     }
88
89     /**
90      * @see org.w3c.dom.Document#getDocumentElement
91      */
92     public org.w3c.dom.Element            getDocumentElement()
93     {
94         Node node = adaptee.content;
95         while (node != null) {
96             if (node.type == Node.StartTag ||
97                 node.type == Node.StartEndTag) break;
98             node = node.next;
99         }
100         if (node != null)
101             return (org.w3c.dom.Element)node.getAdapter();
102         else
103             return null;
104     }
105
106     /**
107      * @see org.w3c.dom.Document#createElement
108      */
109     public org.w3c.dom.Element            createElement(String tagName)
110                                             throws DOMException
111     {
112         Node node = new Node(Node.StartEndTag, null, 0, 0, tagName, tt);
113         if (node != null) {
114             if (node.tag == null)           // Fix Bug 121206
115               node.tag = tt.xmlTags;
116             return (org.w3c.dom.Element)node.getAdapter();
117         }
118         else
119             return null;
120     }
121
122     /**
123      * @see org.w3c.dom.Document#createDocumentFragment
124      */
125     public org.w3c.dom.DocumentFragment   createDocumentFragment()
126     {
127         // NOT SUPPORTED
128         return null;
129     }
130
131     /**
132      * @see org.w3c.dom.Document#createTextNode
133      */
134     public org.w3c.dom.Text               createTextNode(String data)
135     {
136         byte[] textarray = Lexer.getBytes(data);
137         Node node = new Node(Node.TextNode, textarray, 0, textarray.length);
138         if (node != null)
139             return (org.w3c.dom.Text)node.getAdapter();
140         else
141             return null;
142     }
143
144     /**
145      * @see org.w3c.dom.Document#createComment
146      */
147     public org.w3c.dom.Comment            createComment(String data)
148     {
149         byte[] textarray = Lexer.getBytes(data);
150         Node node = new Node(Node.CommentTag, textarray, 0, textarray.length);
151         if (node != null)
152             return (org.w3c.dom.Comment)node.getAdapter();
153         else
154             return null;
155     }
156
157     /**
158      * @see org.w3c.dom.Document#createCDATASection
159      */
160     public org.w3c.dom.CDATASection       createCDATASection(String data)
161                                                  throws DOMException
162     {
163         // NOT SUPPORTED
164         return null;
165     }
166
167     /**
168      * @see org.w3c.dom.Document#createProcessingInstruction
169      */
170     public org.w3c.dom.ProcessingInstruction createProcessingInstruction(String target, 
171                                                           String data)
172                                                           throws DOMException
173     {
174         throw new DOMExceptionImpl(DOMException.NOT_SUPPORTED_ERR,
175                                    "HTML document");
176     }
177
178     /**
179      * @see org.w3c.dom.Document#createAttribute
180      */
181     public org.w3c.dom.Attr               createAttribute(String name)
182                                               throws DOMException
183     {
184         AttVal av = new AttVal(null, null, (int)'"', name, null);
185         if (av != null) {
186             av.dict =
187                 AttributeTable.getDefaultAttributeTable().findAttribute(av);
188             return (org.w3c.dom.Attr)av.getAdapter();
189         } else {
190             return null;
191         }
192     }
193
194     /**
195      * @see org.w3c.dom.Document#createEntityReference
196      */
197     public org.w3c.dom.EntityReference    createEntityReference(String name)
198                                                     throws DOMException
199     {
200         // NOT SUPPORTED
201         return null;
202     }
203
204     /**
205      * @see org.w3c.dom.Document#getElementsByTagName
206      */
207     public org.w3c.dom.NodeList           getElementsByTagName(String tagname)
208     {
209         return new DOMNodeListByTagNameImpl(this.adaptee, tagname);
210     }
211
212     /**
213      * DOM2 - not implemented.
214      * @exception   org.w3c.dom.DOMException
215      */
216     public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep)
217         throws org.w3c.dom.DOMException
218     {
219         return null;
220     }
221
222     /**
223      * DOM2 - not implemented.
224      * @exception   org.w3c.dom.DOMException
225      */
226     public org.w3c.dom.Attr createAttributeNS(String namespaceURI,
227                                               String qualifiedName)
228         throws org.w3c.dom.DOMException
229     {
230         return null;
231     }
232
233     /**
234      * DOM2 - not implemented.
235      * @exception   org.w3c.dom.DOMException
236      */
237     public org.w3c.dom.Element createElementNS(String namespaceURI,
238                                                String qualifiedName)
239         throws org.w3c.dom.DOMException
240     {
241         return null;
242     }
243
244     /**
245      * DOM2 - not implemented.
246      */
247     public org.w3c.dom.NodeList getElementsByTagNameNS(String namespaceURI,
248                                                        String localName)
249     {
250         return null;
251     }
252
253     /**
254      * DOM2 - not implemented.
255      */
256     public org.w3c.dom.Element getElementById(String elementId)
257     {
258         return null;
259     }
260
261 }