diff options
Diffstat (limited to 'gnu')
25 files changed, 780 insertions, 79 deletions
diff --git a/gnu/classpath/SystemProperties.java b/gnu/classpath/SystemProperties.java index 42fa69d14..8a7d0d10c 100644 --- a/gnu/classpath/SystemProperties.java +++ b/gnu/classpath/SystemProperties.java @@ -128,6 +128,7 @@ public class SystemProperties dp.put("gnu.java.io.encoding_scheme_alias.UTF16_LittleEndian", "UTF16LE"); dp.put("gnu.java.io.encoding_scheme_alias.windows-1200", "UTF16LE"); + dp.put("gnu.java.io.encoding_scheme_alias.UnicodeLittleUnmarked", "UTF16LE"); //# UTF16 Big Endian dp.put("gnu.java.io.encoding_scheme_alias.UTF16BE", "UTF16BE"); @@ -144,6 +145,7 @@ public class SystemProperties dp.put("gnu.java.io.encoding_scheme_alias.cp1200", "UTF16BE"); dp.put("gnu.java.io.encoding_scheme_alias.cp1201", "UTF16BE"); dp.put("gnu.java.io.encoding_scheme_alias.UTF16_BigEndian", "UTF16BE"); + dp.put("gnu.java.io.encoding_scheme_alias.UnicodeBigUnmarked", "UTF16BE"); //# UTF16 dp.put("gnu.java.io.encoding_scheme_alias.UTF16", "UTF16BE"); diff --git a/gnu/java/lang/MainThread.java b/gnu/java/lang/MainThread.java index a7665da26..64ab19a92 100644 --- a/gnu/java/lang/MainThread.java +++ b/gnu/java/lang/MainThread.java @@ -57,7 +57,8 @@ public class MainThread public MainThread(String classname, String[] args) throws ClassNotFoundException, NoSuchMethodException { - Class found = Class.forName(classname); + Class found = Class.forName(classname, true, + ClassLoader.getSystemClassLoader()); Class[] argTypes = new Class[1]; argTypes[0] = args.getClass(); mainMethod = found.getMethod("main", argTypes); diff --git a/gnu/java/net/protocol/https/Handler.java b/gnu/java/net/protocol/https/Handler.java index ec1962f1f..0e040d64e 100644 --- a/gnu/java/net/protocol/https/Handler.java +++ b/gnu/java/net/protocol/https/Handler.java @@ -1,5 +1,5 @@ /* Handler.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,14 +38,14 @@ exception statement from your version. */ package gnu.java.net.protocol.https; +import gnu.java.net.protocol.http.HTTPConnection; +import gnu.java.net.protocol.http.HTTPURLConnection; + import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; -import gnu.java.net.protocol.http.HTTPConnection; -import gnu.java.net.protocol.http.HTTPURLConnection; - /** * An HTTPS URL stream handler. * diff --git a/gnu/javax/swing/text/html/parser/HTML_401F.java b/gnu/javax/swing/text/html/parser/HTML_401F.java index 9f8814bce..bd2f9f9f8 100644 --- a/gnu/javax/swing/text/html/parser/HTML_401F.java +++ b/gnu/javax/swing/text/html/parser/HTML_401F.java @@ -38,17 +38,16 @@ exception statement from your version. */ package gnu.javax.swing.text.html.parser; -import java.io.IOException; - -import javax.swing.text.html.parser.DTDConstants; - import gnu.javax.swing.text.html.parser.models.PCDATAonly_model; import gnu.javax.swing.text.html.parser.models.TableRowContentModel; import gnu.javax.swing.text.html.parser.models.noTagModel; -import gnu.javax.swing.text.html.parser.models.node; -import gnu.javax.swing.text.html.parser.models.transformer; + +import java.io.IOException; import java.io.Serializable; + import javax.swing.text.html.parser.*; +import javax.swing.text.html.parser.ContentModel; +import javax.swing.text.html.parser.DTDConstants; /** * This class represents the java implementation of the HTML 4.01 diff --git a/gnu/javax/swing/text/html/parser/gnuDTD.java b/gnu/javax/swing/text/html/parser/gnuDTD.java index ba23223fd..24d800af2 100644 --- a/gnu/javax/swing/text/html/parser/gnuDTD.java +++ b/gnu/javax/swing/text/html/parser/gnuDTD.java @@ -49,7 +49,6 @@ import java.util.Vector; import javax.swing.text.html.parser.AttributeList; import javax.swing.text.html.parser.ContentModel; -import javax.swing.text.html.parser.DTD; import javax.swing.text.html.parser.Element; import javax.swing.text.html.parser.Entity; diff --git a/gnu/javax/swing/text/html/parser/models/node.java b/gnu/javax/swing/text/html/parser/models/node.java index 7b12d11eb..42505d0be 100644 --- a/gnu/javax/swing/text/html/parser/models/node.java +++ b/gnu/javax/swing/text/html/parser/models/node.java @@ -40,9 +40,6 @@ package gnu.javax.swing.text.html.parser.models; import java.io.Serializable; -import javax.swing.text.html.parser.Element; -import javax.swing.text.html.parser.TagElement; - /** * Part of the internal representation of the content model. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) diff --git a/gnu/xml/aelfred2/XmlParser.java b/gnu/xml/aelfred2/XmlParser.java index b29849217..e6f55e38c 100644 --- a/gnu/xml/aelfred2/XmlParser.java +++ b/gnu/xml/aelfred2/XmlParser.java @@ -3382,7 +3382,7 @@ loop: { if (ids.systemId.indexOf('#') != -1) { - handler.verror("SYSTEM id has a URI fragment: " + ids.systemId); + handler.verror("SYSTEM id has an URI fragment: " + ids.systemId); } ids.baseUri = handler.getSystemId(); if (ids.baseUri == null && uriWarnings) diff --git a/gnu/xml/dom/DomImpl.java b/gnu/xml/dom/DomImpl.java index feb7ea703..a23f57d93 100644 --- a/gnu/xml/dom/DomImpl.java +++ b/gnu/xml/dom/DomImpl.java @@ -47,6 +47,7 @@ import org.w3c.dom.ls.LSInput; 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 @@ public class DomImpl "".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 @@ public class DomImpl String rootName, DocumentType doctype) { - Document doc = new DomDocument(this); + Document doc = createDocument(); Element root = null; if (rootName != null) @@ -223,12 +230,22 @@ public class DomImpl 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; diff --git a/gnu/xml/dom/html2/DomHTMLAnchorElement.java b/gnu/xml/dom/html2/DomHTMLAnchorElement.java index 041666f6d..625fa6c93 100644 --- a/gnu/xml/dom/html2/DomHTMLAnchorElement.java +++ b/gnu/xml/dom/html2/DomHTMLAnchorElement.java @@ -177,12 +177,12 @@ public class DomHTMLAnchorElement public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } } diff --git a/gnu/xml/dom/html2/DomHTMLDocument.java b/gnu/xml/dom/html2/DomHTMLDocument.java index 9a3182916..1ff0a27ed 100644 --- a/gnu/xml/dom/html2/DomHTMLDocument.java +++ b/gnu/xml/dom/html2/DomHTMLDocument.java @@ -44,7 +44,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -133,10 +135,43 @@ public class DomHTMLDocument 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); } + private static Set HTML_NS_URIS; + static + { + Set set = new HashSet(); + set.add("http://www.w3.org/TR/html4/strict"); + set.add("http://www.w3.org/TR/html4/loose"); + set.add("http://www.w3.org/TR/html4/frameset"); + set.add("http://www.w3.org/1999/xhtml"); + set.add("http://www.w3.org/TR/xhtml1/strict"); + set.add("http://www.w3.org/TR/xhtml1/loose"); + set.add("http://www.w3.org/TR/xhtml1/frameset"); + HTML_NS_URIS = Collections.unmodifiableSet(set); + } + + /** + * Convenience constructor. + */ + public DomHTMLDocument() + { + this(new DomHTMLImpl()); + } + + /** + * Constructor. + * This is called by the DOMImplementation. + */ + public DomHTMLDocument(DomHTMLImpl impl) + { + super(impl); + } + private Node getChildNodeByName(Node parent, String name) { for (Node ctx = parent.getFirstChild(); ctx != null; @@ -209,7 +244,7 @@ public class DomHTMLDocument public String getReferrer() { - // TODO + // TODO getReferrer return null; } @@ -248,7 +283,21 @@ public class DomHTMLDocument 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 +345,33 @@ public class DomHTMLDocument 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) @@ -341,6 +390,11 @@ public class DomHTMLDocument public Element createElementNS(String uri, String qName) { + /* If a non-HTML element, use the default implementation. */ + if (uri != null && !HTML_NS_URIS.contains(uri)) + { + return super.createElementNS(uri, qName); + } String localName = qName.toLowerCase(); int ci = qName.indexOf(':'); if (ci != -1) @@ -348,13 +402,14 @@ public class DomHTMLDocument localName = qName.substring(ci + 1); } Class t = (Class) ELEMENT_CLASSES.get(localName); + /* If a non-HTML element, use the default implementation. */ if (t == null) { return super.createElementNS(uri, qName); } try { - Constructor c = t.getConstructor(ELEMENT_PT); + Constructor c = t.getDeclaredConstructor(ELEMENT_PT); Object[] args = new Object[] { this, uri, qName }; return (Element) c.newInstance(args); } diff --git a/gnu/xml/dom/html2/DomHTMLElement.java b/gnu/xml/dom/html2/DomHTMLElement.java index b204139fa..b2952e8b4 100644 --- a/gnu/xml/dom/html2/DomHTMLElement.java +++ b/gnu/xml/dom/html2/DomHTMLElement.java @@ -37,9 +37,13 @@ exception statement from your version. */ 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 @@ public abstract class DomHTMLElement 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"); diff --git a/gnu/xml/dom/html2/DomHTMLFormElement.java b/gnu/xml/dom/html2/DomHTMLFormElement.java index 041e15eb4..0785cc989 100644 --- a/gnu/xml/dom/html2/DomHTMLFormElement.java +++ b/gnu/xml/dom/html2/DomHTMLFormElement.java @@ -138,12 +138,12 @@ public class DomHTMLFormElement public void submit() { - // TODO + dispatchUIEvent("submit"); } public void reset() { - // TODO + dispatchUIEvent("reset"); } } diff --git a/gnu/xml/dom/html2/DomHTMLFrameElement.java b/gnu/xml/dom/html2/DomHTMLFrameElement.java index 5912cacb6..db3cbfe00 100644 --- a/gnu/xml/dom/html2/DomHTMLFrameElement.java +++ b/gnu/xml/dom/html2/DomHTMLFrameElement.java @@ -138,7 +138,7 @@ public class DomHTMLFrameElement public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } diff --git a/gnu/xml/dom/html2/DomHTMLIFrameElement.java b/gnu/xml/dom/html2/DomHTMLIFrameElement.java index 8799cbc7a..def7b967d 100644 --- a/gnu/xml/dom/html2/DomHTMLIFrameElement.java +++ b/gnu/xml/dom/html2/DomHTMLIFrameElement.java @@ -158,7 +158,7 @@ public class DomHTMLIFrameElement public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } diff --git a/gnu/xml/dom/html2/DomHTMLImpl.java b/gnu/xml/dom/html2/DomHTMLImpl.java new file mode 100644 index 000000000..6f5538e71 --- /dev/null +++ b/gnu/xml/dom/html2/DomHTMLImpl.java @@ -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 <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +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; + } + +} + diff --git a/gnu/xml/dom/html2/DomHTMLInputElement.java b/gnu/xml/dom/html2/DomHTMLInputElement.java index 1a3a8a082..787be536a 100644 --- a/gnu/xml/dom/html2/DomHTMLInputElement.java +++ b/gnu/xml/dom/html2/DomHTMLInputElement.java @@ -244,22 +244,22 @@ public class DomHTMLInputElement public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } public void select() { - // TODO + dispatchUIEvent("select"); } public void click() { - // TODO + dispatchUIEvent("click"); } } diff --git a/gnu/xml/dom/html2/DomHTMLObjectElement.java b/gnu/xml/dom/html2/DomHTMLObjectElement.java index d4dded5a0..8b8abe7ed 100644 --- a/gnu/xml/dom/html2/DomHTMLObjectElement.java +++ b/gnu/xml/dom/html2/DomHTMLObjectElement.java @@ -234,7 +234,7 @@ public class DomHTMLObjectElement public Document getContentDocument() { - // TODO + // TODO getContentDocument return null; } diff --git a/gnu/xml/dom/html2/DomHTMLOptionElement.java b/gnu/xml/dom/html2/DomHTMLOptionElement.java index b1c808fa6..21952e6de 100644 --- a/gnu/xml/dom/html2/DomHTMLOptionElement.java +++ b/gnu/xml/dom/html2/DomHTMLOptionElement.java @@ -80,8 +80,7 @@ public class DomHTMLOptionElement public int getIndex() { - // TODO - return -1; + return super.getIndex(); } public boolean getDisabled() diff --git a/gnu/xml/dom/html2/DomHTMLParser.java b/gnu/xml/dom/html2/DomHTMLParser.java new file mode 100644 index 000000000..f1b970e12 --- /dev/null +++ b/gnu/xml/dom/html2/DomHTMLParser.java @@ -0,0 +1,266 @@ +/* DomHTMLParser.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.javax.swing.text.html.parser.support.Parser; + +import java.io.IOException; +import java.io.Reader; + +import java.util.Enumeration; +import java.util.Iterator; +import java.util.LinkedList; + +import javax.swing.text.AttributeSet; +import javax.swing.text.html.HTML; +import javax.swing.text.html.parser.DTD; +import javax.swing.text.html.parser.TagElement; + +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.html2.HTMLDocument; + +/** + * This parser reads HTML from the given stream and stores into + * {@link HTMLDocument}. The HTML tag becomes the {@link Node}. + * The tag attributes become the node attributes. The text inside + * HTML tag is inserted as one or several text nodes. The nested + * HTML tags are inserted as child nodes. + * + * If the strict tree structure, closing the tag means closing all + * nested tags. To work around this, this parser closes the nested + * tags and immediately reopens them after the closed tag. + * In this way, <code><b><i>c</b>d</code> + * is parsed as <code><b><i>c</i></b><i>d</code> . + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class DomHTMLParser + extends gnu.javax.swing.text.html.parser.support.Parser +{ + /** + * The target where HTML document will be inserted. + */ + protected DomHTMLDocument document; + + /** + * The subsequently created new nodes will be inserted as the + * childs of this cursor. + */ + protected Node cursor; + + /** + * Create parser using the given DTD. + * + * @param dtd the DTD (for example, + * {@link gnu.javax.swing.text.html.parser.HTML_401F}). + */ + public DomHTMLParser(DTD dtd) + { + super(dtd); + } + + /** + * Parse SGML insertion ( <! ... > ). + * Currently just treats it as comment. + */ + public boolean parseMarkupDeclarations(StringBuffer strBuff) + throws java.io.IOException + { + Node c = document.createComment(strBuff.toString()); + cursor.appendChild(c); + return false; + } + + /** + * Read the document, present in the given stream, and + * return the corresponding {@link HTMLDocument}. + * + * @param input a stream to read from. + * @return a document, reflecting the structure of the provided HTML + * text. + * + * @throws IOException if the reader throws one. + */ + public HTMLDocument parseDocument(Reader input) + throws IOException + { + try + { + document = new DomHTMLDocument(); + + cursor = document; + + parse(input); + + DomHTMLDocument h = document; + document = null; + return h; + } + catch (Exception ex) + { + ex.printStackTrace(); + throw new IOException("Exception: " + ex.getMessage()); + } + } + + /** + * Create a new node. + * @param name the name of node, case insensitive. + * @return the created node. + */ + protected Node createNode(String name) + { + Node new_node = document.createElement(name.toLowerCase()); + AttributeSet hatts = getAttributes(); + NamedNodeMap natts = new_node.getAttributes(); + + Enumeration enumeration = hatts.getAttributeNames(); + Object key; + Node attribute; + + while (hatts != null) + { + while (enumeration.hasMoreElements()) + { + key = enumeration.nextElement(); + attribute = document.createAttribute(key.toString()); + attribute.setNodeValue(hatts.getAttribute(key).toString()); + natts.setNamedItem(attribute); + } + + // The default values are stored in a parent node. + hatts = hatts.getResolveParent(); + } + + return new_node; + } + + /** + * Handle comment by inserting the comment node. + * @param text the comment text. + */ + protected void handleComment(char[] text) + { + Node c = document.createComment(new String(text)); + cursor.appendChild(c); + } + + /** + * Handle the tag with no content. + * @param tag the tag to handle. + */ + protected void handleEmptyTag(TagElement tag) + { + String name = tag.getHTMLTag().toString(); + + if (name.equalsIgnoreCase("#pcdata")) + return; + + Node c = createNode(name); + cursor.appendChild(c); + } + + /** + * Close the given tag. Close and reopen all nested tags. + * @param tag the tag to close. + */ + protected void handleEndTag(TagElement tag) + { + String name = tag.getHTMLTag().toString(); + String nname = cursor.getNodeName(); + + // Closing the current tag. + if (nname != null && nname.equalsIgnoreCase(name)) + { + cursor = cursor.getParentNode(); + } + else + { + Node nCursor = cursor.getParentNode(); + + // Remember the opened nodes. + LinkedList open = new LinkedList(); + Node close = cursor; + while (close != null && !close.getNodeName().equalsIgnoreCase(name)) + { + if (close != document) + open.addFirst(close); + close = close.getParentNode(); + } + + if (close == null) + cursor = document; + else + cursor = close.getParentNode(); + + // Insert the copies of the opened nodes. + Iterator iter = open.iterator(); + while (iter.hasNext()) + { + Node item = (Node) iter.next(); + Node copy = item.cloneNode(true); + cursor.appendChild(copy); + cursor = copy; + } + } + } + + /** + * Handle the start tag by inserting the HTML element. + * @param tag the tag to handle. + */ + protected void handleStartTag(TagElement tag) + { + HTML.Tag h = tag.getHTMLTag(); + Node c = createNode(h.toString()); + cursor.appendChild(c); + cursor = c; + } + + /** + * Handle text by inserting the text node. + * @param text the text to insert. + */ + protected void handleText(char[] text) + { + Node c = document.createTextNode(text, 0, text.length); + cursor.appendChild(c); + } +} diff --git a/gnu/xml/dom/html2/DomHTMLSelectElement.java b/gnu/xml/dom/html2/DomHTMLSelectElement.java index 6bc9bfc20..b888b57e6 100644 --- a/gnu/xml/dom/html2/DomHTMLSelectElement.java +++ b/gnu/xml/dom/html2/DomHTMLSelectElement.java @@ -199,12 +199,12 @@ public class DomHTMLSelectElement public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } } diff --git a/gnu/xml/dom/html2/DomHTMLTableCellElement.java b/gnu/xml/dom/html2/DomHTMLTableCellElement.java index b89c012a6..6338b88d0 100644 --- a/gnu/xml/dom/html2/DomHTMLTableCellElement.java +++ b/gnu/xml/dom/html2/DomHTMLTableCellElement.java @@ -58,8 +58,7 @@ public class DomHTMLTableCellElement public int getCellIndex() { - // TODO - return -1; + return getIndex(); } public String getAbbr() diff --git a/gnu/xml/dom/html2/DomHTMLTableElement.java b/gnu/xml/dom/html2/DomHTMLTableElement.java index 570b3f1e0..95e295733 100644 --- a/gnu/xml/dom/html2/DomHTMLTableElement.java +++ b/gnu/xml/dom/html2/DomHTMLTableElement.java @@ -37,6 +37,9 @@ exception statement from your version. */ 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 class DomHTMLTableElement 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 class DomHTMLTableElement 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; } - + } diff --git a/gnu/xml/dom/html2/DomHTMLTableRowElement.java b/gnu/xml/dom/html2/DomHTMLTableRowElement.java index 6b40b34e6..e21e158b4 100644 --- a/gnu/xml/dom/html2/DomHTMLTableRowElement.java +++ b/gnu/xml/dom/html2/DomHTMLTableRowElement.java @@ -37,6 +37,9 @@ exception statement from your version. */ 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 class DomHTMLTableRowElement 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 class DomHTMLTableRowElement 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; } } diff --git a/gnu/xml/dom/html2/DomHTMLTableSectionElement.java b/gnu/xml/dom/html2/DomHTMLTableSectionElement.java index c2247dfb7..45dd67110 100644 --- a/gnu/xml/dom/html2/DomHTMLTableSectionElement.java +++ b/gnu/xml/dom/html2/DomHTMLTableSectionElement.java @@ -37,6 +37,9 @@ exception statement from your version. */ 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 class DomHTMLTableSectionElement 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; } } diff --git a/gnu/xml/dom/html2/DomHTMLTextAreaElement.java b/gnu/xml/dom/html2/DomHTMLTextAreaElement.java index 9ef9b185c..93a918ab9 100644 --- a/gnu/xml/dom/html2/DomHTMLTextAreaElement.java +++ b/gnu/xml/dom/html2/DomHTMLTextAreaElement.java @@ -165,17 +165,17 @@ public class DomHTMLTextAreaElement public void blur() { - // TODO + dispatchUIEvent("blur"); } public void focus() { - // TODO + dispatchUIEvent("focus"); } public void select() { - // TODO + dispatchUIEvent("select"); } } |