From 9556f88777b749e2e436b61073ea9d3c68630f42 Mon Sep 17 00:00:00 2001 From: Anthony Green Date: Wed, 11 Jul 2001 03:59:16 +0000 Subject: Add some org packages. From-SVN: r43922 --- libjava/org/w3c/dom/Attr.java | 111 ++++++ libjava/org/w3c/dom/CDATASection.java | 48 +++ libjava/org/w3c/dom/CharacterData.java | 144 ++++++++ libjava/org/w3c/dom/Comment.java | 24 ++ libjava/org/w3c/dom/DOMException.java | 117 ++++++ libjava/org/w3c/dom/DOMImplementation.java | 100 ++++++ libjava/org/w3c/dom/Document.java | 365 +++++++++++++++++++ libjava/org/w3c/dom/DocumentFragment.java | 52 +++ libjava/org/w3c/dom/DocumentType.java | 79 ++++ libjava/org/w3c/dom/Element.java | 302 ++++++++++++++++ libjava/org/w3c/dom/Entity.java | 68 ++++ libjava/org/w3c/dom/EntityReference.java | 39 ++ libjava/org/w3c/dom/NamedNodeMap.java | 156 ++++++++ libjava/org/w3c/dom/Node.java | 390 ++++++++++++++++++++ libjava/org/w3c/dom/NodeList.java | 41 +++ libjava/org/w3c/dom/Notation.java | 40 +++ libjava/org/w3c/dom/ProcessingInstruction.java | 40 +++ libjava/org/w3c/dom/Text.java | 56 +++ libjava/org/w3c/dom/ranges/DocumentRange.java | 33 ++ libjava/org/w3c/dom/ranges/Range.java | 399 +++++++++++++++++++++ libjava/org/w3c/dom/ranges/RangeException.java | 39 ++ .../org/w3c/dom/traversal/DocumentTraversal.java | 90 +++++ libjava/org/w3c/dom/traversal/NodeFilter.java | 142 ++++++++ libjava/org/w3c/dom/traversal/NodeIterator.java | 108 ++++++ libjava/org/w3c/dom/traversal/TreeWalker.java | 167 +++++++++ 25 files changed, 3150 insertions(+) create mode 100644 libjava/org/w3c/dom/Attr.java create mode 100644 libjava/org/w3c/dom/CDATASection.java create mode 100644 libjava/org/w3c/dom/CharacterData.java create mode 100644 libjava/org/w3c/dom/Comment.java create mode 100644 libjava/org/w3c/dom/DOMException.java create mode 100644 libjava/org/w3c/dom/DOMImplementation.java create mode 100644 libjava/org/w3c/dom/Document.java create mode 100644 libjava/org/w3c/dom/DocumentFragment.java create mode 100644 libjava/org/w3c/dom/DocumentType.java create mode 100644 libjava/org/w3c/dom/Element.java create mode 100644 libjava/org/w3c/dom/Entity.java create mode 100644 libjava/org/w3c/dom/EntityReference.java create mode 100644 libjava/org/w3c/dom/NamedNodeMap.java create mode 100644 libjava/org/w3c/dom/Node.java create mode 100644 libjava/org/w3c/dom/NodeList.java create mode 100644 libjava/org/w3c/dom/Notation.java create mode 100644 libjava/org/w3c/dom/ProcessingInstruction.java create mode 100644 libjava/org/w3c/dom/Text.java create mode 100644 libjava/org/w3c/dom/ranges/DocumentRange.java create mode 100644 libjava/org/w3c/dom/ranges/Range.java create mode 100644 libjava/org/w3c/dom/ranges/RangeException.java create mode 100644 libjava/org/w3c/dom/traversal/DocumentTraversal.java create mode 100644 libjava/org/w3c/dom/traversal/NodeFilter.java create mode 100644 libjava/org/w3c/dom/traversal/NodeIterator.java create mode 100644 libjava/org/w3c/dom/traversal/TreeWalker.java (limited to 'libjava/org/w3c/dom') diff --git a/libjava/org/w3c/dom/Attr.java b/libjava/org/w3c/dom/Attr.java new file mode 100644 index 0000000..f54467f --- /dev/null +++ b/libjava/org/w3c/dom/Attr.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The Attr interface represents an attribute in an + * Element object. Typically the allowable values for the + * attribute are defined in a document type definition. + *

Attr objects inherit the Node interface, but + * since they are not actually child nodes of the element they describe, the + * DOM does not consider them part of the document tree. Thus, the + * Node attributes parentNode, + * previousSibling, and nextSibling have a + * null value for Attr objects. The DOM takes the + * view that attributes are properties of elements rather than having a + * separate identity from the elements they are associated with; this should + * make it more efficient to implement such features as default attributes + * associated with all elements of a given type. Furthermore, + * Attr nodes may not be immediate children of a + * DocumentFragment. However, they can be associated with + * Element nodes contained within a + * DocumentFragment. In short, users and implementors of the + * DOM need to be aware that Attr nodes have some things in + * common with other objects inheriting the Node interface, but + * they also are quite distinct. + *

The attribute's effective value is determined as follows: if this + * attribute has been explicitly assigned any value, that value is the + * attribute's effective value; otherwise, if there is a declaration for + * this attribute, and that declaration includes a default value, then that + * default value is the attribute's effective value; otherwise, the + * attribute does not exist on this element in the structure model until it + * has been explicitly added. Note that the nodeValue attribute + * on the Attr instance can also be used to retrieve the string + * version of the attribute's value(s). + *

In XML, where the value of an attribute can contain entity references, + * the child nodes of the Attr node may be either + * Text or EntityReference nodes (when these are + * in use; see the description of EntityReference for + * discussion). Because the DOM Core is not aware of attribute types, it + * treats all attribute values as simple strings, even if the DTD or schema + * declares them as having tokenized types. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Attr extends Node { + /** + * Returns the name of this attribute. + */ + public String getName(); + + /** + * If this attribute was explicitly given a value in the original + * document, this is true; otherwise, it is + * false. Note that the implementation is in charge of this + * attribute, not the user. If the user changes the value of the + * attribute (even if it ends up having the same value as the default + * value) then the specified flag is automatically flipped + * to true. To re-specify the attribute as the default + * value from the DTD, the user must delete the attribute. The + * implementation will then make a new attribute available with + * specified set to false and the default + * value (if one exists). + *
In summary: If the attribute has an assigned value in the document + * then specified is true, and the value is + * the assigned value. If the attribute has no assigned value in the + * document and has a default value in the DTD, then + * specified is false, and the value is the + * default value in the DTD. If the attribute has no assigned value in + * the document and has a value of #IMPLIED in the DTD, then the + * attribute does not appear in the structure model of the document. If + * the ownerElement attribute is null (i.e. + * because it was just created or was set to null by the + * various removal and cloning operations) specified is + * true. + */ + public boolean getSpecified(); + + /** + * On retrieval, the value of the attribute is returned as a string. + * Character and general entity references are replaced with their + * values. See also the method getAttribute on the + * Element interface. + *
On setting, this creates a Text node with the unparsed + * contents of the string. I.e. any characters that an XML processor + * would recognize as markup are instead treated as literal text. See + * also the method setAttribute on the Element + * interface. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. + */ + public String getValue(); + public void setValue(String value) + throws DOMException; + + /** + * The Element node this attribute is attached to or + * null if this attribute is not in use. + * @since DOM Level 2 + */ + public Element getOwnerElement(); + +} diff --git a/libjava/org/w3c/dom/CDATASection.java b/libjava/org/w3c/dom/CDATASection.java new file mode 100644 index 0000000..d9972ef --- /dev/null +++ b/libjava/org/w3c/dom/CDATASection.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * CDATA sections are used to escape blocks of text containing characters that + * would otherwise be regarded as markup. The only delimiter that is + * recognized in a CDATA section is the "]]>" string that ends the CDATA + * section. CDATA sections cannot be nested. Their primary purpose is for + * including material such as XML fragments, without needing to escape all + * the delimiters. + *

The DOMString attribute of the Text node holds + * the text that is contained by the CDATA section. Note that this may + * contain characters that need to be escaped outside of CDATA sections and + * that, depending on the character encoding ("charset") chosen for + * serialization, it may be impossible to write out some characters as part + * of a CDATA section. + *

The CDATASection interface inherits from the + * CharacterData interface through the Text + * interface. Adjacent CDATASection nodes are not merged by use + * of the normalize method of the Node interface. + * Because no markup is recognized within a CDATASection, + * character numeric references cannot be used as an escape mechanism when + * serializing. Therefore, action needs to be taken when serializing a + * CDATASection with a character encoding where some of the + * contained characters cannot be represented. Failure to do so would not + * produce well-formed XML.One potential solution in the serialization + * process is to end the CDATA section before the character, output the + * character using a character reference or entity reference, and open a new + * CDATA section for any further characters in the text node. Note, however, + * that some code conversion libraries at the time of writing do not return + * an error or exception when a character is missing from the encoding, + * making the task of ensuring that data is not corrupted on serialization + * more difficult. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface CDATASection extends Text { +} diff --git a/libjava/org/w3c/dom/CharacterData.java b/libjava/org/w3c/dom/CharacterData.java new file mode 100644 index 0000000..d459252 --- /dev/null +++ b/libjava/org/w3c/dom/CharacterData.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The CharacterData interface extends Node with a set of + * attributes and methods for accessing character data in the DOM. For + * clarity this set is defined here rather than on each object that uses + * these attributes and methods. No DOM objects correspond directly to + * CharacterData, though Text and others do + * inherit the interface from it. All offsets in this interface + * start from 0. + *

