001: /*
002: * @(#)DOMDocumentImpl.java 1.11 2000/08/16
003: *
004: */
005:
006: package org.w3c.tidy;
007:
008: import java.util.ArrayList;
009: import java.util.List;
010: import org.w3c.dom.DOMException;
011:
012: /**
013: *
014: * DOMDocumentImpl
015: *
016: * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
017: * See Tidy.java for the copyright notice.
018: * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
019: * HTML Tidy Release 4 Aug 2000</a>
020: *
021: * @author Dave Raggett <dsr@w3.org>
022: * @author Andy Quick <ac.quick@sympatico.ca> (translation to Java)
023: * @version 1.4, 1999/09/04 DOM Support
024: * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
025: * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
026: * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
027: * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
028: * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
029: * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
030: * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
031: */
032:
033: public class DOMDocumentImpl extends DOMNodeImpl implements
034: org.w3c.dom.Document {
035:
036: private TagTable tt; // a DOM Document has its own TagTable.
037:
038: protected DOMDocumentImpl(Node adaptee) {
039: super (adaptee);
040: tt = new TagTable();
041: }
042:
043: public void setTagTable(TagTable tt) {
044: this .tt = tt;
045: }
046:
047: /* --------------------- DOM ---------------------------- */
048:
049: /**
050: * @see org.w3c.dom.Node#getNodeName
051: */
052: public String getNodeName() {
053: return "#document";
054: }
055:
056: /**
057: * @see org.w3c.dom.Node#getNodeType
058: */
059: public short getNodeType() {
060: return org.w3c.dom.Node.DOCUMENT_NODE;
061: }
062:
063: /**
064: * @see org.w3c.dom.Document#getDoctype
065: */
066: public org.w3c.dom.DocumentType getDoctype() {
067: Node node = adaptee.content;
068: while (node != null) {
069: if (node.type == Node.DocTypeTag)
070: break;
071: node = node.next;
072: }
073: if (node != null)
074: return (org.w3c.dom.DocumentType) node.getAdapter();
075: else
076: return null;
077: }
078:
079: /**
080: * @see org.w3c.dom.Document#getImplementation
081: */
082: public org.w3c.dom.DOMImplementation getImplementation() {
083: // NOT SUPPORTED
084: return null;
085: }
086:
087: /**
088: * @see org.w3c.dom.Document#getDocumentElement
089: */
090: public org.w3c.dom.Element getDocumentElement() {
091: Node node = adaptee.content;
092: while (node != null) {
093: if (node.type == Node.StartTag
094: || node.type == Node.StartEndTag)
095: break;
096: node = node.next;
097: }
098: if (node != null)
099: return (org.w3c.dom.Element) node.getAdapter();
100: else
101: return null;
102: }
103:
104: // BEGIN RAVE MODIFICATIONS
105: /** Get all the nodes BEFORE the document element that are JSP nodes. May return null. */
106: public List getJspStartNodes() {
107: Node node = adaptee.content;
108: ArrayList list = null;
109: while (node != null) {
110: if (node.type == Node.StartTag
111: || node.type == Node.StartEndTag)
112: break;
113: if (node.type == Node.AspTag) {
114: if (list == null) {
115: list = new ArrayList();
116: }
117: list.add(node.getAdapter());
118: }
119: node = node.next;
120: }
121: return list;
122: }
123:
124: // END RAVE MODIFICATIONS
125:
126: /**
127: * @see org.w3c.dom.Document#createElement
128: */
129: public org.w3c.dom.Element createElement(String tagName)
130: throws DOMException {
131: Node node = new Node(Node.StartEndTag, null, 0, 0, tagName, tt);
132: if (node != null) {
133: if (node.tag == null) // Fix Bug 121206
134: node.tag = tt.xmlTags;
135: return (org.w3c.dom.Element) node.getAdapter();
136: } else
137: return null;
138: }
139:
140: /**
141: * @see org.w3c.dom.Document#createDocumentFragment
142: */
143: public org.w3c.dom.DocumentFragment createDocumentFragment() {
144: // NOT SUPPORTED
145: return null;
146: }
147:
148: /**
149: * @see org.w3c.dom.Document#createTextNode
150: */
151: public org.w3c.dom.Text createTextNode(String data) {
152: byte[] textarray = Lexer.getBytes(data);
153: Node node = new Node(Node.TextNode, textarray, 0,
154: textarray.length);
155: if (node != null)
156: return (org.w3c.dom.Text) node.getAdapter();
157: else
158: return null;
159: }
160:
161: /**
162: * @see org.w3c.dom.Document#createComment
163: */
164: public org.w3c.dom.Comment createComment(String data) {
165: byte[] textarray = Lexer.getBytes(data);
166: Node node = new Node(Node.CommentTag, textarray, 0,
167: textarray.length);
168: if (node != null)
169: return (org.w3c.dom.Comment) node.getAdapter();
170: else
171: return null;
172: }
173:
174: /**
175: * @see org.w3c.dom.Document#createCDATASection
176: */
177: public org.w3c.dom.CDATASection createCDATASection(String data)
178: throws DOMException {
179: // NOT SUPPORTED
180: return null;
181: }
182:
183: /**
184: * @see org.w3c.dom.Document#createProcessingInstruction
185: */
186: public org.w3c.dom.ProcessingInstruction createProcessingInstruction(
187: String target, String data) throws DOMException {
188: throw new DOMExceptionImpl(DOMException.NOT_SUPPORTED_ERR,
189: "HTML document");
190: }
191:
192: /**
193: * @see org.w3c.dom.Document#createAttribute
194: */
195: public org.w3c.dom.Attr createAttribute(String name)
196: throws DOMException {
197: AttVal av = new AttVal(null, null, (int) '"', name, null);
198: if (av != null) {
199: av.dict = AttributeTable.getDefaultAttributeTable()
200: .findAttribute(av);
201: return (org.w3c.dom.Attr) av.getAdapter();
202: } else {
203: return null;
204: }
205: }
206:
207: /**
208: * @see org.w3c.dom.Document#createEntityReference
209: */
210: public org.w3c.dom.EntityReference createEntityReference(String name)
211: throws DOMException {
212: // NOT SUPPORTED
213: return null;
214: }
215:
216: /**
217: * @see org.w3c.dom.Document#getElementsByTagName
218: */
219: public org.w3c.dom.NodeList getElementsByTagName(String tagname) {
220: return new DOMNodeListByTagNameImpl(this .adaptee, tagname);
221: }
222:
223: /**
224: * DOM2 - not implemented.
225: * @exception org.w3c.dom.DOMException
226: */
227: public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode,
228: boolean deep) throws org.w3c.dom.DOMException {
229: return null;
230: }
231:
232: /**
233: * DOM2 - not implemented.
234: * @exception org.w3c.dom.DOMException
235: */
236: public org.w3c.dom.Attr createAttributeNS(String namespaceURI,
237: String qualifiedName) throws org.w3c.dom.DOMException {
238: return null;
239: }
240:
241: /**
242: * DOM2 - not implemented.
243: * @exception org.w3c.dom.DOMException
244: */
245: public org.w3c.dom.Element createElementNS(String namespaceURI,
246: String qualifiedName) throws org.w3c.dom.DOMException {
247: return null;
248: }
249:
250: /**
251: * DOM2 - not implemented.
252: */
253: public org.w3c.dom.NodeList getElementsByTagNameNS(
254: String namespaceURI, String localName) {
255: return null;
256: }
257:
258: /**
259: * DOM2 - not implemented.
260: */
261: public org.w3c.dom.Element getElementById(String elementId) {
262: return null;
263: }
264:
265: }
|