|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gnu.xml.dom.DomNode
"Node", "EventTarget", and "DocumentEvent" implementation. This provides most of the core DOM functionality; only more specialized features are provided by subclasses. Those subclasses may have some particular constraints they must implement, by overriding methods defined here. Such constraints are noted here in the method documentation.
Note that you can create events with type names prefixed with "USER-", and pass them through this DOM. This lets you use the DOM event scheme for application specific purposes, although you must use a predefined event structure (such as MutationEvent) to pass data along with those events. Test for existence of this feature with the "USER-Events" DOM feature name.
Other kinds of events you can send include the "html" events, like "load", "unload", "abort", "error", and "blur"; and the mutation events. If this DOM has been compiled with mutation event support enabled, it will send mutation events when you change parts of the tree; otherwise you may create and send such events yourself, but they won't be generated by the DOM itself.
Note that there is a namespace-aware name comparison method, nameAndTypeEquals, which compares the names (and types) of two nodes in conformance with the "Namespaces in XML" specification. While mostly intended for use with elements and attributes, this should also be helpful for ProcessingInstruction nodes and some others which do not have namespace URIs.
Fields inherited from interface org.w3c.dom.Node |
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE |
Constructor Summary | |
protected |
DomNode(Document owner,
short type)
Constructs a node and associates it with its owner. |
Method Summary | |
void |
addEventListener(java.lang.String type,
org.w3c.dom.events.EventListener listener,
boolean useCapture)
DOM L2 (Events) Registers an event listener's interest in a class of events. |
Node |
appendChild(Node newChild)
DOM L1 Appends the specified node to this node's list of children. |
java.lang.Object |
clone()
Clones this node; roughly equivalent to cloneNode(false). |
Node |
cloneNode(boolean deep)
DOM L1 Returns a clone of this node which optionally includes cloned versions of child nodes. |
org.w3c.dom.events.Event |
createEvent(java.lang.String type)
DOM L2 (Events) Returns an instance of the specified type of event object. |
boolean |
dispatchEvent(org.w3c.dom.events.Event event)
DOM L2 (Events) Delivers an event to all relevant listeners, returning true if the caller should perform their default action. |
NamedNodeMap |
getAttributes()
DOM L1 Returns null; Element subclasses must override this method. |
NodeList |
getChildNodes()
DOM L1 Returns a list, possibly empty, of the children of this node. |
NodeList |
getElementsByTagName(java.lang.String tag)
DOM L1 Creates a NodeList giving array-style access to elements with the specified name. |
NodeList |
getElementsByTagNameNS(java.lang.String namespace,
java.lang.String local)
DOM L2 Creates a NodeList giving array-style access to elements with the specified namespace and local name. |
Node |
getFirstChild()
DOM L1 Returns the first child of this node, or null if there are none. |
Node |
getLastChild()
DOM L1 Returns the last child of this node, or null if there are none. |
int |
getLength()
DOM L1 (NodeList) Returns the number of elements in this NodeList. |
java.lang.String |
getLocalName()
DOM L2 Returns the node name; this must be overridden for element and attribute nodes. |
java.lang.String |
getNamespaceURI()
DOM L2 Returns null; this must be overridden for element and attribute nodes. |
Node |
getNextSibling()
DOM L1 Returns the previous sibling, if one is known. |
short |
getNodeType()
DOM L1 Returns a code identifying the type of this object, such as ELEMENT_NODE, TEXT_NODE, and so on. |
java.lang.String |
getNodeValue()
DOM L1 Returns null; this must be overridden for nodes types with a defined value, along with the setNodeValue method. |
Document |
getOwnerDocument()
DOM L1 (modified in L2) Returns the owner document. |
Node |
getParentNode()
DOM L1 Returns the parent node, if one is known. |
java.lang.String |
getPrefix()
DOM L2 Returns null; this must be overridden for element and attribute nodes. |
Node |
getPreviousSibling()
DOM L1 Returns the previous sibling, if one is known. |
boolean |
hasAttributes()
DOM L2> Returns true iff this is an element node with attributes. |
boolean |
hasChildNodes()
DOM L1 Returns true if this node has children. |
Node |
insertBefore(Node newChild,
Node refChild)
DOM L1 Inserts the specified node in this node's list of children. |
boolean |
isReadonly()
Exposes the internal "readonly" flag. |
boolean |
isSupported(java.lang.String feature,
java.lang.String version)
DOM L2 Consults the DOM implementation to determine if the requested feature is supported. |
Node |
item(int index)
DOM L1 (NodeList) Returns the item with the specified index in this NodeList, else null. |
void |
makeReadonly()
Sets the internal "readonly" flag so this subtree can't be changed. |
boolean |
nameAndTypeEquals(Node other)
Returns true iff node types match, and either (a) both nodes have no namespace and their getNodeName() values are the same, or (b) both nodes have the same getNamespaceURI() and same getLocalName() values. |
void |
normalize()
DOM L1 (relocated in DOM L2) In this node and all contained nodes (including attributes if relevant) merge adjacent text nodes. |
Node |
removeChild(Node refChild)
DOM L1 Removes the specified child from this node's list of children, or else reports an exception. |
void |
removeEventListener(java.lang.String type,
org.w3c.dom.events.EventListener listener,
boolean useCapture)
DOM L2 (Events) Unregisters an event listener. |
Node |
replaceChild(Node newChild,
Node refChild)
DOM L1 Replaces the specified node in this node's list of children. |
void |
setNodeValue(java.lang.String value)
DOM L1 Does nothing; this must be overridden (along with the getNodeValue method) for nodes with a non-null defined value. |
void |
setPrefix(java.lang.String prefix)
DOM L2 Does nothing; this must be overridden (along with the getPrefix method) for element and attribute nodes. |
void |
trimToSize()
Minimize extra space consumed by this node to hold children and event listeners. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.w3c.dom.Node |
getNodeName |
Constructor Detail |
protected DomNode(Document owner, short type)
Method Detail |
public final short getNodeType()
getNodeType
in interface Node
public NamedNodeMap getAttributes()
getAttributes
in interface Node
public boolean hasAttributes()
hasAttributes
in interface Node
org.w3c.dom.Node
true
if this node has any attributes,
false
otherwise.public NodeList getChildNodes()
getChildNodes
in interface Node
public final Node getFirstChild()
getFirstChild
in interface Node
public final Node getLastChild()
getLastChild
in interface Node
public final boolean hasChildNodes()
hasChildNodes
in interface Node
org.w3c.dom.Node
true
if this node has any children,
false
otherwise.public final boolean isReadonly()
public void makeReadonly()
public Node appendChild(Node newChild)
Causes a DOMNodeInserted mutation event to be reported. Will first cause a DOMNodeRemoved event to be reported if the parameter already has a parent. If the new child is a document fragment node, both events will be reported for each child of the fragment; the order in which children are removed and inserted is implementation-specific.
If this DOM has been compiled without mutation event support, these events will not be reported.
appendChild
in interface Node
org.w3c.dom.Node
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 nodeDOMException
- 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.
newChild
was created
from a different document than the one that created this node.
public Node insertBefore(Node newChild, Node refChild)
Causes a DOMNodeInserted mutation event to be reported. Will first cause a DOMNodeRemoved event to be reported if the newChild parameter already has a parent. If the new child is a document fragment node, both events will be reported for each child of the fragment; the order in which children are removed and inserted is implementation-specific.
If this DOM has been compiled without mutation event support, these events will not be reported.
insertBefore
in interface Node
org.w3c.dom.Node
newChildThe
- node to insert.refChildThe
- reference node, i.e., the node before which the new
node must be inserted.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.
newChild
was created
from a different document than the one that created this node.
refChild
is not a child of
this node.public Node replaceChild(Node newChild, Node refChild)
Causes DOMNodeRemoved and DOMNodeInserted mutation event to be reported. Will cause another DOMNodeRemoved event to be reported if the newChild parameter already has a parent. These events may be delivered in any order, except that the event reporting removal from such an existing parent will always be delivered before the event reporting its re-insertion as a child of some other node. The order in which children are removed and inserted is implementation specific.
If your application needs to depend on the in which those removal and insertion events are delivered, don't use this API. Instead, invoke the removeChild and insertBefore methods directly, to guarantee a specific delivery order. Similarly, don't use document fragments, Otherwise your application code may not work on a DOM which implements this method differently.
If this DOM has been compiled without mutation event support, these events will not be reported.
replaceChild
in interface Node
org.w3c.dom.Node
newChildThe
- new node to put in the child list.oldChildThe
- node being replaced in the list.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.
newChild
was created
from a different document than the one that created this node.
oldChild
is not a child of
this node.public Node removeChild(Node refChild)
Causes a DOMNodeRemoved mutation event to be reported.
If this DOM has been compiled without mutation event support, these events will not be reported.
removeChild
in interface Node
org.w3c.dom.Node
oldChildThe
- node being removed.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
oldChild
is not a child of
this node.public final Node item(int index)
item
in interface NodeList
org.w3c.dom.NodeList
indexIndex
- into the collection.index
th position in the
NodeList
, or null
if that is not a valid
index.public int getLength()
getLength
in interface NodeList
public void trimToSize()
public final Node getNextSibling()
getNextSibling
in interface Node
public final Node getPreviousSibling()
getPreviousSibling
in interface Node
public final Node getParentNode()
getParentNode
in interface Node
public boolean isSupported(java.lang.String feature, java.lang.String version)
isSupported
in interface Node
org.w3c.dom.Node
featureThe
- name of the feature to test. This is the same name
which can be passed to the method hasFeature
on
DOMImplementation
.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
.true
if the specified feature is
supported on this node, false
otherwise.public final Document getOwnerDocument()
getOwnerDocument
in interface Node
public void setNodeValue(java.lang.String value)
setNodeValue
in interface Node
public java.lang.String getNodeValue()
getNodeValue
in interface Node
org.w3c.dom.Node
DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.DOMException
- DOMSTRING_SIZE_ERR: Raised when it would return more characters than
fit in a DOMString
variable on the implementation
platform.public void setPrefix(java.lang.String prefix)
setPrefix
in interface Node
public java.lang.String getPrefix()
getPrefix
in interface Node
org.w3c.dom.Node
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
illegal character.
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" .public java.lang.String getNamespaceURI()
getNamespaceURI
in interface Node
public java.lang.String getLocalName()
getLocalName
in interface Node
public Node cloneNode(boolean deep)
cloneNode
in interface Node
org.w3c.dom.Node
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
).public java.lang.Object clone()
clone
in class java.lang.Object
public NodeList getElementsByTagName(java.lang.String tag)
public NodeList getElementsByTagNameNS(java.lang.String namespace, java.lang.String local)
public org.w3c.dom.events.Event createEvent(java.lang.String type)
If the name of the event type begins with "USER-", then an object implementing the "Event" class will be returned; this provides a limited facility for application-defined events to use the DOM event infrastructure. Alternatively, use one of the standard DOM event classes and initialize it using use such a "USER-" event type name; or defin, instantiate, and initialize an application-specific subclass of DomEvent and pass that to dispatchEvent().
createEvent
in interface org.w3c.dom.events.DocumentEvent
org.w3c.dom.events.DocumentEvent
eventTypeThe
- eventType
parameter specifies the
type of Event
interface to be created. If the
Event
interface specified is supported by the
implementation this method will return a new Event
of
the interface type requested. If the Event
is to be
dispatched via the dispatchEvent
method the
appropriate event init method must be called after creation in
order to initialize the Event
's values. As an example,
a user wishing to synthesize some kind of UIEvent
would call createEvent
with the parameter "UIEvents".
The initUIEvent
method could then be called on the
newly created UIEvent
to set the specific type of
UIEvent to be dispatched and set its context information.The
createEvent
method is used in creating
Event
s when it is either inconvenient or unnecessary
for the user to create an Event
themselves. In cases
where the implementation provided Event
is
insufficient, users may supply their own Event
implementations for use with the dispatchEvent
method.Event
DOMException
- NOT_SUPPORTED_ERR: Raised if the implementation does not support the
type of Event
interface requestedpublic final void addEventListener(java.lang.String type, org.w3c.dom.events.EventListener listener, boolean useCapture)
addEventListener
in interface org.w3c.dom.events.EventTarget
org.w3c.dom.events.EventTarget
typeThe
- event type for which the user is registeringlistenerThe
- listener
parameter takes an interface
implemented by the user which contains the methods to be called
when the event occurs.useCaptureIf
- true, useCapture
indicates that the
user wishes to initiate capture. After initiating capture, all
events of the specified type will be dispatched to the registered
EventListener
before being dispatched to any
EventTargets
beneath them in the tree. Events which
are bubbling upward through the tree will not trigger an
EventListener
designated to use capture.public final boolean dispatchEvent(org.w3c.dom.events.Event event) throws org.w3c.dom.events.EventException
dispatchEvent
in interface org.w3c.dom.events.EventTarget
java.lang.ClassCastException
- When the event wasn't provided by
the createEvent method, or otherwise isn't a DomEvent.org.w3c.dom.events.EventException
- If the event type wasn't specifiedcreateEvent(java.lang.String)
public final void removeEventListener(java.lang.String type, org.w3c.dom.events.EventListener listener, boolean useCapture)
removeEventListener
in interface org.w3c.dom.events.EventTarget
org.w3c.dom.events.EventTarget
typeSpecifies
- the event type of the EventListener
being removed.listenerThe
- EventListener
parameter indicates the
EventListener
to be removed.useCaptureSpecifies
- whether the EventListener
being removed was registered as a capturing listener or not. If a
listener was registered twice, one with capture and one without,
each must be removed separately. Removal of a capturing listener
does not affect a non-capturing version of the same listener, and
vice versa.public void normalize()
normalize
in interface Node
public boolean nameAndTypeEquals(Node other)
Note that notion of a "Per-Element-Type" attribute name scope, as found in a non-normative appendix of the XML Namespaces specification, is not supported here. Your application must implement that notion, typically by not bothering to check nameAndTypeEquals for attributes without namespace URIs unless you already know their elements are nameAndTypeEquals.
|
Source code is GPL'd in the JAXP subproject at http://savannah.gnu.org/projects/classpathx |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |