UserDataHandler
Stay organized with collections
Save and categorize content based on your preferences.
When associating an object to a key on a node using
Node.setUserData()
the application can provide a handler
that gets called when the node the object is associated to is being
cloned, imported, or renamed. This can be used by the application to
implement various behaviors regarding the data it associates to the DOM
nodes. This interface defines that handler.
See also the Document Object Model (DOM) Level 3 Core Specification.
Constant Summary
short |
NODE_ADOPTED |
The node is adopted, using Document.adoptNode() . |
short |
NODE_CLONED |
The node is cloned, using Node.cloneNode() . |
short |
NODE_DELETED |
The node is deleted. |
short |
NODE_IMPORTED |
The node is imported, using Document.importNode() . |
short |
NODE_RENAMED |
The node is renamed, using Document.renameNode() . |
Public Method Summary
abstract
void
|
handle(short operation, String key, Object data, Node src, Node dst)
This method is called whenever the node for which this handler is
registered is imported or cloned.
|
Constants
public
static
final
short
NODE_ADOPTED
The node is adopted, using Document.adoptNode()
.
Constant Value:
5
public
static
final
short
NODE_CLONED
The node is cloned, using Node.cloneNode()
.
Constant Value:
1
public
static
final
short
NODE_DELETED
The node is deleted.
Note: This may not be supported or may not be reliable in
certain environments, such as Java, where the implementation has no
real control over when objects are actually deleted.
Constant Value:
3
public
static
final
short
NODE_IMPORTED
The node is imported, using Document.importNode()
.
Constant Value:
2
public
static
final
short
NODE_RENAMED
The node is renamed, using Document.renameNode()
.
Constant Value:
4
Public Methods
public
abstract
void
handle
(short operation, String key, Object data, Node src, Node dst)
This method is called whenever the node for which this handler is
registered is imported or cloned.
DOM applications must not raise exceptions in a
UserDataHandler
. The effect of throwing exceptions from
the handler is DOM implementation dependent.
Parameters
operation |
Specifies the type of operation that is being
performed on the node. |
key |
Specifies the key for which this handler is being called. |
data |
Specifies the data for which this handler is being called. |
src |
Specifies the node being cloned, adopted, imported, or
renamed. This is null when the node is being deleted. |
dst |
Specifies the node newly created if any, or
null .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eUserDataHandler\u003c/code\u003e allows defining custom behaviors when a DOM node with associated data is cloned, imported, or renamed.\u003c/p\u003e\n"],["\u003cp\u003eIt provides constants like \u003ccode\u003eNODE_CLONED\u003c/code\u003e, \u003ccode\u003eNODE_IMPORTED\u003c/code\u003e, etc., representing different node operations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ehandle()\u003c/code\u003e method is called during these operations, allowing developers to manage associated data.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eUserDataHandler\u003c/code\u003e is crucial for implementing application-specific logic tied to DOM node manipulations.\u003c/p\u003e\n"]]],["The `UserDataHandler` interface provides a mechanism to manage data associated with DOM nodes. When a node is cloned (`Node.cloneNode()`), adopted (`Document.adoptNode()`), imported (`Document.importNode()`), or renamed (`Document.renameNode()`), a registered handler's `handle` method is invoked. This method receives information about the operation, the associated key and data, and the source and destination nodes. `NODE_DELETED` represents the deletion operation, though its reliability varies by environment.\n"],null,["public interface **UserDataHandler** \nWhen associating an object to a key on a node using\n`Node.setUserData()` the application can provide a handler\nthat gets called when the node the object is associated to is being\ncloned, imported, or renamed. This can be used by the application to\nimplement various behaviors regarding the data it associates to the DOM\nnodes. This interface defines that handler.\n\nSee also the [Document Object Model (DOM) Level 3 Core Specification](http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407). \n\nConstant Summary\n\n|-------|---------------------------------------------------------------------------------------|------------------------------------------------------|\n| short | [NODE_ADOPTED](../../../../reference/org/w3c/dom/UserDataHandler.html#NODE_ADOPTED) | The node is adopted, using `Document.adoptNode()`. |\n| short | [NODE_CLONED](../../../../reference/org/w3c/dom/UserDataHandler.html#NODE_CLONED) | The node is cloned, using `Node.cloneNode()`. |\n| short | [NODE_DELETED](../../../../reference/org/w3c/dom/UserDataHandler.html#NODE_DELETED) | The node is deleted. |\n| short | [NODE_IMPORTED](../../../../reference/org/w3c/dom/UserDataHandler.html#NODE_IMPORTED) | The node is imported, using `Document.importNode()`. |\n| short | [NODE_RENAMED](../../../../reference/org/w3c/dom/UserDataHandler.html#NODE_RENAMED) | The node is renamed, using `Document.renameNode()`. |\n\nPublic Method Summary\n\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [handle](../../../../reference/org/w3c/dom/UserDataHandler.html#handle(short,%20java.lang.String,%20java.lang.Object,%20org.w3c.dom.Node,%20org.w3c.dom.Node))(short operation, [String](../../../../reference/java/lang/String.html) key, [Object](../../../../reference/java/lang/Object.html) data, [Node](../../../../reference/org/w3c/dom/Node.html) src, [Node](../../../../reference/org/w3c/dom/Node.html) dst) This method is called whenever the node for which this handler is registered is imported or cloned. |\n\nConstants \n\npublic static final short\n**NODE_ADOPTED** \nThe node is adopted, using `Document.adoptNode()`. \nConstant Value: 5 \n\npublic static final short\n**NODE_CLONED** \nThe node is cloned, using `Node.cloneNode()`. \nConstant Value: 1 \n\npublic static final short\n**NODE_DELETED** \nThe node is deleted.\n\n**Note:** This may not be supported or may not be reliable in\ncertain environments, such as Java, where the implementation has no\nreal control over when objects are actually deleted. \nConstant Value: 3 \n\npublic static final short\n**NODE_IMPORTED** \nThe node is imported, using `Document.importNode()`. \nConstant Value: 2 \n\npublic static final short\n**NODE_RENAMED** \nThe node is renamed, using `Document.renameNode()`. \nConstant Value: 4\n\nPublic Methods \n\npublic abstract void\n**handle**\n(short operation, [String](../../../../reference/java/lang/String.html) key, [Object](../../../../reference/java/lang/Object.html) data, [Node](../../../../reference/org/w3c/dom/Node.html) src, [Node](../../../../reference/org/w3c/dom/Node.html) dst) \nThis method is called whenever the node for which this handler is\nregistered is imported or cloned.\n\nDOM applications must not raise exceptions in a\n`UserDataHandler`. The effect of throwing exceptions from\nthe handler is DOM implementation dependent. \n\nParameters\n\n| operation | Specifies the type of operation that is being performed on the node. |\n| key | Specifies the key for which this handler is being called. |\n| data | Specifies the data for which this handler is being called. |\n| src | Specifies the node being cloned, adopted, imported, or renamed. This is `null` when the node is being deleted. |\n| dst | Specifies the node newly created if any, or `null`. |\n|-----------|----------------------------------------------------------------------------------------------------------------|"]]