APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xerces.internal.dom

public Class RangeImpl

extends Object
implements Range
Class Inheritance
All Implemented Interfaces
org.w3c.dom.ranges.Range
Imports
java.util.ArrayList, .List, org.w3c.dom.CharacterData, .DOMException, .DocumentFragment, .Node, org.w3c.dom.ranges.Range, .RangeException

The RangeImpl class implements the org.w3c.dom.range.Range interface.

Please see the API documentation for the interface classes and use the interfaces in your client programs.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv Node
pack-priv boolean
pack-priv DocumentImpl
pack-priv Node
pack-priv int
pack-priv boolean
pack-priv Node
pack-priv boolean
pack-priv Node
fRemoveChild

This function is called within Range instead of Node.removeChild, so that the range can remember that it is actively removing this child.

pack-priv Node
pack-priv Node
pack-priv int

Constructor Summary

AccessConstructor and Description
public
RangeImpl(DocumentImpl document)

The constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
checkIndex(Node refNode, int offset)

public DocumentFragment
cloneContents()

Implements org.w3c.dom.ranges.Range.cloneContents.

Duplicates the contents of a Range

public Range
cloneRange()

Implements org.w3c.dom.ranges.Range.cloneRange.

Produces a new Range whose boundary-points are equal to the boundary-points of the Range.

public void
collapse(boolean toStart)

Implements org.w3c.dom.ranges.Range.collapse.

Collapse a Range onto one of its boundary-points

public short
compareBoundaryPoints(short how, Range sourceRange)

Implements org.w3c.dom.ranges.Range.compareBoundaryPoints.

Compare the boundary-points of two Ranges in a document.

public void
deleteContents()

Implements org.w3c.dom.ranges.Range.deleteContents.

Removes the contents of a Range from the containing document or document fragment without returning a reference to the removed content.

pack-priv void
deleteData(CharacterData node, int offset, int count)

This function inserts text into a Node and invokes a method to fix-up all other Ranges.

public void
detach()

Implements org.w3c.dom.ranges.Range.detach.

Called to indicate that the Range is no longer in use and that the implementation may relinquish any resources associated with this Range.

public DocumentFragment
extractContents()

Implements org.w3c.dom.ranges.Range.extractContents.

Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.

public boolean
getCollapsed()

Implements org.w3c.dom.ranges.Range.getCollapsed.

TRUE if the Range is collapsed

public Node
getCommonAncestorContainer()

Implements org.w3c.dom.ranges.Range.getCommonAncestorContainer.

The deepest common ancestor container of the Range's two boundary-points.

public Node
getEndContainer()

Implements org.w3c.dom.ranges.Range.getEndContainer.

Node within which the Range ends

public int
getEndOffset()

Implements org.w3c.dom.ranges.Range.getEndOffset.

Offset within the ending node of the Range.

private Node
getRootContainer(Node node)

Given a node, calculate what the Range's root container for that node would be.

private Node

Returns:

Returns either a child node of the container or the container itself.
getSelectedNode
(Node
A container node
container
,
int
An offset within the container for which a selected node should be computed. If the offset is less than zero, or if the offset is greater than the number of children, the container is returned.
offset
)

Utility method to retrieve a child node by index.

public Node
getStartContainer()

Implements org.w3c.dom.ranges.Range.getStartContainer.

Node within which the Range begins

public int
getStartOffset()

Implements org.w3c.dom.ranges.Range.getStartOffset.

Offset within the starting node of the Range.

private boolean
hasLegalRootContainer(Node node)

Finds the root container for the given node and determines if that root container is legal with respect to the DOM 2 specification.

pack-priv int
indexOf(Node child, Node parent)

what is the index of the child in the parent

pack-priv void
insertData(CharacterData node, int index, String insert)

This function inserts text into a Node and invokes a method to fix-up all other Ranges.

public void
insertedNodeFromDOM(Node node)

This function is called from the DOM.

public void
insertNode(Node newNode)

Implements org.w3c.dom.ranges.Range.insertNode.

Inserts a node into the Document or DocumentFragment at the start of the Range.

pack-priv boolean
isAncestorOf(Node a, Node b)

is a an ancestor of b ?

private boolean
isLegalContainedNode(Node node)

Returns true IFF the given node can be contained by a range.

private boolean
isLegalContainer(Node node)

Returns true IFF the given node can serve as a container for a range's boundary points.

pack-priv Node
nextNode(Node node, boolean visitChildren)

pack-priv void
receiveDeletedText(Node node, int offset, int count)

