Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/html/tidy/DOMDocumentImpl.java


1   /*
2    * @(#)DOMDocumentImpl.java   1.11 2000/08/16
3    *
4    */
5   
6   package com.port80.html.tidy;
7   
8   import org.w3c.dom.DOMException;
9   
10  
11  /**
12   *
13   * DOMDocumentImpl
14   *
15   * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
16   * See Tidy.java for the copyright notice.
17   * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
18   * HTML Tidy Release 4 Aug 2000</a>
19   *
20   * @author  Dave Raggett <dsr@w3.org>
21   * @author  Andy Quick <ac.quick@sympatico.ca> (translation to Java)
22   * @version 1.4, 1999/09/04 DOM Support
23   * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
24   * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
25   * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
26   * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
27   * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
28   * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
29   * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
30   */
31  
32  public class DOMDocumentImpl extends DOMNodeImpl implements org.w3c.dom.Document {
33  
34    private TagTable tt; // a DOM Document has its own TagTable.
35  
36    protected DOMDocumentImpl(Node adaptee) {
37      super(adaptee);
38      tt = new TagTable();
39    }
40  
41    public void setTagTable(TagTable tt) {
42      this.tt = tt;
43    }
44  
45    /* --------------------- DOM ---------------------------- */
46  
47    /**
48     * @see org.w3c.dom.Node#getNodeName
49     */
50    public String getNodeName() {
51      return "#document";
52    }
53  
54    /**
55     * @see org.w3c.dom.Node#getNodeType
56     */
57    public short getNodeType() {
58      return org.w3c.dom.Node.DOCUMENT_NODE;
59    }
60  
61    public Node getDocument() {
62      return adaptee;
63    }
64    
65    /**
66     * @see org.w3c.dom.Document#getDoctype
67     */
68    public org.w3c.dom.DocumentType getDoctype() {
69      Node node = adaptee.content;
70      while (node != null) {
71        if (node.type == Node.DocTypeTag)
72          break;
73        node = node.next;
74      }
75      if (node != null)
76        return (org.w3c.dom.DocumentType) node.getAdapter();
77      else
78        return null;
79    }
80  
81    /**
82     * @see org.w3c.dom.Document#getImplementation
83     */
84    public org.w3c.dom.DOMImplementation getImplementation() {
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      Node node = adaptee.content;
94      while (node != null) {
95        if (node.type == Node.StartTag || node.type == Node.StartEndTag)
96          break;
97        node = node.next;
98      }
99      if (node != null)
100       return (org.w3c.dom.Element) node.getAdapter();
101     else
102       return null;
103   }
104 
105   /**
106    * @see org.w3c.dom.Document#createElement
107    */
108   public org.w3c.dom.Element createElement(String tagName) throws DOMException {
109     Node node = new Node(Node.StartEndTag, null, 0, 0, tagName, tt);
110     if (node != null) {
111       if (node.tag == null) // Fix Bug 121206
112         node.tag = tt.xmlTags;
113       return (org.w3c.dom.Element) node.getAdapter();
114     } else
115       return null;
116   }
117 
118   /**
119    * @see org.w3c.dom.Document#createDocumentFragment
120    */
121   public org.w3c.dom.DocumentFragment createDocumentFragment() {
122     // NOT SUPPORTED
123     return null;
124   }
125 
126   /**
127    * @see org.w3c.dom.Document#createTextNode
128    */
129   public org.w3c.dom.Text createTextNode(String data) {
130     Node node = new Node(Node.TextNode, new CharBuffer(data), 0, data.length());
131     if (node != null)
132       return (org.w3c.dom.Text) node.getAdapter();
133     else
134       return null;
135   }
136 
137   /**
138    * @see org.w3c.dom.Document#createComment
139    */
140   public org.w3c.dom.Comment createComment(String data) {
141     Node node = new Node(Node.CommentTag, new CharBuffer(data), 0, data.length());
142     if (node != null)
143       return (org.w3c.dom.Comment) node.getAdapter();
144     else
145       return null;
146   }
147 
148   /**
149    * @see org.w3c.dom.Document#createCDATASection
150    */
151   public org.w3c.dom.CDATASection createCDATASection(String data) throws DOMException {
152     // NOT SUPPORTED
153     return null;
154   }
155 
156   /**
157    * @see org.w3c.dom.Document#createProcessingInstruction
158    */
159   public org.w3c.dom.ProcessingInstruction createProcessingInstruction(String target, String data)
160     throws DOMException {
161     throw new DOMExceptionImpl(DOMException.NOT_SUPPORTED_ERR, "HTML document");
162   }
163 
164   /**
165    * @see org.w3c.dom.Document#createAttribute
166    */
167   public org.w3c.dom.Attr createAttribute(String name) throws DOMException {
168     AttVal av = new AttVal(null, null, '"', name, null);
169     if (av != null) {
170       av.dict = AttributeTable.getDefaultAttributeTable().findAttribute(av);
171       return (org.w3c.dom.Attr) av.getAdapter();
172     } else {
173       return null;
174     }
175   }
176 
177   /**
178    * @see org.w3c.dom.Document#createEntityReference
179    */
180   public org.w3c.dom.EntityReference createEntityReference(String name) throws DOMException {
181     // NOT SUPPORTED
182     return null;
183   }
184 
185   /**
186    * @see org.w3c.dom.Document#getElementsByTagName
187    */
188   public org.w3c.dom.NodeList getElementsByTagName(String tagname) {
189     return new DOMNodeListByTagNameImpl(this.adaptee, tagname);
190   }
191 
192   /**
193    * DOM2 - not implemented.
194    * @exception   org.w3c.dom.DOMException
195    */
196   public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep)
197     throws org.w3c.dom.DOMException {
198     return null;
199   }
200 
201   /**
202    * DOM2 - not implemented.
203    * @exception   org.w3c.dom.DOMException
204    */
205   public org.w3c.dom.Attr createAttributeNS(String namespaceURI, String qualifiedName)
206     throws org.w3c.dom.DOMException {
207     return null;
208   }
209 
210   /**
211    * DOM2 - not implemented.
212    * @exception   org.w3c.dom.DOMException
213    */
214   public org.w3c.dom.Element createElementNS(String namespaceURI, String qualifiedName)
215     throws org.w3c.dom.DOMException {
216     return null;
217   }
218 
219   /**
220    * DOM2 - not implemented.
221    */
222   public org.w3c.dom.NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
223     return null;
224   }
225 
226   /**
227    * DOM2 - not implemented.
228    */
229   public org.w3c.dom.Element getElementById(String elementId) {
230     return null;
231   }
232 
233 }