As explained in the DOMString interface, text strings in + * the DOM are represented in UTF-16, i.e. as a sequence of 16-bit units. In + * the following, the term 16-bit units is used whenever necessary to + * indicate that indexing on CharacterData is done in 16-bit units. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface CharacterData extends Node { + /** + * The character data of the node that implements this interface. The DOM + * implementation may not put arbitrary limits on the amount of data + * that may be stored in a CharacterData node. However, + * implementation limits may mean that the entirety of a node's data may + * not fit into a single DOMString. In such cases, the user + * may call substringData to retrieve the data in + * appropriately sized pieces. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. + * @exception DOMException + * DOMSTRING_SIZE_ERR: Raised when it would return more characters than + * fit in a DOMString variable on the implementation + * platform. + */ + public String getData() + throws DOMException; + public void setData(String data) + throws DOMException; + + /** + * The number of 16-bit units that are available through data + * and the substringData method below. This may have the + * value zero, i.e., CharacterData nodes may be empty. + */ + public int getLength(); + + /** + * Extracts a range of data from the node. + * @param offsetStart offset of substring to extract. + * @param countThe number of 16-bit units to extract. + * @return The specified substring. If the sum of offset and + * count exceeds the length, then all 16-bit + * units to the end of the data are returned. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if the specified offset is + * negative or greater than the number of 16-bit units in + * data, or if the specified count is + * negative. + *
DOMSTRING_SIZE_ERR: Raised if the specified range of text does + * not fit into a DOMString. + */ + public String substringData(int offset, + int count) + throws DOMException; + + /** + * Append the string to the end of the character data of the node. Upon + * success, data provides access to the concatenation of + * data and the DOMString specified. + * @param argThe DOMString to append. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void appendData(String arg) + throws DOMException; + + /** + * Insert a string at the specified 16-bit unit offset. + * @param offsetThe character offset at which to insert. + * @param argThe DOMString to insert. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if the specified offset is + * negative or greater than the number of 16-bit units in + * data. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void insertData(int offset, + String arg) + throws DOMException; + + /** + * Remove a range of 16-bit units from the node. Upon success, + * data and length reflect the change. + * @param offsetThe offset from which to start removing. + * @param countThe number of 16-bit units to delete. If the sum of + * offset and count exceeds + * length then all 16-bit units from offset + * to the end of the data are deleted. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if the specified offset is + * negative or greater than the number of 16-bit units in + * data, or if the specified count is + * negative. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void deleteData(int offset, + int count) + throws DOMException; + + /** + * Replace the characters starting at the specified 16-bit unit offset + * with the specified string. + * @param offsetThe offset from which to start replacing. + * @param countThe number of 16-bit units to replace. If the sum of + * offset and count exceeds + * length, then all 16-bit units to the end of the data + * are replaced; (i.e., the effect is the same as a remove + * method call with the same range, followed by an append + * method invocation). + * @param argThe DOMString with which the range must be + * replaced. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if the specified offset is + * negative or greater than the number of 16-bit units in + * data, or if the specified count is + * negative. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void replaceData(int offset, + int count, + String arg) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/Comment.java b/libjava/org/w3c/dom/Comment.java new file mode 100644 index 0000000..7c37d96 --- /dev/null +++ b/libjava/org/w3c/dom/Comment.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * This interface inherits from CharacterData and represents the + * content of a comment, i.e., all the characters between the starting ' + * <!--' and ending '-->'. Note that this is + * the definition of a comment in XML, and, in practice, HTML, although some + * HTML tools may implement the full SGML comment structure. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Comment extends CharacterData { +} diff --git a/libjava/org/w3c/dom/DOMException.java b/libjava/org/w3c/dom/DOMException.java new file mode 100644 index 0000000..41ad08a --- /dev/null +++ b/libjava/org/w3c/dom/DOMException.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * DOM operations only raise exceptions in "exceptional" circumstances, i.e., + * when an operation is impossible to perform (either for logical reasons, + * because data is lost, or because the implementation has become unstable). + * In general, DOM methods return specific error values in ordinary + * processing situations, such as out-of-bound errors when using + * NodeList. + *

Implementations should raise other exceptions under other circumstances. + * For example, implementations should raise an implementation-dependent + * exception if a null argument is passed. + *

Some languages and object systems do not support the concept of + * exceptions. For such systems, error conditions may be indicated using + * native error reporting mechanisms. For some bindings, for example, + * methods may return error codes similar to those listed in the + * corresponding method descriptions. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public class DOMException extends RuntimeException { + public DOMException(short code, String message) { + super(message); + this.code = code; + } + /** @serial */ + public short code; + // ExceptionCode + /** + * If index or size is negative, or greater than the allowed value + */ + public static final short INDEX_SIZE_ERR = 1; + /** + * If the specified range of text does not fit into a DOMString + */ + public static final short DOMSTRING_SIZE_ERR = 2; + /** + * If any node is inserted somewhere it doesn't belong + */ + public static final short HIERARCHY_REQUEST_ERR = 3; + /** + * If a node is used in a different document than the one that created it + * (that doesn't support it) + */ + public static final short WRONG_DOCUMENT_ERR = 4; + /** + * If an invalid or illegal character is specified, such as in a name. See + * production 2 in the XML specification for the definition of a legal + * character, and production 5 for the definition of a legal name + * character. + */ + public static final short INVALID_CHARACTER_ERR = 5; + /** + * If data is specified for a node which does not support data + */ + public static final short NO_DATA_ALLOWED_ERR = 6; + /** + * If an attempt is made to modify an object where modifications are not + * allowed + */ + public static final short NO_MODIFICATION_ALLOWED_ERR = 7; + /** + * If an attempt is made to reference a node in a context where it does + * not exist + */ + public static final short NOT_FOUND_ERR = 8; + /** + * If the implementation does not support the requested type of object or + * operation. + */ + public static final short NOT_SUPPORTED_ERR = 9; + /** + * If an attempt is made to add an attribute that is already in use + * elsewhere + */ + public static final short INUSE_ATTRIBUTE_ERR = 10; + /** + * If an attempt is made to use an object that is not, or is no longer, + * usable. + * @since DOM Level 2 + */ + public static final short INVALID_STATE_ERR = 11; + /** + * If an invalid or illegal string is specified. + * @since DOM Level 2 + */ + public static final short SYNTAX_ERR = 12; + /** + * If an attempt is made to modify the type of the underlying object. + * @since DOM Level 2 + */ + public static final short INVALID_MODIFICATION_ERR = 13; + /** + * If an attempt is made to create or change an object in a way which is + * incorrect with regard to namespaces. + * @since DOM Level 2 + */ + public static final short NAMESPACE_ERR = 14; + /** + * If a parameter or an operation is not supported by the underlying + * object. + * @since DOM Level 2 + */ + public static final short INVALID_ACCESS_ERR = 15; + +} diff --git a/libjava/org/w3c/dom/DOMImplementation.java b/libjava/org/w3c/dom/DOMImplementation.java new file mode 100644 index 0000000..b11d715 --- /dev/null +++ b/libjava/org/w3c/dom/DOMImplementation.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The DOMImplementation interface provides a number of methods + * for performing operations that are independent of any particular instance + * of the document object model. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface DOMImplementation { + /** + * Test if the DOM implementation implements a specific feature. + * @param featureThe name of the feature to test (case-insensitive). The + * values used by DOM features are defined throughout the DOM Level 2 + * specifications and listed in the section. The name must be an XML + * name. To avoid possible conflicts, as a convention, names referring + * to features defined outside the DOM specification should be made + * unique by reversing the name of the Internet domain name of the + * person (or the organization that the person belongs to) who defines + * the feature, component by component, and using this as a prefix. + * For instance, the W3C SVG Working Group defines the feature + * "org.w3c.dom.svg". + * @param versionThis is the version number of the feature to test. In + * Level 2, the string can be either "2.0" or "1.0". If the version is + * not specified, supporting any version of the feature causes the + * method to return true. + * @return true if the feature is implemented in the + * specified version, false otherwise. + */ + public boolean hasFeature(String feature, + String version); + + /** + * Creates an empty DocumentType node. Entity declarations + * and notations are not made available. Entity reference expansions and + * default attribute additions do not occur. It is expected that a + * future version of the DOM will provide a way for populating a + * DocumentType. + *
HTML-only DOM implementations do not need to implement this method. + * @param qualifiedNameThe qualified name of the document type to be + * created. + * @param publicIdThe external subset public identifier. + * @param systemIdThe external subset system identifier. + * @return A new DocumentType node with + * Node.ownerDocument set to null. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified qualified name + * contains an illegal character. + *
NAMESPACE_ERR: Raised if the qualifiedName is + * malformed. + * @since DOM Level 2 + */ + public DocumentType createDocumentType(String qualifiedName, + String publicId, + String systemId) + throws DOMException; + + /** + * Creates an XML Document object of the specified type with + * its document element. HTML-only DOM implementations do not need to + * implement this method. + * @param namespaceURIThe namespace URI of the document element to create. + * @param qualifiedNameThe qualified name of the document element to be + * created. + * @param doctypeThe type of document to be created or null. + * When doctype is not null, its + * Node.ownerDocument attribute is set to the document + * being created. + * @return A new Document object. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified qualified name + * contains an illegal character. + *
NAMESPACE_ERR: Raised if the qualifiedName is + * malformed, if the qualifiedName has a prefix and the + * namespaceURI is null, or if the + * qualifiedName has a prefix that is "xml" and the + * namespaceURI is different from " + * http://www.w3.org/XML/1998/namespace" . + *
WRONG_DOCUMENT_ERR: Raised if doctype has already + * been used with a different document or was created from a different + * implementation. + * @since DOM Level 2 + */ + public Document createDocument(String namespaceURI, + String qualifiedName, + DocumentType doctype) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/Document.java b/libjava/org/w3c/dom/Document.java new file mode 100644 index 0000000..2db27c9 --- /dev/null +++ b/libjava/org/w3c/dom/Document.java @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The Document interface represents the entire HTML or XML + * document. Conceptually, it is the root of the document tree, and provides + * the primary access to the document's data. + *

Since elements, text nodes, comments, processing instructions, etc. + * cannot exist outside the context of a Document, the + * Document interface also contains the factory methods needed + * to create these objects. The Node objects created have a + * ownerDocument attribute which associates them with the + * Document within whose context they were created. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Document extends Node { + /** + * The Document Type Declaration (see DocumentType) + * associated with this document. For HTML documents as well as XML + * documents without a document type declaration this returns + * null. The DOM Level 2 does not support editing the + * Document Type Declaration. docType cannot be altered in + * any way, including through the use of methods inherited from the + * Node interface, such as insertNode or + * removeNode. + */ + public DocumentType getDoctype(); + + /** + * The DOMImplementation object that handles this document. A + * DOM application may use objects from multiple implementations. + */ + public DOMImplementation getImplementation(); + + /** + * This is a convenience attribute that allows direct access to the child + * node that is the root element of the document. For HTML documents, + * this is the element with the tagName "HTML". + */ + public Element getDocumentElement(); + + /** + * Creates an element of the type specified. Note that the instance + * returned implements the Element interface, so attributes + * can be specified directly on the returned object. + *
In addition, if there are known attributes with default values, + * Attr nodes representing them are automatically created + * and attached to the element. + *
To create an element with a qualified name and namespace URI, use + * the createElementNS method. + * @param tagNameThe name of the element type to instantiate. For XML, + * this is case-sensitive. For HTML, the tagName + * parameter may be provided in any case, but it must be mapped to the + * canonical uppercase form by the DOM implementation. + * @return A new Element object with the + * nodeName attribute set to tagName, and + * localName, prefix, and + * namespaceURI set to null. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified name contains an + * illegal character. + */ + public Element createElement(String tagName) + throws DOMException; + + /** + * Creates an empty DocumentFragment object. + * @return A new DocumentFragment. + */ + public DocumentFragment createDocumentFragment(); + + /** + * Creates a Text node given the specified string. + * @param dataThe data for the node. + * @return The new Text object. + */ + public Text createTextNode(String data); + + /** + * Creates a Comment node given the specified string. + * @param dataThe data for the node. + * @return The new Comment object. + */ + public Comment createComment(String data); + + /** + * Creates a CDATASection node whose value is the specified + * string. + * @param dataThe data for the CDATASection contents. + * @return The new CDATASection object. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if this document is an HTML document. + */ + public CDATASection createCDATASection(String data) + throws DOMException; + + /** + * Creates a ProcessingInstruction node given the specified + * name and data strings. + * @param targetThe target part of the processing instruction. + * @param dataThe data for the node. + * @return The new ProcessingInstruction object. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified target contains an + * illegal character. + *
NOT_SUPPORTED_ERR: Raised if this document is an HTML document. + */ + public ProcessingInstruction createProcessingInstruction(String target, + String data) + throws DOMException; + + /** + * Creates an Attr of the given name. Note that the + * Attr instance can then be set on an Element + * using the setAttributeNode method. + *
To create an attribute with a qualified name and namespace URI, use + * the createAttributeNS method. + * @param nameThe name of the attribute. + * @return A new Attr object with the nodeName + * attribute set to name, and localName, + * prefix, and namespaceURI set to + * null. The value of the attribute is the empty string. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified name contains an + * illegal character. + */ + public Attr createAttribute(String name) + throws DOMException; + + /** + * Creates an EntityReference object. In addition, if the + * referenced entity is known, the child list of the + * EntityReference node is made the same as that of the + * corresponding Entity node.If any descendant of the + * Entity node has an unbound namespace prefix, the + * corresponding descendant of the created EntityReference + * node is also unbound; (its namespaceURI is + * null). The DOM Level 2 does not support any mechanism to + * resolve namespace prefixes. + * @param nameThe name of the entity to reference. + * @return The new EntityReference object. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified name contains an + * illegal character. + *
NOT_SUPPORTED_ERR: Raised if this document is an HTML document. + */ + public EntityReference createEntityReference(String name) + throws DOMException; + + /** + * Returns a NodeList of all the Elements with a + * given tag name in the order in which they are encountered in a + * preorder traversal of the Document tree. + * @param tagnameThe name of the tag to match on. The special value "*" + * matches all tags. + * @return A new NodeList object containing all the matched + * Elements. + */ + public NodeList getElementsByTagName(String tagname); + + /** + * Imports a node from another document to this document. The returned + * node has no parent; (parentNode is null). + * The source node is not altered or removed from the original document; + * this method creates a new copy of the source node. + *
For all nodes, importing a node creates a node object owned by the + * importing document, with attribute values identical to the source + * node's nodeName and nodeType, plus the + * attributes related to namespaces (prefix, + * localName, and namespaceURI). As in the + * cloneNode operation on a Node, the source + * node is not altered. + *
Additional information is copied as appropriate to the + * nodeType, attempting to mirror the behavior expected if + * a fragment of XML or HTML source was copied from one document to + * another, recognizing that the two documents may have different DTDs + * in the XML case. The following list describes the specifics for each + * type of node. + *

+ *
ATTRIBUTE_NODE
+ *
The ownerElement attribute + * is set to null and the specified flag is + * set to true on the generated Attr. The + * descendants of the source Attr are recursively imported + * and the resulting nodes reassembled to form the corresponding subtree. + * Note that the deep parameter has no effect on + * Attr nodes; they always carry their children with them + * when imported.
+ *
DOCUMENT_FRAGMENT_NODE
+ *
If the deep option + * was set to true, the descendants of the source element + * are recursively imported and the resulting nodes reassembled to form + * the corresponding subtree. Otherwise, this simply generates an empty + * DocumentFragment.
+ *
DOCUMENT_NODE
+ *
Document + * nodes cannot be imported.
+ *
DOCUMENT_TYPE_NODE
+ *
DocumentType + * nodes cannot be imported.
+ *
ELEMENT_NODE
+ *
Specified attribute nodes of the + * source element are imported, and the generated Attr + * nodes are attached to the generated Element. Default + * attributes are not copied, though if the document being imported into + * defines default attributes for this element name, those are assigned. + * If the importNode deep parameter was set to + * true, the descendants of the source element are + * recursively imported and the resulting nodes reassembled to form the + * corresponding subtree.
+ *
ENTITY_NODE
+ *
Entity nodes can be + * imported, however in the current release of the DOM the + * DocumentType is readonly. Ability to add these imported + * nodes to a DocumentType will be considered for addition + * to a future release of the DOM.On import, the publicId, + * systemId, and notationName attributes are + * copied. If a deep import is requested, the descendants + * of the the source Entity are recursively imported and + * the resulting nodes reassembled to form the corresponding subtree.
+ *
+ * ENTITY_REFERENCE_NODE
+ *
Only the EntityReference itself is + * copied, even if a deep import is requested, since the + * source and destination documents might have defined the entity + * differently. If the document being imported into provides a + * definition for this entity name, its value is assigned.
+ *
NOTATION_NODE
+ *
+ * Notation nodes can be imported, however in the current + * release of the DOM the DocumentType is readonly. Ability + * to add these imported nodes to a DocumentType will be + * considered for addition to a future release of the DOM.On import, the + * publicId and systemId attributes are copied. + * Note that the deep parameter has no effect on + * Notation nodes since they never have any children.
+ *
+ * PROCESSING_INSTRUCTION_NODE
+ *
The imported node copies its + * target and data values from those of the + * source node.
+ *
TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE
+ *
These three + * types of nodes inheriting from CharacterData copy their + * data and length attributes from those of + * the source node.
+ * + * @param importedNodeThe node to import. + * @param deepIf true, recursively import the subtree under + * the specified node; if false, import only the node + * itself, as explained above. This has no effect on Attr + * , EntityReference, and Notation nodes. + * @return The imported node that belongs to this Document. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not + * supported. + * @since DOM Level 2 + */ + public Node importNode(Node importedNode, + boolean deep) + throws DOMException; + + /** + * Creates an element of the given qualified name and namespace URI. + * HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the element to create. + * @param qualifiedNameThe qualified name of the element type to + * instantiate. + * @return A new Element object with the following + * attributes:AttributeValueNode.nodeName + * qualifiedNameNode.namespaceURI + * namespaceURINode.prefixprefix, extracted + * from qualifiedName, or null if there is + * no prefixNode.localNamelocal name, extracted from + * qualifiedNameElement.tagName + * qualifiedName + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified qualified name + * contains an illegal character. + *
NAMESPACE_ERR: Raised if the qualifiedName is + * malformed, if the qualifiedName has a prefix and the + * namespaceURI is null, or if the + * qualifiedName has a prefix that is "xml" and the + * namespaceURI is different from " + * http://www.w3.org/XML/1998/namespace" . + * @since DOM Level 2 + */ + public Element createElementNS(String namespaceURI, + String qualifiedName) + throws DOMException; + + /** + * Creates an attribute of the given qualified name and namespace URI. + * HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to create. + * @param qualifiedNameThe qualified name of the attribute to instantiate. + * @return A new Attr object with the following attributes: + * AttributeValueNode.nodeNamequalifiedName + * Node.namespaceURInamespaceURI + * Node.prefixprefix, extracted from + * qualifiedName, or null if there is no + * prefixNode.localNamelocal name, extracted from + * qualifiedNameAttr.name + * qualifiedNameNode.nodeValuethe empty + * string + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified qualified name + * contains an illegal character. + *
NAMESPACE_ERR: Raised if the qualifiedName is + * malformed, if the qualifiedName has a prefix and the + * namespaceURI is null, if the + * qualifiedName has a prefix that is "xml" and the + * namespaceURI is different from " + * http://www.w3.org/XML/1998/namespace", or if the + * qualifiedName is "xmlns" and the + * namespaceURI is different from " + * http://www.w3.org/2000/xmlns/". + * @since DOM Level 2 + */ + public Attr createAttributeNS(String namespaceURI, + String qualifiedName) + throws DOMException; + + /** + * Returns a NodeList of all the Elements with a + * given local name and namespace URI in the order in which they are + * encountered in a preorder traversal of the Document tree. + * @param namespaceURIThe namespace URI of the elements to match on. The + * special value "*" matches all namespaces. + * @param localNameThe local name of the elements to match on. The + * special value "*" matches all local names. + * @return A new NodeList object containing all the matched + * Elements. + * @since DOM Level 2 + */ + public NodeList getElementsByTagNameNS(String namespaceURI, + String localName); + + /** + * Returns the Element whose ID is given by + * elementId. If no such element exists, returns + * null. Behavior is not defined if more than one element + * has this ID. The DOM implementation must have + * information that says which attributes are of type ID. Attributes + * with the name "ID" are not of type ID unless so defined. + * Implementations that do not know whether attributes are of type ID or + * not are expected to return null. + * @param elementIdThe unique id value for an element. + * @return The matching element. + * @since DOM Level 2 + */ + public Element getElementById(String elementId); + +} diff --git a/libjava/org/w3c/dom/DocumentFragment.java b/libjava/org/w3c/dom/DocumentFragment.java new file mode 100644 index 0000000..9579eb7 --- /dev/null +++ b/libjava/org/w3c/dom/DocumentFragment.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * DocumentFragment is a "lightweight" or "minimal" + * Document object. It is very common to want to be able to + * extract a portion of a document's tree or to create a new fragment of a + * document. Imagine implementing a user command like cut or rearranging a + * document by moving fragments around. It is desirable to have an object + * which can hold such fragments and it is quite natural to use a Node for + * this purpose. While it is true that a Document object could + * fulfill this role, a Document object can potentially be a + * heavyweight object, depending on the underlying implementation. What is + * really needed for this is a very lightweight object. + * DocumentFragment is such an object. + *

Furthermore, various operations -- such as inserting nodes as children + * of another Node -- may take DocumentFragment + * objects as arguments; this results in all the child nodes of the + * DocumentFragment being moved to the child list of this node. + *

The children of a DocumentFragment node are zero or more + * nodes representing the tops of any sub-trees defining the structure of + * the document. DocumentFragment nodes do not need to be + * well-formed XML documents (although they do need to follow the rules + * imposed upon well-formed XML parsed entities, which can have multiple top + * nodes). For example, a DocumentFragment might have only one + * child and that child node could be a Text node. Such a + * structure model represents neither an HTML document nor a well-formed XML + * document. + *

When a DocumentFragment is inserted into a + * Document (or indeed any other Node that may + * take children) the children of the DocumentFragment and not + * the DocumentFragment itself are inserted into the + * Node. This makes the DocumentFragment very + * useful when the user wishes to create nodes that are siblings; the + * DocumentFragment acts as the parent of these nodes so that + * the user can use the standard methods from the Node + * interface, such as insertBefore and appendChild. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface DocumentFragment extends Node { +} diff --git a/libjava/org/w3c/dom/DocumentType.java b/libjava/org/w3c/dom/DocumentType.java new file mode 100644 index 0000000..0bbcfac --- /dev/null +++ b/libjava/org/w3c/dom/DocumentType.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * Each Document has a doctype attribute whose value + * is either null or a DocumentType object. The + * DocumentType interface in the DOM Core provides an interface + * to the list of entities that are defined for the document, and little + * else because the effect of namespaces and the various XML schema efforts + * on DTD representation are not clearly understood as of this writing. + *

The DOM Level 2 doesn't support editing DocumentType nodes. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface DocumentType extends Node { + /** + * The name of DTD; i.e., the name immediately following the + * DOCTYPE keyword. + */ + public String getName(); + + /** + * A NamedNodeMap containing the general entities, both + * external and internal, declared in the DTD. Parameter entities are + * not contained. Duplicates are discarded. For example in: + *

<!DOCTYPE 
+     * ex SYSTEM "ex.dtd" [ <!ENTITY foo "foo"> <!ENTITY bar 
+     * "bar"> <!ENTITY bar "bar2"> <!ENTITY % baz "baz"> 
+     * ]> <ex/>
+ * the interface provides access to foo + * and the first declaration of bar but not the second + * declaration of bar or baz. Every node in + * this map also implements the Entity interface. + *
The DOM Level 2 does not support editing entities, therefore + * entities cannot be altered in any way. + */ + public NamedNodeMap getEntities(); + + /** + * A NamedNodeMap containing the notations declared in the + * DTD. Duplicates are discarded. Every node in this map also implements + * the Notation interface. + *
The DOM Level 2 does not support editing notations, therefore + * notations cannot be altered in any way. + */ + public NamedNodeMap getNotations(); + + /** + * The public identifier of the external subset. + * @since DOM Level 2 + */ + public String getPublicId(); + + /** + * The system identifier of the external subset. + * @since DOM Level 2 + */ + public String getSystemId(); + + /** + * The internal subset as a string.The actual content returned depends on + * how much information is available to the implementation. This may + * vary depending on various parameters, including the XML processor + * used to build the document. + * @since DOM Level 2 + */ + public String getInternalSubset(); + +} diff --git a/libjava/org/w3c/dom/Element.java b/libjava/org/w3c/dom/Element.java new file mode 100644 index 0000000..85277fa --- /dev/null +++ b/libjava/org/w3c/dom/Element.java @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The Element interface represents an element in an HTML or XML + * document. Elements may have attributes associated with them; since the + * Element interface inherits from Node, the + * generic Node interface attribute attributes may + * be used to retrieve the set of all attributes for an element. There are + * methods on the Element interface to retrieve either an + * Attr object by name or an attribute value by name. In XML, + * where an attribute value may contain entity references, an + * Attr object should be retrieved to examine the possibly + * fairly complex sub-tree representing the attribute value. On the other + * hand, in HTML, where all attributes have simple string values, methods to + * directly access an attribute value can safely be used as a convenience.In + * DOM Level 2, the method normalize is inherited from the + * Node interface where it was moved. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Element extends Node { + /** + * The name of the element. For example, in: + *

 <elementExample 
+     * id="demo"> ... </elementExample> , 
+ * tagName has + * the value "elementExample". Note that this is + * case-preserving in XML, as are all of the operations of the DOM. The + * HTML DOM returns the tagName of an HTML element in the + * canonical uppercase form, regardless of the case in the source HTML + * document. + */ + public String getTagName(); + + /** + * Retrieves an attribute value by name. + * @param nameThe name of the attribute to retrieve. + * @return The Attr value as a string, or the empty string + * if that attribute does not have a specified or default value. + */ + public String getAttribute(String name); + + /** + * Adds a new attribute. If an attribute with that name is already present + * in the element, its value is changed to be that of the value + * parameter. This value is a simple string; it is not parsed as it is + * being set. So any markup (such as syntax to be recognized as an + * entity reference) is treated as literal text, and needs to be + * appropriately escaped by the implementation when it is written out. + * In order to assign an attribute value that contains entity + * references, the user must create an Attr node plus any + * Text and EntityReference nodes, build the + * appropriate subtree, and use setAttributeNode to assign + * it as the value of an attribute. + *
To set an attribute with a qualified name and namespace URI, use + * the setAttributeNS method. + * @param nameThe name of the attribute to create or alter. + * @param valueValue to set in string form. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified name contains an + * illegal character. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void setAttribute(String name, + String value) + throws DOMException; + + /** + * Removes an attribute by name. If the removed attribute is known to have + * a default value, an attribute immediately appears containing the + * default value as well as the corresponding namespace URI, local name, + * and prefix when applicable. + *
To remove an attribute by local name and namespace URI, use the + * removeAttributeNS method. + * @param nameThe name of the attribute to remove. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public void removeAttribute(String name) + throws DOMException; + + /** + * Retrieves an attribute node by name. + *
To retrieve an attribute node by qualified name and namespace URI, + * use the getAttributeNodeNS method. + * @param nameThe name (nodeName) of the attribute to + * retrieve. + * @return The Attr node with the specified name ( + * nodeName) or null if there is no such + * attribute. + */ + public Attr getAttributeNode(String name); + + /** + * Adds a new attribute node. If an attribute with that name ( + * nodeName) is already present in the element, it is + * replaced by the new one. + *
To add a new attribute node with a qualified name and namespace + * URI, use the setAttributeNodeNS method. + * @param newAttrThe Attr node to add to the attribute list. + * @return If the newAttr attribute replaces an existing + * attribute, the replaced Attr node is returned, + * otherwise null is returned. + * @exception DOMException + * WRONG_DOCUMENT_ERR: Raised if newAttr was created from a + * different document than the one that created the element. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an + * attribute of another Element object. The DOM user must + * explicitly clone Attr nodes to re-use them in other + * elements. + */ + public Attr setAttributeNode(Attr newAttr) + throws DOMException; + + /** + * Removes the specified attribute node. If the removed Attr + * has a default value it is immediately replaced. The replacing + * attribute has the same namespace URI and local name, as well as the + * original prefix, when applicable. + * @param oldAttrThe Attr node to remove from the attribute + * list. + * @return The Attr node that was removed. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
NOT_FOUND_ERR: Raised if oldAttr is not an attribute + * of the element. + */ + public Attr removeAttributeNode(Attr oldAttr) + throws DOMException; + + /** + * Returns a NodeList of all descendant Elements + * with a given tag name, in the order in which they are encountered in + * a preorder traversal of this Element tree. + * @param nameThe name of the tag to match on. The special value "*" + * matches all tags. + * @return A list of matching Element nodes. + */ + public NodeList getElementsByTagName(String name); + + /** + * Retrieves an attribute value by local name and namespace URI. HTML-only + * DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to retrieve. + * @param localNameThe local name of the attribute to retrieve. + * @return The Attr value as a string, or the empty string + * if that attribute does not have a specified or default value. + * @since DOM Level 2 + */ + public String getAttributeNS(String namespaceURI, + String localName); + + /** + * Adds a new attribute. If an attribute with the same local name and + * namespace URI is already present on the element, its prefix is + * changed to be the prefix part of the qualifiedName, and + * its value is changed to be the value parameter. This + * value is a simple string; it is not parsed as it is being set. So any + * markup (such as syntax to be recognized as an entity reference) is + * treated as literal text, and needs to be appropriately escaped by the + * implementation when it is written out. In order to assign an + * attribute value that contains entity references, the user must create + * an Attr node plus any Text and + * EntityReference nodes, build the appropriate subtree, + * and use setAttributeNodeNS or + * setAttributeNode to assign it as the value of an + * attribute. + *
HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to create or + * alter. + * @param qualifiedNameThe qualified name of the attribute to create or + * alter. + * @param valueThe value to set in string form. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified qualified name + * contains an illegal character. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
NAMESPACE_ERR: Raised if the qualifiedName is + * malformed, if the qualifiedName has a prefix and the + * namespaceURI is null, if the + * qualifiedName has a prefix that is "xml" and the + * namespaceURI is different from " + * http://www.w3.org/XML/1998/namespace", or if the + * qualifiedName is "xmlns" and the + * namespaceURI is different from " + * http://www.w3.org/2000/xmlns/". + * @since DOM Level 2 + */ + public void setAttributeNS(String namespaceURI, + String qualifiedName, + String value) + throws DOMException; + + /** + * Removes an attribute by local name and namespace URI. If the removed + * attribute has a default value it is immediately replaced. The + * replacing attribute has the same namespace URI and local name, as + * well as the original prefix. + *
HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to remove. + * @param localNameThe local name of the attribute to remove. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + * @since DOM Level 2 + */ + public void removeAttributeNS(String namespaceURI, + String localName) + throws DOMException; + + /** + * Retrieves an Attr node by local name and namespace URI. + * HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to retrieve. + * @param localNameThe local name of the attribute to retrieve. + * @return The Attr node with the specified attribute local + * name and namespace URI or null if there is no such + * attribute. + * @since DOM Level 2 + */ + public Attr getAttributeNodeNS(String namespaceURI, + String localName); + + /** + * Adds a new attribute. If an attribute with that local name and that + * namespace URI is already present in the element, it is replaced by + * the new one. + *
HTML-only DOM implementations do not need to implement this method. + * @param newAttrThe Attr node to add to the attribute list. + * @return If the newAttr attribute replaces an existing + * attribute with the same local name and namespace URI, the replaced + * Attr node is returned, otherwise null is + * returned. + * @exception DOMException + * WRONG_DOCUMENT_ERR: Raised if newAttr was created from a + * different document than the one that created the element. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an + * attribute of another Element object. The DOM user must + * explicitly clone Attr nodes to re-use them in other + * elements. + * @since DOM Level 2 + */ + public Attr setAttributeNodeNS(Attr newAttr) + throws DOMException; + + /** + * Returns a NodeList of all the descendant + * Elements with a given local name and namespace URI in + * the order in which they are encountered in a preorder traversal of + * this Element tree. + *
HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the elements to match on. The + * special value "*" matches all namespaces. + * @param localNameThe local name of the elements to match on. The + * special value "*" matches all local names. + * @return A new NodeList object containing all the matched + * Elements. + * @since DOM Level 2 + */ + public NodeList getElementsByTagNameNS(String namespaceURI, + String localName); + + /** + * Returns true when an attribute with a given name is + * specified on this element or has a default value, false + * otherwise. + * @param nameThe name of the attribute to look for. + * @return true if an attribute with the given name is + * specified on this element or has a default value, false + * otherwise. + * @since DOM Level 2 + */ + public boolean hasAttribute(String name); + + /** + * Returns true when an attribute with a given local name and + * namespace URI is specified on this element or has a default value, + * false otherwise. HTML-only DOM implementations do not + * need to implement this method. + * @param namespaceURIThe namespace URI of the attribute to look for. + * @param localNameThe local name of the attribute to look for. + * @return true if an attribute with the given local name + * and namespace URI is specified or has a default value on this + * element, false otherwise. + * @since DOM Level 2 + */ + public boolean hasAttributeNS(String namespaceURI, + String localName); + +} diff --git a/libjava/org/w3c/dom/Entity.java b/libjava/org/w3c/dom/Entity.java new file mode 100644 index 0000000..51a69cb --- /dev/null +++ b/libjava/org/w3c/dom/Entity.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * This interface represents an entity, either parsed or unparsed, in an XML + * document. Note that this models the entity itself not the entity + * declaration. Entity declaration modeling has been left for a + * later Level of the DOM specification. + *