This function is called from DOM.

pack-priv void
receiveInsertedText(Node node, int index, int len)

This function is called from DOM.

pack-priv void
receiveReplacedText(Node node)

This function is called from DOM.

pack-priv void
receiveSplitData(Node node, Node newNode, int offset)

Fix up this Range if another Range has split a Text Node into 2 Nodes.

pack-priv Node
removeChild(Node parent, Node child)

pack-priv void
removeNode(Node node)

This function must be called by the DOM _BEFORE_ a node is deleted, because at that time it is connected in the DOM tree, which we depend on.

public void
selectNode(Node refNode)

Implements org.w3c.dom.ranges.Range.selectNode.

Select a node and its contents

public void
selectNodeContents(Node refNode)

Implements org.w3c.dom.ranges.Range.selectNodeContents.

Select the contents within a node

public void
setEnd(Node refNode, int offset)

Implements org.w3c.dom.ranges.Range.setEnd.

Sets the attributes describing the end of a Range.

public void
setEndAfter(Node refNode)

Implements org.w3c.dom.ranges.Range.setEndAfter.

Sets the end of a Range to be after a node

public void
setEndBefore(Node refNode)

Implements org.w3c.dom.ranges.Range.setEndBefore.

Sets the end position to be before a node.

public void
setStart(Node refNode, int offset)

Implements org.w3c.dom.ranges.Range.setStart.

Sets the attributes describing the start of the Range.

public void
setStartAfter(Node refNode)

Implements org.w3c.dom.ranges.Range.setStartAfter.

Sets the start position to be after a node

public void
setStartBefore(Node refNode)

Implements org.w3c.dom.ranges.Range.setStartBefore.

Sets the start position to be before a node

pack-priv void
signalSplitData(Node node, Node newNode, int offset)

Signal other Ranges to update their start/end containers/offsets.

public void
surroundContents(Node newParent)

Implements org.w3c.dom.ranges.Range.surroundContents.

Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.

public String
toString()

Overrides java.lang.Object.toString.

Implements org.w3c.dom.ranges.Range.toString.

Returns the contents of a Range as a string.

private DocumentFragment

Returns:

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.
traverseCommonAncestors
(Node
Given a common ancestor of the start and end containers, this parameter is the ancestor (or self) of the start container that is a direct child of the common ancestor.
startAncestor
,
Node
Given a common ancestor of the start and end containers, this parameter is the ancestor (or self) of the end container that is a direct child of the common ancestor.
endAncestor
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
how
)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, and we also know that neither the start nor end container is an ancestor of the other.

private DocumentFragment

Returns:

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.
traverseCommonEndContainer
(Node
The ancestor of the start container that is a direct child of the end container.
startAncestor
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
how
)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, but the end container is an ancestor of the start container.

private DocumentFragment

Returns:

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.
traverseCommonStartContainer
(Node
The ancestor of the end container that is a direct child of the start container.
endAncestor
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
how
)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, but the start container is an ancestor of the end container.

private DocumentFragment

Returns:

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.
traverseContents
(int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
how
)

This is the master routine invoked to visit the nodes selected by this range.

private Node

Returns:

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.
traverseFullySelected
(Node
The node to be traversed.
n
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
how
)

Utility method for traversing a single node when we know a-priori that the node if fully selected.

private Node

Returns:

Returns a node that is the result of visiting nodes. If the traversal operation is DELETE_CONTENTS the return value is null.
traverseLeftBoundary
(Node
The node that is the root of the "left boundary" subtree.
root
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a node containing the boundaries content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will produced cloned content.
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes within the boundary.
how
)

Traverses the "left boundary" of this range and operates on each "boundary node" according to the how parameter.

private Node

Returns:

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.
traverseNode
(Node
The node to be traversed.
n
,
boolean
Set to true if the node is fully selected. Should be false otherwise. Note that although the DOM 2 specification says that a text node that is boththe start and end container is not selected, we treat it here as if it were partially selected.
isFullySelected
,
boolean
Is true if we are traversing the node as part of navigating the "left boundary" of the range. If this value is false, it implies we are navigating the "right boundary" of the range.
isLeft
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
how
)

Utility method for traversing a single node.

private Node

Returns:

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.
traversePartiallySelected
(Node
The node to be traversed.
n
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
how
)

Utility method for traversing a single node when we know a-priori that the node if partially selected and is not a text node.

private Node

Returns:

