Index: gnu/xml/dom/DomImpl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/DomImpl.java,v retrieving revision 1.2 diff -u -r1.2 DomImpl.java --- gnu/xml/dom/DomImpl.java 10 Feb 2005 17:21:25 -0000 1.2 +++ gnu/xml/dom/DomImpl.java 14 Mar 2005 21:04:04 -0000 @@ -47,6 +47,7 @@ import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSParser; import org.w3c.dom.ls.LSSerializer; +import gnu.xml.dom.html2.DomHTMLImpl; import gnu.xml.dom.ls.DomLSInput; import gnu.xml.dom.ls.DomLSOutput; import gnu.xml.dom.ls.DomLSParser; @@ -150,6 +151,12 @@ "".equals(version) || "3.0".equals(version)); } + else if ("html".equals(name) || "xhtml".equals(name)) + { + return (version == null || + "".equals(version) || + "2.0".equals(version)); + } // views // stylesheets @@ -199,7 +206,7 @@ String rootName, DocumentType doctype) { - Document doc = new DomDocument(this); + Document doc = createDocument(); Element root = null; if (rootName != null) @@ -223,12 +230,22 @@ return doc; } + protected Document createDocument() + { + return new DomDocument(this); + } + // DOM Level 3 public Object getFeature(String feature, String version) { if (hasFeature(feature, version)) { + if ("html".equalsIgnoreCase(feature) || + "xhtml".equalsIgnoreCase(feature)) + { + return new DomHTMLImpl(); + } return this; } return null; Index: gnu/xml/dom/html2/DomHTMLAnchorElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLAnchorElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLAnchorElement.java --- gnu/xml/dom/html2/DomHTMLAnchorElement.java 9 Mar 2005 21:59:33 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLAnchorElement.java 14 Mar 2005 21:04:04 -0000 @@ -177,12 +177,12 @@ public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } } Index: gnu/xml/dom/html2/DomHTMLDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLDocument.java,v retrieving revision 1.2 diff -u -r1.2 DomHTMLDocument.java --- gnu/xml/dom/html2/DomHTMLDocument.java 12 Mar 2005 19:53:26 -0000 1.2 +++ gnu/xml/dom/html2/DomHTMLDocument.java 14 Mar 2005 21:04:04 -0000 @@ -133,10 +133,21 @@ map.put("thead", DomHTMLTableSectionElement.class); map.put("tfoot", DomHTMLTableSectionElement.class); map.put("tbody", DomHTMLTableSectionElement.class); - // TODO others + map.put("textarea", DomHTMLTextAreaElement.class); + map.put("title", DomHTMLTitleElement.class); + map.put("ul", DomHTMLUListElement.class); ELEMENT_CLASSES = Collections.unmodifiableMap(map); } + /** + * Constructor. + * This is called by the implementation. + */ + protected DomHTMLDocument(DomHTMLImpl impl) + { + super(impl); + } + private Node getChildNodeByName(Node parent, String name) { for (Node ctx = parent.getFirstChild(); ctx != null; @@ -209,7 +220,7 @@ public String getReferrer() { - // TODO + // TODO getReferrer return null; } @@ -248,7 +259,21 @@ public void setBody(HTMLElement body) { - // TODO + Node html = getDocumentElement(); + if (html == null) + { + html = createElement("html"); + appendChild(html); + } + Node ref = getBody(); + if (ref == null) + { + html.appendChild(body); + } + else + { + html.replaceChild(body, ref); + } } public HTMLCollection getImages() @@ -296,33 +321,33 @@ public String getCookie() { - // TODO + // TODO getCookie return null; } public void setCookie(String cookie) { - // TODO + // TODO setCookie } public void open() { - // TODO + // TODO open } public void close() { - // TODO + // TODO close } public void write(String text) { - // TODO + // TODO write } public void writeln(String text) { - // TODO + // TODO write } public NodeList getElementsByName(String name) Index: gnu/xml/dom/html2/DomHTMLElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLElement.java,v retrieving revision 1.2 diff -u -r1.2 DomHTMLElement.java --- gnu/xml/dom/html2/DomHTMLElement.java 12 Mar 2005 19:53:26 -0000 1.2 +++ gnu/xml/dom/html2/DomHTMLElement.java 14 Mar 2005 21:04:04 -0000 @@ -37,9 +37,13 @@ package gnu.xml.dom.html2; +import gnu.xml.dom.DomDOMException; import gnu.xml.dom.DomElement; +import gnu.xml.dom.DomEvent; +import org.w3c.dom.DOMException; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; +import org.w3c.dom.events.UIEvent; import org.w3c.dom.html2.HTMLElement; /** @@ -166,6 +170,51 @@ return null; } + /** + * Returns the first child element with the specified name. + */ + protected Node getChildElement(String name) + { + for (Node child = getFirstChild(); child != null; + child = child.getNextSibling()) + { + if (name.equalsIgnoreCase(child.getLocalName())) + { + return child; + } + } + return null; + } + + /** + * Returns the index of this element among elements of the same name, + * relative to its parent. + */ + protected int getIndex() + { + int index = 0; + Node parent = getParentNode(); + if (parent != null) + { + for (Node ctx = parent.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (ctx == this) + { + return index; + } + index++; + } + } + throw new DomDOMException(DOMException.NOT_FOUND_ERR); + } + + protected void dispatchUIEvent(String name) + { + UIEvent event = new DomEvent.DomUIEvent(name); + dispatchEvent(event); + } + public String getId() { return getHTMLAttribute("id"); Index: gnu/xml/dom/html2/DomHTMLFormElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLFormElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLFormElement.java --- gnu/xml/dom/html2/DomHTMLFormElement.java 12 Mar 2005 19:53:26 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLFormElement.java 14 Mar 2005 21:04:04 -0000 @@ -138,12 +138,12 @@ public void submit() { - // TODO + dispatchUIEvent("submit"); } public void reset() { - // TODO + dispatchUIEvent("reset"); } } Index: gnu/xml/dom/html2/DomHTMLFrameElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLFrameElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLFrameElement.java --- gnu/xml/dom/html2/DomHTMLFrameElement.java 12 Mar 2005 19:53:26 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLFrameElement.java 14 Mar 2005 21:04:04 -0000 @@ -138,7 +138,7 @@ public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } Index: gnu/xml/dom/html2/DomHTMLIFrameElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLIFrameElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLIFrameElement.java --- gnu/xml/dom/html2/DomHTMLIFrameElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLIFrameElement.java 14 Mar 2005 21:04:04 -0000 @@ -158,7 +158,7 @@ public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } Index: gnu/xml/dom/html2/DomHTMLImpl.java =================================================================== RCS file: gnu/xml/dom/html2/DomHTMLImpl.java diff -N gnu/xml/dom/html2/DomHTMLImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/xml/dom/html2/DomHTMLImpl.java 14 Mar 2005 21:04:04 -0000 @@ -0,0 +1,67 @@ +/* DomHTMLImpl.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.dom.html2; + +import gnu.xml.dom.DomImpl; +import org.w3c.dom.Document; + +/** + * Specialised DOMImplementation for creating HTML documents. + * + * @author Chris Burdess + */ +public class DomHTMLImpl + extends DomImpl +{ + + protected Document createDocument() + { + return new DomHTMLDocument(this); + } + + public Object getFeature(String feature, String version) + { + if (hasFeature(feature, version)) + { + return this; + } + return null; + } + +} + Index: gnu/xml/dom/html2/DomHTMLInputElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLInputElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLInputElement.java --- gnu/xml/dom/html2/DomHTMLInputElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLInputElement.java 14 Mar 2005 21:04:04 -0000 @@ -244,22 +244,22 @@ public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } public void select() { - // TODO + dispatchUIEvent("select"); } public void click() { - // TODO + dispatchUIEvent("click"); } } Index: gnu/xml/dom/html2/DomHTMLObjectElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLObjectElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLObjectElement.java --- gnu/xml/dom/html2/DomHTMLObjectElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLObjectElement.java 14 Mar 2005 21:04:04 -0000 @@ -234,7 +234,7 @@ public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } Index: gnu/xml/dom/html2/DomHTMLOptionElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLOptionElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLOptionElement.java --- gnu/xml/dom/html2/DomHTMLOptionElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLOptionElement.java 14 Mar 2005 21:04:04 -0000 @@ -80,8 +80,7 @@ public int getIndex() { - // TODO - return -1; + return super.getIndex(); } public boolean getDisabled() Index: gnu/xml/dom/html2/DomHTMLSelectElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLSelectElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLSelectElement.java --- gnu/xml/dom/html2/DomHTMLSelectElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLSelectElement.java 14 Mar 2005 21:04:04 -0000 @@ -199,12 +199,12 @@ public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } } Index: gnu/xml/dom/html2/DomHTMLTableCellElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLTableCellElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLTableCellElement.java --- gnu/xml/dom/html2/DomHTMLTableCellElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLTableCellElement.java 14 Mar 2005 21:04:04 -0000 @@ -58,8 +58,7 @@ public int getCellIndex() { - // TODO - return -1; + return getIndex(); } public String getAbbr() Index: gnu/xml/dom/html2/DomHTMLTableElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLTableElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLTableElement.java --- gnu/xml/dom/html2/DomHTMLTableElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLTableElement.java 14 Mar 2005 21:04:04 -0000 @@ -37,6 +37,9 @@ package gnu.xml.dom.html2; +import gnu.xml.dom.DomDOMException; +import org.w3c.dom.DOMException; +import org.w3c.dom.Node; import org.w3c.dom.html2.HTMLCollection; import org.w3c.dom.html2.HTMLElement; import org.w3c.dom.html2.HTMLTableCaptionElement; @@ -61,35 +64,56 @@ public HTMLTableCaptionElement getCaption() { - // TODO - return null; + return (HTMLTableCaptionElement) getChildElement("caption"); } public void setCaption(HTMLTableCaptionElement caption) { - // TODO + HTMLTableCaptionElement ref = getCaption(); + if (ref == null) + { + appendChild(caption); + } + else + { + replaceChild(caption, ref); + } } public HTMLTableSectionElement getTHead() { - // TODO - return null; + return (HTMLTableSectionElement) getChildElement("thead"); } public void setTHead(HTMLTableSectionElement tHead) { - // TODO + HTMLTableSectionElement ref = getTHead(); + if (ref == null) + { + appendChild(tHead); + } + else + { + replaceChild(tHead, ref); + } } public HTMLTableSectionElement getTFoot() { - // TODO - return null; + return (HTMLTableSectionElement) getChildElement("tfoot"); } public void setTFoot(HTMLTableSectionElement tFoot) { - // TODO + HTMLTableSectionElement ref = getTFoot(); + if (ref == null) + { + appendChild(tFoot); + } + else + { + replaceChild(tFoot, ref); + } } public HTMLCollection getRows() @@ -202,47 +226,158 @@ public HTMLElement createTHead() { - // TODO - return null; + HTMLTableSectionElement ref = getTHead(); + if (ref == null) + { + return (HTMLElement) getOwnerDocument().createElement("thead"); + } + else + { + return ref; + } } public void deleteTHead() { - // TODO + HTMLTableSectionElement ref = getTHead(); + if (ref != null) + { + removeChild(ref); + } } public HTMLElement createTFoot() { - // TODO - return null; + HTMLTableSectionElement ref = getTFoot(); + if (ref == null) + { + return (HTMLElement) getOwnerDocument().createElement("tfoot"); + } + else + { + return ref; + } } public void deleteTFoot() { - // TODO + HTMLTableSectionElement ref = getTFoot(); + if (ref != null) + { + removeChild(ref); + } } public HTMLElement createCaption() { - // TODO - return null; + HTMLTableCaptionElement ref = getCaption(); + if (ref == null) + { + return (HTMLElement) getOwnerDocument().createElement("caption"); + } + else + { + return ref; + } } public void deleteCaption() { - // TODO + HTMLTableCaptionElement ref = getCaption(); + if (ref != null) + { + removeChild(ref); + } } public HTMLElement insertRow(int index) { - // TODO - return null; + Node ref = getRow(index); + Node row = getOwnerDocument().createElement("tr"); + if (ref == null) + { + Node tbody = getChildElement("tbody"); + if (tbody == null) + { + tbody = getOwnerDocument().createElement("tfoot"); + appendChild(tbody); + } + tbody.appendChild(row); + } + else + { + ref.getParentNode().insertBefore(row, ref); + } + return (HTMLElement) row; } public void deleteRow(int index) { - // TODO + Node ref = getRow(index); + if (ref == null) + { + throw new DomDOMException(DOMException.INDEX_SIZE_ERR); + } + ref.getParentNode().removeChild(ref); + } + + Node getRow(final int index) + { + int i = 0; + Node thead = getChildElement("thead"); + if (thead != null) + { + for (Node ctx = thead.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (!"tr".equalsIgnoreCase(ctx.getLocalName())) + { + continue; + } + if (index == i) + { + return ctx; + } + i++; + } + } + Node tbody = getChildElement("tbody"); + if (tbody == null) + { + tbody = this; + } + for (Node ctx = tbody.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (!"tr".equalsIgnoreCase(ctx.getLocalName())) + { + continue; + } + if (index == i) + { + return ctx; + } + i++; + } + Node tfoot = getChildElement("tfoot"); + if (tfoot != null) + { + for (Node ctx = tfoot.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (!"tr".equalsIgnoreCase(ctx.getLocalName())) + { + continue; + } + if (index == i) + { + return ctx; + } + i++; + } + } + return null; } - + } Index: gnu/xml/dom/html2/DomHTMLTableRowElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLTableRowElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLTableRowElement.java --- gnu/xml/dom/html2/DomHTMLTableRowElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLTableRowElement.java 14 Mar 2005 21:04:04 -0000 @@ -37,6 +37,9 @@ package gnu.xml.dom.html2; +import gnu.xml.dom.DomDOMException; +import org.w3c.dom.DOMException; +import org.w3c.dom.Node; import org.w3c.dom.html2.HTMLCollection; import org.w3c.dom.html2.HTMLElement; import org.w3c.dom.html2.HTMLTableRowElement; @@ -60,14 +63,56 @@ public int getRowIndex() { - // TODO - return -1; + return getIndex(); } public int getSectionRowIndex() { - // TODO - return -1; + int index = 0; + DomHTMLElement parent = (DomHTMLElement) getParentElement("table"); + if (parent != null) + { + Node thead = parent.getChildElement("thead"); + if (thead != null) + { + for (Node ctx = thead.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (ctx == this) + { + return index; + } + index++; + } + } + Node tbody = parent.getChildElement("tbody"); + if (tbody != null) + { + for (Node ctx = tbody.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (ctx == this) + { + return index; + } + index++; + } + } + Node tfoot = parent.getChildElement("tfoot"); + if (tfoot != null) + { + for (Node ctx = tfoot.getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (ctx == this) + { + return index; + } + index++; + } + } + } + throw new DomDOMException(DOMException.NOT_FOUND_ERR); } public HTMLCollection getCells() @@ -132,13 +177,48 @@ public HTMLElement insertCell(int index) { - // TODO - return null; + Node ref = getCell(index); + Node cell = getOwnerDocument().createElement("td"); + if (ref == null) + { + appendChild(cell); + } + else + { + insertBefore(cell, ref); + } + return (HTMLElement) cell; } public void deleteCell(int index) { - // TODO + Node ref = getCell(index); + if (ref == null) + { + throw new DomDOMException(DOMException.INDEX_SIZE_ERR); + } + removeChild(ref); + } + + Node getCell(final int index) + { + int i = 0; + for (Node ctx = getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + String name = ctx.getLocalName(); + if (!"td".equalsIgnoreCase(name) && + !"th".equalsIgnoreCase(name)) + { + continue; + } + if (index == i) + { + return ctx; + } + i++; + } + return null; } } Index: gnu/xml/dom/html2/DomHTMLTableSectionElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLTableSectionElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLTableSectionElement.java --- gnu/xml/dom/html2/DomHTMLTableSectionElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLTableSectionElement.java 14 Mar 2005 21:04:04 -0000 @@ -37,6 +37,9 @@ package gnu.xml.dom.html2; +import gnu.xml.dom.DomDOMException; +import org.w3c.dom.DOMException; +import org.w3c.dom.Node; import org.w3c.dom.html2.HTMLCollection; import org.w3c.dom.html2.HTMLElement; import org.w3c.dom.html2.HTMLTableSectionElement; @@ -109,13 +112,46 @@ public HTMLElement insertRow(int index) { - // TODO - return null; + Node ref = getRow(index); + Node row = getOwnerDocument().createElement("tr"); + if (ref == null) + { + appendChild(row); + } + else + { + insertBefore(row, ref); + } + return (HTMLElement) row; } public void deleteRow(int index) { - // TODO + Node ref = getRow(index); + if (ref == null) + { + throw new DomDOMException(DOMException.INDEX_SIZE_ERR); + } + removeChild(ref); + } + + Node getRow(final int index) + { + int i = 0; + for (Node ctx = getFirstChild(); ctx != null; + ctx = ctx.getNextSibling()) + { + if (!"tr".equalsIgnoreCase(ctx.getLocalName())) + { + continue; + } + if (index == i) + { + return ctx; + } + i++; + } + return null; } } Index: gnu/xml/dom/html2/DomHTMLTextAreaElement.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLTextAreaElement.java,v retrieving revision 1.1 diff -u -r1.1 DomHTMLTextAreaElement.java --- gnu/xml/dom/html2/DomHTMLTextAreaElement.java 12 Mar 2005 19:53:27 -0000 1.1 +++ gnu/xml/dom/html2/DomHTMLTextAreaElement.java 14 Mar 2005 21:04:04 -0000 @@ -165,17 +165,17 @@ public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } public void select() { - // TODO + dispatchUIEvent("select"); } }