The nodeName attribute that is inherited from + * Node contains the name of the entity. + *

An XML processor may choose to completely expand entities before the + * structure model is passed to the DOM; in this case there will be no + * EntityReference nodes in the document tree. + *

XML does not mandate that a non-validating XML processor read and + * process entity declarations made in the external subset or declared in + * external parameter entities. This means that parsed entities declared in + * the external subset need not be expanded by some classes of applications, + * and that the replacement value of the entity may not be available. When + * the replacement value is available, the corresponding Entity + * node's child list represents the structure of that replacement text. + * Otherwise, the child list is empty. + *

The DOM Level 2 does not support editing Entity nodes; if a + * user wants to make changes to the contents of an Entity, + * every related EntityReference node has to be replaced in the + * structure model by a clone of the Entity's contents, and + * then the desired changes must be made to each of those clones instead. + * Entity nodes and all their descendants are readonly. + *

An Entity node does not have any parent.If the entity + * contains an unbound namespace prefix, the namespaceURI of + * the corresponding node in the Entity node subtree is + * null. The same is true for EntityReference + * nodes that refer to this entity, when they are created using the + * createEntityReference method of the Document + * interface. The DOM Level 2 does not support any mechanism to resolve + * namespace prefixes. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Entity extends Node { + /** + * The public identifier associated with the entity, if specified. If the + * public identifier was not specified, this is null. + */ + public String getPublicId(); + + /** + * The system identifier associated with the entity, if specified. If the + * system identifier was not specified, this is null. + */ + public String getSystemId(); + + /** + * For unparsed entities, the name of the notation for the entity. For + * parsed entities, this is null. + */ + public String getNotationName(); + +} diff --git a/libjava/org/w3c/dom/EntityReference.java b/libjava/org/w3c/dom/EntityReference.java new file mode 100644 index 0000000..31c854d --- /dev/null +++ b/libjava/org/w3c/dom/EntityReference.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * EntityReference objects may be inserted into the structure + * model when an entity reference is in the source document, or when the + * user wishes to insert an entity reference. Note that character references + * and references to predefined entities are considered to be expanded by + * the HTML or XML processor so that characters are represented by their + * Unicode equivalent rather than by an entity reference. Moreover, the XML + * processor may completely expand references to entities while building the + * structure model, instead of providing EntityReference + * objects. If it does provide such objects, then for a given + * EntityReference node, it may be that there is no + * Entity node representing the referenced entity. If such an + * Entity exists, then the subtree of the + * EntityReference node is in general a copy of the + * Entity node subtree. However, this may not be true when an + * entity contains an unbound namespace prefix. In such a case, because the + * namespace prefix resolution depends on where the entity reference is, the + * descendants of the EntityReference node may be bound to + * different namespace URIs. + *