Returns a node that is the result of visiting nodes. If the traversal operation is DELETE_CONTENTS the return value is null.
traverseRightBoundary
(Node
The node that is the root of the "right boundary" subtree.
root
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a node containing the boundaries content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will produced cloned content.
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes within the boundary.
how
)

Traverses the "right boundary" of this range and operates on each "boundary node" according to the how parameter.

private DocumentFragment

Returns:

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.
traverseSameContainer
(int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
how
)

Visits the nodes selected by this range when we know a-priori that the start and end containers are the same.

private Node

Returns:

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.
traverseTextNode
(Node
The node to be traversed.
n
,
boolean
Is true if we are traversing the node as part of navigating the "left boundary" of the range. If this value is false, it implies we are navigating the "right boundary" of the range.
isLeft
,
int
Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:
  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
how
)

Utility method for traversing a text node that we know a-priori to be on a left or right boundary of the range.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CLONE_CONTENTSback to summary
pack-priv static final int CLONE_CONTENTS
DELETE_CONTENTSback to summary
pack-priv static final int DELETE_CONTENTS
EXTRACT_CONTENTSback to summary
pack-priv static final int EXTRACT_CONTENTS
fDeleteNodeback to summary
pack-priv Node fDeleteNode
fDetachback to summary
pack-priv boolean fDetach
fDocumentback to summary
pack-priv DocumentImpl fDocument
fEndContainerback to summary
pack-priv Node fEndContainer
fEndOffsetback to summary
pack-priv int fEndOffset
fInsertedFromRangeback to summary
pack-priv boolean fInsertedFromRange
fInsertNodeback to summary
pack-priv Node fInsertNode
fIsCollapsedback to summary
pack-priv boolean fIsCollapsed
fRemoveChildback to summary
pack-priv Node fRemoveChild

This function is called within Range instead of Node.removeChild, so that the range can remember that it is actively removing this child.

fSplitNodeback to summary
pack-priv Node fSplitNode
fStartContainerback to summary
pack-priv Node fStartContainer
fStartOffsetback to summary
pack-priv int fStartOffset

Constructor Detail

RangeImplback to summary
public RangeImpl(DocumentImpl document)

The constructor. Clients must use DocumentRange.createRange(), because it registers the Range with the document, so it can be fixed-up.

Method Detail

checkIndexback to summary
pack-priv void checkIndex(Node refNode, int offset) throws DOMException
cloneContentsback to summary
public DocumentFragment cloneContents() throws DOMException

Implements org.w3c.dom.ranges.Range.cloneContents.

Doc from org.w3c.dom.ranges.Range.cloneContents.

Duplicates the contents of a Range

Exceptions
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.
cloneRangeback to summary
public Range cloneRange()

Implements org.w3c.dom.ranges.Range.cloneRange.

Doc from org.w3c.dom.ranges.Range.cloneRange.

Produces a new Range whose boundary-points are equal to the boundary-points of the Range.

collapseback to summary
public void collapse(boolean toStart)

Implements org.w3c.dom.ranges.Range.collapse.

Doc from org.w3c.dom.ranges.Range.collapse.

Collapse a Range onto one of its boundary-points

compareBoundaryPointsback to summary
public short compareBoundaryPoints(short how, Range sourceRange) throws DOMException

Implements org.w3c.dom.ranges.Range.compareBoundaryPoints.

Doc from org.w3c.dom.ranges.Range.compareBoundaryPoints.

Compare the boundary-points of two Ranges in a document.

Exceptions
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.
deleteContentsback to summary
public void deleteContents() throws DOMException

Implements org.w3c.dom.ranges.Range.deleteContents.

Doc from org.w3c.dom.ranges.Range.deleteContents.

Removes the contents of a Range from the containing document or document fragment without returning a reference to the removed content.

Exceptions
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.
deleteDataback to summary
pack-priv void deleteData(CharacterData node, int offset, int count)

This function inserts text into a Node and invokes a method to fix-up all other Ranges.

detachback to summary
public void detach()

Implements org.w3c.dom.ranges.Range.detach.

Doc from org.w3c.dom.ranges.Range.detach.

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.

extractContentsback to summary
public DocumentFragment extractContents() throws DOMException

Implements org.w3c.dom.ranges.Range.extractContents.

Doc from org.w3c.dom.ranges.Range.extractContents.

Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.

Exceptions
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.
getCollapsedback to summary
public boolean getCollapsed()

Implements org.w3c.dom.ranges.Range.getCollapsed.

Doc from org.w3c.dom.ranges.Range.getCollapsed.

TRUE if the Range is collapsed

getCommonAncestorContainerback to summary
public Node getCommonAncestorContainer()