As for Entity nodes, EntityReference nodes and + * all their descendants are readonly. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface EntityReference extends Node { +} diff --git a/libjava/org/w3c/dom/NamedNodeMap.java b/libjava/org/w3c/dom/NamedNodeMap.java new file mode 100644 index 0000000..d57ba8d --- /dev/null +++ b/libjava/org/w3c/dom/NamedNodeMap.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * Objects implementing the NamedNodeMap interface are used to + * represent collections of nodes that can be accessed by name. Note that + * NamedNodeMap does not inherit from NodeList; + * NamedNodeMaps are not maintained in any particular order. + * Objects contained in an object implementing NamedNodeMap may + * also be accessed by an ordinal index, but this is simply to allow + * convenient enumeration of the contents of a NamedNodeMap, + * and does not imply that the DOM specifies an order to these Nodes. + *

NamedNodeMap objects in the DOM are live. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface NamedNodeMap { + /** + * Retrieves a node specified by name. + * @param nameThe nodeName of a node to retrieve. + * @return A Node (of any type) with the specified + * nodeName, or null if it does not identify + * any node in this map. + */ + public Node getNamedItem(String name); + + /** + * Adds a node using its nodeName attribute. If a node with + * that name is already present in this map, it is replaced by the new + * one. + *
As the nodeName attribute is used to derive the name + * which the node must be stored under, multiple nodes of certain types + * (those that have a "special" string value) cannot be stored as the + * names would clash. This is seen as preferable to allowing nodes to be + * aliased. + * @param argA node to store in this map. The node will later be + * accessible using the value of its nodeName attribute. + * @return If the new Node replaces an existing node the + * replaced Node is returned, otherwise null + * is returned. + * @exception DOMException + * WRONG_DOCUMENT_ERR: Raised if arg was created from a + * different document than the one that created this map. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. + *
INUSE_ATTRIBUTE_ERR: Raised if arg is an + * Attr that is already an attribute of another + * Element object. The DOM user must explicitly clone + * Attr nodes to re-use them in other elements. + */ + public Node setNamedItem(Node arg) + throws DOMException; + + /** + * Removes a node specified by name. When this map contains the attributes + * attached to an element, if the removed attribute is known to have a + * default value, an attribute immediately appears containing the + * default value as well as the corresponding namespace URI, local name, + * and prefix when applicable. + * @param nameThe nodeName of the node to remove. + * @return The node removed from this map if a node with such a name + * exists. + * @exception DOMException + * NOT_FOUND_ERR: Raised if there is no node named name in + * this map. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. + */ + public Node removeNamedItem(String name) + throws DOMException; + + /** + * Returns the indexth item in the map. If index + * is greater than or equal to the number of nodes in this map, this + * returns null. + * @param indexIndex into this map. + * @return The node at the indexth position in the map, or + * null if that is not a valid index. + */ + public Node item(int index); + + /** + * The number of nodes in this map. The range of valid child node indices + * is 0 to length-1 inclusive. + */ + public int getLength(); + + /** + * Retrieves a node specified by local name and namespace URI. HTML-only + * DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the node to retrieve. + * @param localNameThe local name of the node to retrieve. + * @return A Node (of any type) with the specified local + * name and namespace URI, or null if they do not + * identify any node in this map. + * @since DOM Level 2 + */ + public Node getNamedItemNS(String namespaceURI, + String localName); + + /** + * Adds a node using its namespaceURI and + * localName. If a node with that namespace URI and that + * local name is already present in this map, it is replaced by the new + * one. + *
HTML-only DOM implementations do not need to implement this method. + * @param argA node to store in this map. The node will later be + * accessible using the value of its namespaceURI and + * localName attributes. + * @return If the new Node replaces an existing node the + * replaced Node is returned, otherwise null + * is returned. + * @exception DOMException + * WRONG_DOCUMENT_ERR: Raised if arg was created from a + * different document than the one that created this map. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. + *
INUSE_ATTRIBUTE_ERR: Raised if arg is an + * Attr that is already an attribute of another + * Element object. The DOM user must explicitly clone + * Attr nodes to re-use them in other elements. + * @since DOM Level 2 + */ + public Node setNamedItemNS(Node arg) + throws DOMException; + + /** + * Removes a node specified by local name and namespace URI. A removed + * attribute may be known to have a default value when this map contains + * the attributes attached to an element, as returned by the attributes + * attribute of the Node interface. If so, an attribute + * immediately appears containing the default value as well as the + * corresponding namespace URI, local name, and prefix when applicable. + *
HTML-only DOM implementations do not need to implement this method. + * @param namespaceURIThe namespace URI of the node to remove. + * @param localNameThe local name of the node to remove. + * @return The node removed from this map if a node with such a local + * name and namespace URI exists. + * @exception DOMException + * NOT_FOUND_ERR: Raised if there is no node with the specified + * namespaceURI and localName in this map. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. + * @since DOM Level 2 + */ + public Node removeNamedItemNS(String namespaceURI, + String localName) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/Node.java b/libjava/org/w3c/dom/Node.java new file mode 100644 index 0000000..ef650a2 --- /dev/null +++ b/libjava/org/w3c/dom/Node.java @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The Node interface is the primary datatype for the entire + * Document Object Model. It represents a single node in the document tree. + * While all objects implementing the Node interface expose + * methods for dealing with children, not all objects implementing the + * Node interface may have children. For example, + * Text nodes may not have children, and adding children to + * such nodes results in a DOMException being raised. + *

The attributes nodeName, nodeValue and + * attributes are included as a mechanism to get at node + * information without casting down to the specific derived interface. In + * cases where there is no obvious mapping of these attributes for a + * specific nodeType (e.g., nodeValue for an + * Element or attributes for a Comment + * ), this returns null. Note that the specialized interfaces + * may contain additional and more convenient mechanisms to get and set the + * relevant information. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Node { + // NodeType + /** + * The node is an Element. + */ + public static final short ELEMENT_NODE = 1; + /** + * The node is an Attr. + */ + public static final short ATTRIBUTE_NODE = 2; + /** + * The node is a Text node. + */ + public static final short TEXT_NODE = 3; + /** + * The node is a CDATASection. + */ + public static final short CDATA_SECTION_NODE = 4; + /** + * The node is an EntityReference. + */ + public static final short ENTITY_REFERENCE_NODE = 5; + /** + * The node is an Entity. + */ + public static final short ENTITY_NODE = 6; + /** + * The node is a ProcessingInstruction. + */ + public static final short PROCESSING_INSTRUCTION_NODE = 7; + /** + * The node is a Comment. + */ + public static final short COMMENT_NODE = 8; + /** + * The node is a Document. + */ + public static final short DOCUMENT_NODE = 9; + /** + * The node is a DocumentType. + */ + public static final short DOCUMENT_TYPE_NODE = 10; + /** + * The node is a DocumentFragment. + */ + public static final short DOCUMENT_FRAGMENT_NODE = 11; + /** + * The node is a Notation. + */ + public static final short NOTATION_NODE = 12; + + /** + * The name of this node, depending on its type; see the table above. + */ + public String getNodeName(); + + /** + * The value of this node, depending on its type; see the table above. + * When it is defined to be null, setting it has no effect. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. + * @exception DOMException + * DOMSTRING_SIZE_ERR: Raised when it would return more characters than + * fit in a DOMString variable on the implementation + * platform. + */ + public String getNodeValue() + throws DOMException; + public void setNodeValue(String nodeValue) + throws DOMException; + + /** + * A code representing the type of the underlying object, as defined above. + */ + public short getNodeType(); + + /** + * The parent of this node. All nodes, except Attr, + * Document, DocumentFragment, + * Entity, and Notation may have a parent. + * However, if a node has just been created and not yet added to the + * tree, or if it has been removed from the tree, this is + * null. + */ + public Node getParentNode(); + + /** + * A NodeList that contains all children of this node. If + * there are no children, this is a NodeList containing no + * nodes. + */ + public NodeList getChildNodes(); + + /** + * The first child of this node. If there is no such node, this returns + * null. + */ + public Node getFirstChild(); + + /** + * The last child of this node. If there is no such node, this returns + * null. + */ + public Node getLastChild(); + + /** + * The node immediately preceding this node. If there is no such node, + * this returns null. + */ + public Node getPreviousSibling(); + + /** + * The node immediately following this node. If there is no such node, + * this returns null. + */ + public Node getNextSibling(); + + /** + * A NamedNodeMap containing the attributes of this node (if + * it is an Element) or null otherwise. + */ + public NamedNodeMap getAttributes(); + + /** + * The Document object associated with this node. This is + * also the Document object used to create new nodes. When + * this node is a Document or a DocumentType + * which is not used with any Document yet, this is + * null. + * @version DOM Level 2 + */ + public Document getOwnerDocument(); + + /** + * Inserts the node newChild before the existing child node + * refChild. If refChild is null, + * insert newChild at the end of the list of children. + *
If newChild is a DocumentFragment object, + * all of its children are inserted, in the same order, before + * refChild. If the newChild is already in the + * tree, it is first removed. + * @param newChildThe node to insert. + * @param refChildThe reference node, i.e., the node before which the new + * node must be inserted. + * @return The node being inserted. + * @exception DOMException + * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not + * allow children of the type of the newChild node, or if + * the node to insert is one of this node's ancestors. + *
WRONG_DOCUMENT_ERR: Raised if newChild was created + * from a different document than the one that created this node. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or + * if the parent of the node being inserted is readonly. + *
NOT_FOUND_ERR: Raised if refChild is not a child of + * this node. + */ + public Node insertBefore(Node newChild, + Node refChild) + throws DOMException; + + /** + * Replaces the child node oldChild with newChild + * in the list of children, and returns the oldChild node. + *
If newChild is a DocumentFragment object, + * oldChild is replaced by all of the + * DocumentFragment children, which are inserted in the + * same order. If the newChild is already in the tree, it + * is first removed. + * @param newChildThe new node to put in the child list. + * @param oldChildThe node being replaced in the list. + * @return The node replaced. + * @exception DOMException + * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not + * allow children of the type of the newChild node, or if + * the node to put in is one of this node's ancestors. + *
WRONG_DOCUMENT_ERR: Raised if newChild was created + * from a different document than the one that created this node. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of + * the new node is readonly. + *
NOT_FOUND_ERR: Raised if oldChild is not a child of + * this node. + */ + public Node replaceChild(Node newChild, + Node oldChild) + throws DOMException; + + /** + * Removes the child node indicated by oldChild from the list + * of children, and returns it. + * @param oldChildThe node being removed. + * @return The node removed. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
NOT_FOUND_ERR: Raised if oldChild is not a child of + * this node. + */ + public Node removeChild(Node oldChild) + throws DOMException; + + /** + * Adds the node newChild to the end of the list of children + * of this node. If the newChild is already in the tree, it + * is first removed. + * @param newChildThe node to add.If it is a DocumentFragment + * object, the entire contents of the document fragment are moved + * into the child list of this node + * @return The node added. + * @exception DOMException + * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not + * allow children of the type of the newChild node, or if + * the node to append is one of this node's ancestors. + *
WRONG_DOCUMENT_ERR: Raised if newChild was created + * from a different document than the one that created this node. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public Node appendChild(Node newChild) + throws DOMException; + + /** + * Returns whether this node has any children. + * @return true if this node has any children, + * false otherwise. + */ + public boolean hasChildNodes(); + + /** + * Returns a duplicate of this node, i.e., serves as a generic copy + * constructor for nodes. The duplicate node has no parent; ( + * parentNode is null.). + *
Cloning an Element copies all attributes and their + * values, including those generated by the XML processor to represent + * defaulted attributes, but this method does not copy any text it + * contains unless it is a deep clone, since the text is contained in a + * child Text node. Cloning an Attribute + * directly, as opposed to be cloned as part of an Element + * cloning operation, returns a specified attribute ( + * specified is true). Cloning any other type + * of node simply returns a copy of this node. + *
Note that cloning an immutable subtree results in a mutable copy, + * but the children of an EntityReference clone are readonly + * . In addition, clones of unspecified Attr nodes are + * specified. And, cloning Document, + * DocumentType, Entity, and + * Notation nodes is implementation dependent. + * @param deepIf true, recursively clone the subtree under + * the specified node; if false, clone only the node + * itself (and its attributes, if it is an Element). + * @return The duplicate node. + */ + public Node cloneNode(boolean deep); + + /** + * Puts all Text nodes in the full depth of the sub-tree + * underneath this Node, including attribute nodes, into a + * "normal" form where only structure (e.g., elements, comments, + * processing instructions, CDATA sections, and entity references) + * separates Text nodes, i.e., there are neither adjacent + * Text nodes nor empty Text nodes. This can + * be used to ensure that the DOM view of a document is the same as if + * it were saved and re-loaded, and is useful when operations (such as + * XPointer lookups) that depend on a particular document tree + * structure are to be used.In cases where the document contains + * CDATASections, the normalize operation alone may not be + * sufficient, since XPointers do not differentiate between + * Text nodes and CDATASection nodes. + * @version DOM Level 2 + */ + public void normalize(); + + /** + * Tests whether the DOM implementation implements a specific feature and + * that feature is supported by this node. + * @param featureThe name of the feature to test. This is the same name + * which can be passed to the method hasFeature on + * DOMImplementation. + * @param versionThis is the version number of the feature to test. In + * Level 2, version 1, this is the string "2.0". If the version is not + * specified, supporting any version of the feature will cause the + * method to return true. + * @return Returns true if the specified feature is + * supported on this node, false otherwise. + * @since DOM Level 2 + */ + public boolean isSupported(String feature, + String version); + + /** + * The namespace URI of this node, or null if it is + * unspecified. + *
This is not a computed value that is the result of a namespace + * lookup based on an examination of the namespace declarations in + * scope. It is merely the namespace URI given at creation time. + *
For nodes of any type other than ELEMENT_NODE and + * ATTRIBUTE_NODE and nodes created with a DOM Level 1 + * method, such as createElement from the + * Document interface, this is always null.Per + * the Namespaces in XML Specification an attribute does not inherit + * its namespace from the element it is attached to. If an attribute is + * not explicitly given a namespace, it simply has no namespace. + * @since DOM Level 2 + */ + public String getNamespaceURI(); + + /** + * The namespace prefix of this node, or null if it is + * unspecified. + *
Note that setting this attribute, when permitted, changes the + * nodeName attribute, which holds the qualified name, as + * well as the tagName and name attributes of + * the Element and Attr interfaces, when + * applicable. + *
Note also that changing the prefix of an attribute that is known to + * have a default value, does not make a new attribute with the default + * value and the original prefix appear, since the + * namespaceURI and localName do not change. + *
For nodes of any type other than ELEMENT_NODE and + * ATTRIBUTE_NODE and nodes created with a DOM Level 1 + * method, such as createElement from the + * Document interface, this is always null. + * @exception DOMException + * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an + * illegal character. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + *
NAMESPACE_ERR: Raised if the specified prefix is + * malformed, if the namespaceURI of this node is + * null, if the specified prefix is "xml" and the + * namespaceURI of this node is different from " + * http://www.w3.org/XML/1998/namespace", if this node is an attribute + * and the specified prefix is "xmlns" and the + * namespaceURI of this node is different from " + * http://www.w3.org/2000/xmlns/", or if this node is an attribute and + * the qualifiedName of this node is "xmlns" . + * @since DOM Level 2 + */ + public String getPrefix(); + public void setPrefix(String prefix) + throws DOMException; + + /** + * Returns the local part of the qualified name of this node. + *
For nodes of any type other than ELEMENT_NODE and + * ATTRIBUTE_NODE and nodes created with a DOM Level 1 + * method, such as createElement from the + * Document interface, this is always null. + * @since DOM Level 2 + */ + public String getLocalName(); + + /** + * Returns whether this node (if it is an element) has any attributes. + * @return true if this node has any attributes, + * false otherwise. + * @since DOM Level 2 + */ + public boolean hasAttributes(); + +} diff --git a/libjava/org/w3c/dom/NodeList.java b/libjava/org/w3c/dom/NodeList.java new file mode 100644 index 0000000..f4033f3 --- /dev/null +++ b/libjava/org/w3c/dom/NodeList.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The NodeList interface provides the abstraction of an ordered + * collection of nodes, without defining or constraining how this collection + * is implemented. NodeList objects in the DOM are live. + *

The items in the NodeList are accessible via an integral + * index, starting from 0. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface NodeList { + /** + * Returns the indexth item in the collection. If + * index is greater than or equal to the number of nodes in + * the list, this returns null. + * @param indexIndex into the collection. + * @return The node at the indexth position in the + * NodeList, or null if that is not a valid + * index. + */ + public Node item(int index); + + /** + * The number of nodes in the list. The range of valid child node indices + * is 0 to length-1 inclusive. + */ + public int getLength(); + +} diff --git a/libjava/org/w3c/dom/Notation.java b/libjava/org/w3c/dom/Notation.java new file mode 100644 index 0000000..284e015 --- /dev/null +++ b/libjava/org/w3c/dom/Notation.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * This interface represents a notation declared in the DTD. A notation either + * declares, by name, the format of an unparsed entity (see section 4.7 of + * the XML 1.0 specification ), or is used for formal declaration of + * processing instruction targets (see section 2.6 of the XML 1.0 + * specification ). The nodeName attribute inherited from + * Node is set to the declared name of the notation. + *

The DOM Level 1 does not support editing Notation nodes; + * they are therefore readonly. + *

A Notation node does not have any parent. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Notation extends Node { + /** + * The public identifier of this notation. If the public identifier was + * not specified, this is null. + */ + public String getPublicId(); + + /** + * The system identifier of this notation. If the system identifier was + * not specified, this is null. + */ + public String getSystemId(); + +} diff --git a/libjava/org/w3c/dom/ProcessingInstruction.java b/libjava/org/w3c/dom/ProcessingInstruction.java new file mode 100644 index 0000000..e3cfd1b --- /dev/null +++ b/libjava/org/w3c/dom/ProcessingInstruction.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The ProcessingInstruction interface represents a "processing + * instruction", used in XML as a way to keep processor-specific information + * in the text of the document. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface ProcessingInstruction extends Node { + /** + * The target of this processing instruction. XML defines this as being + * the first token following the markup that begins the processing + * instruction. + */ + public String getTarget(); + + /** + * The content of this processing instruction. This is from the first non + * white space character after the target to the character immediately + * preceding the ?>. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. + */ + public String getData(); + public void setData(String data) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/Text.java b/libjava/org/w3c/dom/Text.java new file mode 100644 index 0000000..c7c9971 --- /dev/null +++ b/libjava/org/w3c/dom/Text.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom; + +/** + * The Text interface inherits from CharacterData + * and represents the textual content (termed character data in XML) of an + * Element or Attr. If there is no markup inside + * an element's content, the text is contained in a single object + * implementing the Text interface that is the only child of + * the element. If there is markup, it is parsed into the information items + * (elements, comments, etc.) and Text nodes that form the list + * of children of the element. + *

When a document is first made available via the DOM, there is only one + * Text node for each block of text. Users may create adjacent + * Text nodes that represent the contents of a given element + * without any intervening markup, but should be aware that there is no way + * to represent the separations between these nodes in XML or HTML, so they + * will not (in general) persist between DOM editing sessions. The + * normalize() method on Node merges any such + * adjacent Text objects into a single node for each block of + * text. + *

See also the Document Object Model (DOM) Level 2 Core Specification. + */ +public interface Text extends CharacterData { + /** + * Breaks this node into two nodes at the specified offset, + * keeping both in the tree as siblings. After being split, this node + * will contain all the content up to the offset point. A + * new node of the same type, which contains all the content at and + * after the offset point, is returned. If the original + * node had a parent node, the new node is inserted as the next sibling + * of the original node. When the offset is equal to the + * length of this node, the new node has no data. + * @param offsetThe 16-bit unit offset at which to split, starting from + * 0. + * @return The new node, of the same type as this node. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater + * than the number of 16-bit units in data. + *
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. + */ + public Text splitText(int offset) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/ranges/DocumentRange.java b/libjava/org/w3c/dom/ranges/DocumentRange.java new file mode 100644 index 0000000..f9b764f --- /dev/null +++ b/libjava/org/w3c/dom/ranges/DocumentRange.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.ranges; + +/** + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface DocumentRange { + /** + * This interface can be obtained from the object implementing the + * Document interface using binding-specific casting + * methods. + * @return The initial state of the Range returned from this method is + * such that both of its boundary-points are positioned at the + * beginning of the corresponding Document, before any content. The + * Range returned can only be used to select content associated with + * this Document, or with DocumentFragments and Attrs for which this + * Document is the ownerDocument. + */ + public Range createRange(); + +} diff --git a/libjava/org/w3c/dom/ranges/Range.java b/libjava/org/w3c/dom/ranges/Range.java new file mode 100644 index 0000000..f4c3608 --- /dev/null +++ b/libjava/org/w3c/dom/ranges/Range.java @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.ranges; + +import org.w3c.dom.Node; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.DOMException; + +/** + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface Range { + /** + * Node within which the Range begins + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public Node getStartContainer() + throws DOMException; + + /** + * Offset within the starting node of the Range. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public int getStartOffset() + throws DOMException; + + /** + * Node within which the Range ends + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public Node getEndContainer() + throws DOMException; + + /** + * Offset within the ending node of the Range. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public int getEndOffset() + throws DOMException; + + /** + * TRUE if the Range is collapsed + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public boolean getCollapsed() + throws DOMException; + + /** + * The deepest common ancestor container of the Range's two + * boundary-points. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public Node getCommonAncestorContainer() + throws DOMException; + + /** + * Sets the attributes describing the start of the Range. + * @param refNodeThe refNode value. This parameter must be + * different from null. + * @param offsetThe startOffset value. + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor + * of refNode is an Entity, Notation, or DocumentType + * node. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if offset is negative or greater + * than the number of child units in refNode. Child units + * are 16-bit units if refNode is a type of CharacterData + * node (e.g., a Text or Comment node) or a ProcessingInstruction + * node. Child units are Nodes in all other cases. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public void setStart(Node refNode, + int offset) + throws RangeException, DOMException; + + /** + * Sets the attributes describing the end of a Range. + * @param refNodeThe refNode value. This parameter must be + * different from null. + * @param offsetThe endOffset value. + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor + * of refNode is an Entity, Notation, or DocumentType + * node. + * @exception DOMException + * INDEX_SIZE_ERR: Raised if offset is negative or greater + * than the number of child units in refNode. Child units + * are 16-bit units if refNode is a type of CharacterData + * node (e.g., a Text or Comment node) or a ProcessingInstruction + * node. Child units are Nodes in all other cases. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public void setEnd(Node refNode, + int offset) + throws RangeException, DOMException; + + /** + * Sets the start position to be before a node + * @param refNodeRange starts before refNode + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if the root container of + * refNode is not an Attr, Document, or DocumentFragment + * node or if refNode is a Document, DocumentFragment, + * Attr, Entity, or Notation node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void setStartBefore(Node refNode) + throws RangeException, DOMException; + + /** + * Sets the start position to be after a node + * @param refNodeRange starts after refNode + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if the root container of + * refNode is not an Attr, Document, or DocumentFragment + * node or if refNode is a Document, DocumentFragment, + * Attr, Entity, or Notation node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void setStartAfter(Node refNode) + throws RangeException, DOMException; + + /** + * Sets the end position to be before a node. + * @param refNodeRange ends before refNode + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if the root container of + * refNode is not an Attr, Document, or DocumentFragment + * node or if refNode is a Document, DocumentFragment, + * Attr, Entity, or Notation node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void setEndBefore(Node refNode) + throws RangeException, DOMException; + + /** + * Sets the end of a Range to be after a node + * @param refNodeRange ends after refNode. + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if the root container of + * refNode is not an Attr, Document or DocumentFragment + * node or if refNode is a Document, DocumentFragment, + * Attr, Entity, or Notation node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void setEndAfter(Node refNode) + throws RangeException, DOMException; + + /** + * Collapse a Range onto one of its boundary-points + * @param toStartIf TRUE, collapses the Range onto its start; if FALSE, + * collapses it onto its end. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void collapse(boolean toStart) + throws DOMException; + + /** + * Select a node and its contents + * @param refNodeThe node to select. + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode + * is an Entity, Notation or DocumentType node or if + * refNode is a Document, DocumentFragment, Attr, Entity, + * or Notation node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void selectNode(Node refNode) + throws RangeException, DOMException; + + /** + * Select the contents within a node + * @param refNodeNode to select from + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor + * of refNode is an Entity, Notation or DocumentType node. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void selectNodeContents(Node refNode) + throws RangeException, DOMException; + + // CompareHow + /** + * Compare start boundary-point of sourceRange to start + * boundary-point of Range on which compareBoundaryPoints + * is invoked. + */ + public static final short START_TO_START = 0; + /** + * Compare start boundary-point of sourceRange to end + * boundary-point of Range on which compareBoundaryPoints + * is invoked. + */ + public static final short START_TO_END = 1; + /** + * Compare end boundary-point of sourceRange to end + * boundary-point of Range on which compareBoundaryPoints + * is invoked. + */ + public static final short END_TO_END = 2; + /** + * Compare end boundary-point of sourceRange to start + * boundary-point of Range on which compareBoundaryPoints + * is invoked. + */ + public static final short END_TO_START = 3; + + /** + * Compare the boundary-points of two Ranges in a document. + * @param howA code representing the type of comparison, as defined above. + * @param sourceRangeThe Range on which this current + * Range is compared to. + * @return -1, 0 or 1 depending on whether the corresponding + * boundary-point of the Range is respectively before, equal to, or + * after the corresponding boundary-point of sourceRange. + * @exception DOMException + * WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same + * Document or DocumentFragment. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public short compareBoundaryPoints(short how, + Range sourceRange) + throws DOMException; + + /** + * Removes the contents of a Range from the containing document or + * document fragment without returning a reference to the removed + * content. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of + * the Range is read-only or any of the nodes that contain any of the + * content of the Range are read-only. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public void deleteContents() + throws DOMException; + + /** + * Moves the contents of a Range from the containing document or document + * fragment to a new DocumentFragment. + * @return A DocumentFragment containing the extracted contents. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of + * the Range is read-only or any of the nodes which contain any of the + * content of the Range are read-only. + *
HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be + * extracted into the new DocumentFragment. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public DocumentFragment extractContents() + throws DOMException; + + /** + * Duplicates the contents of a Range + * @return A DocumentFragment that contains content equivalent to this + * Range. + * @exception DOMException + * HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be + * extracted into the new DocumentFragment. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + */ + public DocumentFragment cloneContents() + throws DOMException; + + /** + * Inserts a node into the Document or DocumentFragment at the start of + * the Range. If the container is a Text node, this will be split at the + * start of the Range (as if the Text node's splitText method was + * performed at the insertion point) and the insertion will occur + * between the two resulting Text nodes. Adjacent Text nodes will not be + * automatically merged. If the node to be inserted is a + * DocumentFragment node, the children will be inserted rather than the + * DocumentFragment node itself. + * @param newNodeThe node to insert at the start of the Range + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the + * start of the Range is read-only. + *
WRONG_DOCUMENT_ERR: Raised if newNode and the + * container of the start of the Range were not created from the same + * document. + *
HIERARCHY_REQUEST_ERR: Raised if the container of the start of + * the Range is of a type that does not allow children of the type of + * newNode or if newNode is an ancestor of + * the container. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + * @exception RangeException + * INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, + * Entity, Notation, or Document node. + */ + public void insertNode(Node newNode) + throws DOMException, RangeException; + + /** + * Reparents the contents of the Range to the given node and inserts the + * node at the position of the start of the Range. + * @param newParentThe node to surround the contents with. + * @exception DOMException + * NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of + * either boundary-point of the Range is read-only. + *
WRONG_DOCUMENT_ERR: Raised if newParent and the + * container of the start of the Range were not created from the same + * document. + *
HIERARCHY_REQUEST_ERR: Raised if the container of the start of + * the Range is of a type that does not allow children of the type of + * newParent or if newParent is an ancestor + * of the container or if node would end up with a child + * node of a type not allowed by the type of node. + *
INVALID_STATE_ERR: Raised if detach() has already + * been invoked on this object. + * @exception RangeException + * BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a + * non-text node. + *
INVALID_NODE_TYPE_ERR: Raised if node is an Attr, + * Entity, DocumentType, Notation, Document, or DocumentFragment node. + */ + public void surroundContents(Node newParent) + throws DOMException, RangeException; + + /** + * Produces a new Range whose boundary-points are equal to the + * boundary-points of the Range. + * @return The duplicated Range. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public Range cloneRange() + throws DOMException; + + /** + * Returns the contents of a Range as a string. This string contains only + * the data characters, not any markup. + * @return The contents of the Range. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public String toString() + throws DOMException; + + /** + * Called to indicate that the Range is no longer in use and that the + * implementation may relinquish any resources associated with this + * Range. Subsequent calls to any methods or attribute getters on this + * Range will result in a DOMException being thrown with an + * error code of INVALID_STATE_ERR. + * @exception DOMException + * INVALID_STATE_ERR: Raised if detach() has already been + * invoked on this object. + */ + public void detach() + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/ranges/RangeException.java b/libjava/org/w3c/dom/ranges/RangeException.java new file mode 100644 index 0000000..abf9a9f --- /dev/null +++ b/libjava/org/w3c/dom/ranges/RangeException.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.ranges; + +/** + * Range operations may throw a RangeException as specified in + * their method descriptions. + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public class RangeException extends RuntimeException { + public RangeException(short code, String message) { + super(message); + this.code = code; + } + public short code; + // RangeExceptionCode + /** + * If the boundary-points of a Range do not meet specific requirements. + */ + public static final short BAD_BOUNDARYPOINTS_ERR = 1; + /** + * If the container of an boundary-point of a Range is being set to either + * a node of an invalid type or a node with an ancestor of an invalid + * type. + */ + public static final short INVALID_NODE_TYPE_ERR = 2; + +} diff --git a/libjava/org/w3c/dom/traversal/DocumentTraversal.java b/libjava/org/w3c/dom/traversal/DocumentTraversal.java new file mode 100644 index 0000000..88e7a92 --- /dev/null +++ b/libjava/org/w3c/dom/traversal/DocumentTraversal.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * DocumentTraversal contains methods that create iterators and + * tree-walkers to traverse a node and its children in document order (depth + * first, pre-order traversal, which is equivalent to the order in which the + * start tags occur in the text representation of the document). In DOMs + * which support the Traversal feature, DocumentTraversal will + * be implemented by the same objects that implement the Document interface. + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface DocumentTraversal { + /** + * Create a new NodeIterator over the subtree rooted at the + * specified node. + * @param rootThe node which will be iterated together with its children. + * The iterator is initially positioned just before this node. The + * whatToShow flags and the filter, if any, are not + * considered when setting this position. The root must not be + * null. + * @param whatToShowThis flag specifies which node types may appear in + * the logical view of the tree presented by the iterator. See the + * description of NodeFilter for the set of possible + * SHOW_ values.These flags can be combined using + * OR. + * @param filterThe NodeFilter to be used with this + * TreeWalker, or null to indicate no filter. + * @param entityReferenceExpansionThe value of this flag determines + * whether entity reference nodes are expanded. + * @return The newly created NodeIterator. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if the specified root is + * null. + */ + public NodeIterator createNodeIterator(Node root, + int whatToShow, + NodeFilter filter, + boolean entityReferenceExpansion) + throws DOMException; + + /** + * Create a new TreeWalker over the subtree rooted at the + * specified node. + * @param rootThe node which will serve as the root for the + * TreeWalker. The whatToShow flags and the + * NodeFilter are not considered when setting this value; + * any node type will be accepted as the root. The + * currentNode of the TreeWalker is + * initialized to this node, whether or not it is visible. The + * root functions as a stopping point for traversal + * methods that look upward in the document structure, such as + * parentNode and nextNode. The root must + * not be null. + * @param whatToShowThis flag specifies which node types may appear in + * the logical view of the tree presented by the tree-walker. See the + * description of NodeFilter for the set of possible + * SHOW_ values.These flags can be combined using OR. + * @param filterThe NodeFilter to be used with this + * TreeWalker, or null to indicate no filter. + * @param entityReferenceExpansionIf this flag is false, the contents of + * EntityReference nodes are not presented in the logical + * view. + * @return The newly created TreeWalker. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if the specified root is + * null. + */ + public TreeWalker createTreeWalker(Node root, + int whatToShow, + NodeFilter filter, + boolean entityReferenceExpansion) + throws DOMException; + +} diff --git a/libjava/org/w3c/dom/traversal/NodeFilter.java b/libjava/org/w3c/dom/traversal/NodeFilter.java new file mode 100644 index 0000000..8901059 --- /dev/null +++ b/libjava/org/w3c/dom/traversal/NodeFilter.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; + +/** + * Filters are objects that know how to "filter out" nodes. If a + * NodeIterator or TreeWalker is given a + * NodeFilter, it applies the filter before it returns the next + * node. If the filter says to accept the node, the traversal logic returns + * it; otherwise, traversal looks for the next node and pretends that the + * node that was rejected was not there. + *

The DOM does not provide any filters. NodeFilter is just an + * interface that users can implement to provide their own filters. + *

NodeFilters do not need to know how to traverse from node + * to node, nor do they need to know anything about the data structure that + * is being traversed. This makes it very easy to write filters, since the + * only thing they have to know how to do is evaluate a single node. One + * filter may be used with a number of different kinds of traversals, + * encouraging code reuse. + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface NodeFilter { + // Constants returned by acceptNode + /** + * Accept the node. Navigation methods defined for + * NodeIterator or TreeWalker will return this + * node. + */ + public static final short FILTER_ACCEPT = 1; + /** + * Reject the node. Navigation methods defined for + * NodeIterator or TreeWalker will not return + * this node. For TreeWalker, the children of this node + * will also be rejected. NodeIterators treat this as a + * synonym for FILTER_SKIP. + */ + public static final short FILTER_REJECT = 2; + /** + * Skip this single node. Navigation methods defined for + * NodeIterator or TreeWalker will not return + * this node. For both NodeIterator and + * TreeWalker, the children of this node will still be + * considered. + */ + public static final short FILTER_SKIP = 3; + + // Constants for whatToShow + /** + * Show all Nodes. + */ + public static final int SHOW_ALL = 0xFFFFFFFF; + /** + * Show Element nodes. + */ + public static final int SHOW_ELEMENT = 0x00000001; + /** + * Show Attr nodes. This is meaningful only when creating an + * iterator or tree-walker with an attribute node as its + * root; in this case, it means that the attribute node + * will appear in the first position of the iteration or traversal. + * Since attributes are never children of other nodes, they do not + * appear when traversing over the document tree. + */ + public static final int SHOW_ATTRIBUTE = 0x00000002; + /** + * Show Text nodes. + */ + public static final int SHOW_TEXT = 0x00000004; + /** + * Show CDATASection nodes. + */ + public static final int SHOW_CDATA_SECTION = 0x00000008; + /** + * Show EntityReference nodes. + */ + public static final int SHOW_ENTITY_REFERENCE = 0x00000010; + /** + * Show Entity nodes. This is meaningful only when creating + * an iterator or tree-walker with an Entity node as its + * root; in this case, it means that the Entity + * node will appear in the first position of the traversal. Since + * entities are not part of the document tree, they do not appear when + * traversing over the document tree. + */ + public static final int SHOW_ENTITY = 0x00000020; + /** + * Show ProcessingInstruction nodes. + */ + public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040; + /** + * Show Comment nodes. + */ + public static final int SHOW_COMMENT = 0x00000080; + /** + * Show Document nodes. + */ + public static final int SHOW_DOCUMENT = 0x00000100; + /** + * Show DocumentType nodes. + */ + public static final int SHOW_DOCUMENT_TYPE = 0x00000200; + /** + * Show DocumentFragment nodes. + */ + public static final int SHOW_DOCUMENT_FRAGMENT = 0x00000400; + /** + * Show Notation nodes. This is meaningful only when creating + * an iterator or tree-walker with a Notation node as its + * root; in this case, it means that the + * Notation node will appear in the first position of the + * traversal. Since notations are not part of the document tree, they do + * not appear when traversing over the document tree. + */ + public static final int SHOW_NOTATION = 0x00000800; + + /** + * Test whether a specified node is visible in the logical view of a + * TreeWalker or NodeIterator. This function + * will be called by the implementation of TreeWalker and + * NodeIterator; it is not normally called directly from + * user code. (Though you could do so if you wanted to use the same + * filter to guide your own application logic.) + * @param nThe node to check to see if it passes the filter or not. + * @return a constant to determine whether the node is accepted, + * rejected, or skipped, as defined above. + */ + public short acceptNode(Node n); + +} diff --git a/libjava/org/w3c/dom/traversal/NodeIterator.java b/libjava/org/w3c/dom/traversal/NodeIterator.java new file mode 100644 index 0000000..3563e80 --- /dev/null +++ b/libjava/org/w3c/dom/traversal/NodeIterator.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * Iterators are used to step through a set of nodes, e.g. the + * set of nodes in a NodeList, the document subtree governed by + * a particular Node, the results of a query, or any other set + * of nodes. The set of nodes to be iterated is determined by the + * implementation of the NodeIterator. DOM Level 2 specifies a + * single NodeIterator implementation for document-order + * traversal of a document subtree. Instances of these iterators are created + * by calling DocumentTraversal + * .createNodeIterator(). + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface NodeIterator { + /** + * The root node of the NodeIterator, as specified when it + * was created. + */ + public Node getRoot(); + + /** + * This attribute determines which node types are presented via the + * iterator. The available set of constants is defined in the + * NodeFilter interface. Nodes not accepted by + * whatToShow will be skipped, but their children may still + * be considered. Note that this skip takes precedence over the filter, + * if any. + */ + public int getWhatToShow(); + + /** + * The NodeFilter used to screen nodes. + */ + public NodeFilter getFilter(); + + /** + * The value of this flag determines whether the children of entity + * reference nodes are visible to the iterator. If false, they and + * their descendants will be rejected. Note that this rejection takes + * precedence over whatToShow and the filter. Also note + * that this is currently the only situation where + * NodeIterators may reject a complete subtree rather than + * skipping individual nodes. + *
+ *
To produce a view of the document that has entity references + * expanded and does not expose the entity reference node itself, use + * the whatToShow flags to hide the entity reference node + * and set expandEntityReferences to true when creating the + * iterator. To produce a view of the document that has entity reference + * nodes but no entity expansion, use the whatToShow flags + * to show the entity reference node and set + * expandEntityReferences to false. + */ + public boolean getExpandEntityReferences(); + + /** + * Returns the next node in the set and advances the position of the + * iterator in the set. After a NodeIterator is created, + * the first call to nextNode() returns the first node in + * the set. + * @return The next Node in the set being iterated over, or + * null if there are no more members in that set. + * @exception DOMException + * INVALID_STATE_ERR: Raised if this method is called after the + * detach method was invoked. + */ + public Node nextNode() + throws DOMException; + + /** + * Returns the previous node in the set and moves the position of the + * NodeIterator backwards in the set. + * @return The previous Node in the set being iterated over, + * or null if there are no more members in that set. + * @exception DOMException + * INVALID_STATE_ERR: Raised if this method is called after the + * detach method was invoked. + */ + public Node previousNode() + throws DOMException; + + /** + * Detaches the NodeIterator from the set which it iterated + * over, releasing any computational resources and placing the iterator + * in the INVALID state. After detach has been invoked, + * calls to nextNode or previousNode will + * raise the exception INVALID_STATE_ERR. + */ + public void detach(); + +} diff --git a/libjava/org/w3c/dom/traversal/TreeWalker.java b/libjava/org/w3c/dom/traversal/TreeWalker.java new file mode 100644 index 0000000..ed02929 --- /dev/null +++ b/libjava/org/w3c/dom/traversal/TreeWalker.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * TreeWalker objects are used to navigate a document tree or + * subtree using the view of the document defined by their + * whatToShow flags and filter (if any). Any function which + * performs navigation using a TreeWalker will automatically + * support any view defined by a TreeWalker. + *

Omitting nodes from the logical view of a subtree can result in a + * structure that is substantially different from the same subtree in the + * complete, unfiltered document. Nodes that are siblings in the + * TreeWalker view may be children of different, widely + * separated nodes in the original view. For instance, consider a + * NodeFilter that skips all nodes except for Text nodes and + * the root node of a document. In the logical view that results, all text + * nodes will be siblings and appear as direct children of the root node, no + * matter how deeply nested the structure of the original document. + *

See also the Document Object Model (DOM) Level 2 Traversal and Range Specification. + * @since DOM Level 2 + */ +public interface TreeWalker { + /** + * The root node of the TreeWalker, as specified + * when it was created. + */ + public Node getRoot(); + + /** + * This attribute determines which node types are presented via the + * TreeWalker. The available set of constants is defined in + * the NodeFilter interface. Nodes not accepted by + * whatToShow will be skipped, but their children may still + * be considered. Note that this skip takes precedence over the filter, + * if any. + */ + public int getWhatToShow(); + + /** + * The filter used to screen nodes. + */ + public NodeFilter getFilter(); + + /** + * The value of this flag determines whether the children of entity + * reference nodes are visible to the TreeWalker. If false, + * they and their descendants will be rejected. Note that this + * rejection takes precedence over whatToShow and the + * filter, if any. + *
To produce a view of the document that has entity references + * expanded and does not expose the entity reference node itself, use + * the whatToShow flags to hide the entity reference node + * and set expandEntityReferences to true when creating the + * TreeWalker. To produce a view of the document that has + * entity reference nodes but no entity expansion, use the + * whatToShow flags to show the entity reference node and + * set expandEntityReferences to false. + */ + public boolean getExpandEntityReferences(); + + /** + * The node at which the TreeWalker is currently positioned. + *
Alterations to the DOM tree may cause the current node to no longer + * be accepted by the TreeWalker's associated filter. + * currentNode may also be explicitly set to any node, + * whether or not it is within the subtree specified by the + * root node or would be accepted by the filter and + * whatToShow flags. Further traversal occurs relative to + * currentNode even if it is not part of the current view, + * by applying the filters in the requested direction; if no traversal + * is possible, currentNode is not changed. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if an attempt is made to set + * currentNode to null. + */ + public Node getCurrentNode(); + public void setCurrentNode(Node currentNode) + throws DOMException; + + /** + * Moves to and returns the closest visible ancestor node of the current + * node. If the search for parentNode attempts to step + * upward from the TreeWalker's root node, or + * if it fails to find a visible ancestor node, this method retains the + * current position and returns null. + * @return The new parent node, or null if the current node + * has no parent in the TreeWalker's logical view. + */ + public Node parentNode(); + + /** + * Moves the TreeWalker to the first visible child of the + * current node, and returns the new node. If the current node has no + * visible children, returns null, and retains the current + * node. + * @return The new node, or null if the current node has no + * visible children in the TreeWalker's logical view. + */ + public Node firstChild(); + + /** + * Moves the TreeWalker to the last visible child of the + * current node, and returns the new node. If the current node has no + * visible children, returns null, and retains the current + * node. + * @return The new node, or null if the current node has no + * children in the TreeWalker's logical view. + */ + public Node lastChild(); + + /** + * Moves the TreeWalker to the previous sibling of the + * current node, and returns the new node. If the current node has no + * visible previous sibling, returns null, and retains the + * current node. + * @return The new node, or null if the current node has no + * previous sibling. in the TreeWalker's logical view. + */ + public Node previousSibling(); + + /** + * Moves the TreeWalker to the next sibling of the current + * node, and returns the new node. If the current node has no visible + * next sibling, returns null, and retains the current node. + * @return The new node, or null if the current node has no + * next sibling. in the TreeWalker's logical view. + */ + public Node nextSibling(); + + /** + * Moves the TreeWalker to the previous visible node in + * document order relative to the current node, and returns the new + * node. If the current node has no previous node, or if the search for + * previousNode attempts to step upward from the + * TreeWalker's root node, returns + * null, and retains the current node. + * @return The new node, or null if the current node has no + * previous node in the TreeWalker's logical view. + */ + public Node previousNode(); + + /** + * Moves the TreeWalker to the next visible node in document + * order relative to the current node, and returns the new node. If the + * current node has no next node, or if the search for nextNode attempts + * to step upward from the TreeWalker's root + * node, returns null, and retains the current node. + * @return The new node, or null if the current node has no + * next node in the TreeWalker's logical view. + */ + public Node nextNode(); + +} -- cgit v1.1