Implements org.w3c.dom.ranges.Range.getCommonAncestorContainer.

Doc from org.w3c.dom.ranges.Range.getCommonAncestorContainer.

The deepest common ancestor container of the Range's two boundary-points.

getEndContainerback to summary
public Node getEndContainer()

Implements org.w3c.dom.ranges.Range.getEndContainer.

Doc from org.w3c.dom.ranges.Range.getEndContainer.

Node within which the Range ends

getEndOffsetback to summary
public int getEndOffset()

Implements org.w3c.dom.ranges.Range.getEndOffset.

Doc from org.w3c.dom.ranges.Range.getEndOffset.

Offset within the ending node of the Range.

getRootContainerback to summary
private Node getRootContainer(Node node)

Given a node, calculate what the Range's root container for that node would be.

getSelectedNodeback to summary
private Node getSelectedNode(Node container, int offset)

Utility method to retrieve a child node by index. This method assumes the caller is trying to find out which node is selected by the given index. Note that if the index is greater than the number of children, this implies that the first node selected is the parent node itself.

Parameters
container:Node

A container node

offset:int

An offset within the container for which a selected node should be computed. If the offset is less than zero, or if the offset is greater than the number of children, the container is returned.

Returns:Node

Returns either a child node of the container or the container itself.

getStartContainerback to summary
public Node getStartContainer()

Implements org.w3c.dom.ranges.Range.getStartContainer.

Doc from org.w3c.dom.ranges.Range.getStartContainer.

Node within which the Range begins

getStartOffsetback to summary
public int getStartOffset()

Implements org.w3c.dom.ranges.Range.getStartOffset.

Doc from org.w3c.dom.ranges.Range.getStartOffset.

Offset within the starting node of the Range.

hasLegalRootContainerback to summary
private boolean hasLegalRootContainer(Node node)

Finds the root container for the given node and determines if that root container is legal with respect to the DOM 2 specification. At present, that means the root container must be either an attribute, a document, or a document fragment.

indexOfback to summary
pack-priv int indexOf(Node child, Node parent)

what is the index of the child in the parent

insertDataback to summary
pack-priv void insertData(CharacterData node, int index, String insert)

This function inserts text into a Node and invokes a method to fix-up all other Ranges.

insertedNodeFromDOMback to summary
public void insertedNodeFromDOM(Node node)

This function is called from the DOM. This node has already been inserted into the DOM. Fix-up any offsets.

insertNodeback to summary
public void insertNode(Node newNode) throws DOMException, RangeException

Implements org.w3c.dom.ranges.Range.insertNode.

Doc from org.w3c.dom.ranges.Range.insertNode.

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.

Exceptions
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.
RangeException:
INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or Document node.
isAncestorOfback to summary
pack-priv boolean isAncestorOf(Node a, Node b)

is a an ancestor of b ?

isLegalContainedNodeback to summary
private boolean isLegalContainedNode(Node node)

Returns true IFF the given node can be contained by a range.

isLegalContainerback to summary
private boolean isLegalContainer(Node node)

Returns true IFF the given node can serve as a container for a range's boundary points.

nextNodeback to summary
pack-priv Node nextNode(Node node, boolean visitChildren)
receiveDeletedTextback to summary
pack-priv void receiveDeletedText(Node node, int offset, int count)

This function is called from DOM. The text has already beeen inserted. Fix-up any offsets.

receiveInsertedTextback to summary
pack-priv void receiveInsertedText(Node node, int index, int len)

This function is called from DOM. The text has already beeen inserted. Fix-up any offsets.

receiveReplacedTextback to summary
pack-priv void receiveReplacedText(Node node)

This function is called from DOM. The text has already beeen replaced. Fix-up any offsets.

receiveSplitDataback to summary
pack-priv void receiveSplitData(Node node, Node newNode, int offset)

Fix up this Range if another Range has split a Text Node into 2 Nodes.

removeChildback to summary
pack-priv Node removeChild(Node parent, Node child)
removeNodeback to summary
pack-priv void removeNode(Node node)

This function must be called by the DOM _BEFORE_ a node is deleted, because at that time it is connected in the DOM tree, which we depend on.

selectNodeback to summary
public void selectNode(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.selectNode.

Doc from org.w3c.dom.ranges.Range.selectNode.

Select a node and its contents

Exceptions
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.
selectNodeContentsback to summary
public void selectNodeContents(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.selectNodeContents.

Doc from org.w3c.dom.ranges.Range.selectNodeContents.

Select the contents within a node

Exceptions
RangeException:
INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation or DocumentType node.
setEndback to summary
public void setEnd(Node refNode, int offset) throws RangeException, DOMException

Implements org.w3c.dom.ranges.Range.setEnd.

Doc from org.w3c.dom.ranges.Range.setEnd.

Sets the attributes describing the end of a Range.

Exceptions
RangeException:
INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation, or DocumentType node.
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.
WRONG_DOCUMENT_ERR: Raised if refNode was created from a different document than the one that created this range.
setEndAfterback to summary
public void setEndAfter(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.setEndAfter.

Doc from org.w3c.dom.ranges.Range.setEndAfter.

Sets the end of a Range to be after a node

Exceptions
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.
setEndBeforeback to summary
public void setEndBefore(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.setEndBefore.

Doc from org.w3c.dom.ranges.Range.setEndBefore.

Sets the end position to be before a node.

Exceptions
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.
setStartback to summary
public void setStart(Node refNode, int offset) throws RangeException, DOMException

Implements org.w3c.dom.ranges.Range.setStart.

Doc from org.w3c.dom.ranges.Range.setStart.

Sets the attributes describing the start of the Range.

Exceptions
RangeException:
INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation, or DocumentType node.
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.
WRONG_DOCUMENT_ERR: Raised if refNode was created from a different document than the one that created this range.
setStartAfterback to summary
public void setStartAfter(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.setStartAfter.

Doc from org.w3c.dom.ranges.Range.setStartAfter.

Sets the start position to be after a node

Exceptions
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.
setStartBeforeback to summary
public void setStartBefore(Node refNode) throws RangeException

Implements org.w3c.dom.ranges.Range.setStartBefore.

Doc from org.w3c.dom.ranges.Range.setStartBefore.

Sets the start position to be before a node

Exceptions
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.
signalSplitDataback to summary
pack-priv void signalSplitData(Node node, Node newNode, int offset)

Signal other Ranges to update their start/end containers/offsets. The data has already been split into the two Nodes.

surroundContentsback to summary
public void surroundContents(Node newParent) throws DOMException, RangeException

Implements org.w3c.dom.ranges.Range.surroundContents.

Doc from org.w3c.dom.ranges.Range.surroundContents.

Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.

Exceptions
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.
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.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.w3c.dom.ranges.Range.toString.

Doc from org.w3c.dom.ranges.Range.toString.

Returns the contents of a Range as a string. This string contains only the data characters, not any markup.

traverseCommonAncestorsback to summary
private DocumentFragment traverseCommonAncestors(Node startAncestor, Node endAncestor, int how)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, and we also know that neither the start nor end container is an ancestor of the other. This method is invoked by the generic traverse method.

Parameters
startAncestor:Node

Given a common ancestor of the start and end containers, this parameter is the ancestor (or self) of the start container that is a direct child of the common ancestor.

endAncestor:Node

Given a common ancestor of the start and end containers, this parameter is the ancestor (or self) of the end container that is a direct child of the common ancestor.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
Returns:DocumentFragment

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.

traverseCommonEndContainerback to summary
private DocumentFragment traverseCommonEndContainer(Node startAncestor, int how)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, but the end container is an ancestor of the start container. This method is invoked by the generic traverse method.

Parameters
startAncestor:Node

The ancestor of the start container that is a direct child of the end container.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
Returns:DocumentFragment

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.

traverseCommonStartContainerback to summary
private DocumentFragment traverseCommonStartContainer(Node endAncestor, int how)

Visits the nodes selected by this range when we know a-priori that the start and end containers are not the same, but the start container is an ancestor of the end container. This method is invoked by the generic traverse method.

Parameters
endAncestor:Node

The ancestor of the end container that is a direct child of the start container.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
Returns:DocumentFragment

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.

traverseContentsback to summary
private DocumentFragment traverseContents(int how) throws DOMException

This is the master routine invoked to visit the nodes selected by this range. For each such node, different actions are taken depending on the value of the how argument.

Parameters
how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
Returns:DocumentFragment

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.

traverseFullySelectedback to summary
private Node traverseFullySelected(Node n, int how)

Utility method for traversing a single node when we know a-priori that the node if fully selected.

Parameters
n:Node

The node to be traversed.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
Returns:Node

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.

traverseLeftBoundaryback to summary
private Node traverseLeftBoundary(Node root, int how)

Traverses the "left boundary" of this range and operates on each "boundary node" according to the how parameter. It is a-priori assumed by this method that the left boundary does not contain the range's end container.

A "left boundary" is best visualized by thinking of a sample tree:


                A
               /|\
              / | \
             /  |  \
            B   C   D
           /|\     /|\
          E F G   H I J
Imagine first a range that begins between the "E" and "F" nodes and ends between the "I" and "J" nodes. The start container is "B" and the end container is "D". Given this setup, the following applies:

Partially Selected Nodes: B, D
Fully Selected Nodes: F, G, C, H, I

The "left boundary" is the highest subtree node that contains the starting container. The root of this subtree is always partially selected.

In this example, the nodes that are traversed as "left boundary" nodes are: F, G, and B.

Parameters
root:Node

The node that is the root of the "left boundary" subtree.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a node containing the boundaries content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will produced cloned content.
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes within the boundary.
Returns:Node

Returns a node that is the result of visiting nodes. If the traversal operation is DELETE_CONTENTS the return value is null.

traverseNodeback to summary
private Node traverseNode(Node n, boolean isFullySelected, boolean isLeft, int how)

Utility method for traversing a single node. Does not properly handle a text node containing both the start and end offsets. Such nodes should have been previously detected and been routed to traverseTextNode.

Parameters
n:Node

The node to be traversed.

isFullySelected:boolean

Set to true if the node is fully selected. Should be false otherwise. Note that although the DOM 2 specification says that a text node that is boththe start and end container is not selected, we treat it here as if it were partially selected.

isLeft:boolean

Is true if we are traversing the node as part of navigating the "left boundary" of the range. If this value is false, it implies we are navigating the "right boundary" of the range.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
Returns:Node

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.

traversePartiallySelectedback to summary
private Node traversePartiallySelected(Node n, int how)

Utility method for traversing a single node when we know a-priori that the node if partially selected and is not a text node.

Parameters
n:Node

The node to be traversed.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
Returns:Node

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.

traverseRightBoundaryback to summary
private Node traverseRightBoundary(Node root, int how)

Traverses the "right boundary" of this range and operates on each "boundary node" according to the how parameter. It is a-priori assumed by this method that the right boundary does not contain the range's start container.

A "right boundary" is best visualized by thinking of a sample tree:

                A
               /|\
              / | \
             /  |  \
            B   C   D
           /|\     /|\
          E F G   H I J
Imagine first a range that begins between the "E" and "F" nodes and ends between the "I" and "J" nodes. The start container is "B" and the end container is "D". Given this setup, the following applies:

Partially Selected Nodes: B, D
Fully Selected Nodes: F, G, C, H, I

The "right boundary" is the highest subtree node that contains the ending container. The root of this subtree is always partially selected.

In this example, the nodes that are traversed as "right boundary" nodes are: H, I, and D.

Parameters
root:Node

The node that is the root of the "right boundary" subtree.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a node containing the boundaries content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will produced cloned content.
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes within the boundary.
Returns:Node

Returns a node that is the result of visiting nodes. If the traversal operation is DELETE_CONTENTS the return value is null.

traverseSameContainerback to summary
private DocumentFragment traverseSameContainer(int how)

Visits the nodes selected by this range when we know a-priori that the start and end containers are the same. This method is invoked by the generic traverse method.

Parameters
how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will produce a document fragment containing the range's content. Partially selected nodes are copied, but fully selected nodes are moved.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but sill produced cloned content in a document fragment
  3. DELETE_CONTENTS - will delete from the context tree of the range, all fully selected nodes.
Returns:DocumentFragment

Returns a document fragment containing any copied or extracted nodes. If the how parameter was DELETE_CONTENTS, the return value is null.

traverseTextNodeback to summary
private Node traverseTextNode(Node n, boolean isLeft, int how)

Utility method for traversing a text node that we know a-priori to be on a left or right boundary of the range. This method does not properly handle text nodes that contain both the start and end points of the range.

Parameters
n:Node

The node to be traversed.

isLeft:boolean

Is true if we are traversing the node as part of navigating the "left boundary" of the range. If this value is false, it implies we are navigating the "right boundary" of the range.

how:int

Specifies what type of traversal is being requested (extract, clone, or delete). Legal values for this argument are:

  1. EXTRACT_CONTENTS - will simply return the original node.
  2. CLONE_CONTENTS - will leave the context tree of the range undisturbed, but will return a cloned node.
  3. DELETE_CONTENTS - will delete the node from it's parent, but will return null.
Returns:Node

Returns a node that is the result of visiting the node. If the traversal operation is DELETE_CONTENTS the return value is null.