Methods Summary |
---|
public org.w3c.dom.Node | appendChild(org.w3c.dom.Node newChild)
return insertChildAt(newChild, children.size());
|
public org.w3c.dom.NodeList | getChildNodes()
NodeListImpl list = new NodeListImpl();
for (NodeImpl node : children) {
list.add(node);
}
return list;
|
public org.w3c.dom.Node | getFirstChild()
return (!children.isEmpty() ? children.get(0) : null);
|
public org.w3c.dom.Node | getLastChild()
return (!children.isEmpty() ? children.get(children.size() - 1) : null);
|
public org.w3c.dom.Node | getNextSibling()
if (parent == null || index >= parent.children.size()) {
return null;
}
return parent.children.get(index + 1);
|
public boolean | hasChildNodes()
return children.size() != 0;
|
public org.w3c.dom.Node | insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
LeafNodeImpl refChildImpl = (LeafNodeImpl) refChild;
if (refChildImpl.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (refChildImpl.parent != this) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
return insertChildAt(newChild, refChildImpl.index);
|
public org.w3c.dom.Node | insertChildAt(org.w3c.dom.Node newChild, int index)Inserts a new child node into this node at a given position. If the new
node is already child of another node, it is first removed from there.
This method is the generalization of the appendChild() and insertBefore()
methods.
LeafNodeImpl newChildImpl = (LeafNodeImpl) newChild;
if (document != null && newChildImpl.document != null && newChildImpl.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (newChildImpl.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
if (newChildImpl.parent != null) {
int oldIndex = newChildImpl.index;
newChildImpl.parent.children.remove(oldIndex);
newChildImpl.parent.refreshIndices(oldIndex);
}
children.add(index, newChildImpl);
newChildImpl.parent = this;
refreshIndices(index);
return newChild;
|
public boolean | isParentOf(org.w3c.dom.Node node)
LeafNodeImpl nodeImpl = (LeafNodeImpl) node;
while (nodeImpl != null) {
if (nodeImpl == this) {
return true;
}
nodeImpl = nodeImpl.parent;
}
return false;
|
public void | normalize()
Node nextNode = null;
for (int i = children.size() - 1; i >= 0; i--) {
Node thisNode = children.get(i);
thisNode.normalize();
if (thisNode.getNodeType() == Node.TEXT_NODE) {
if (nextNode != null && nextNode.getNodeType() == Node.TEXT_NODE) {
((Text)thisNode).setData(thisNode.getNodeValue() + nextNode.getNodeValue());
removeChild(nextNode);
}
if ("".equals(thisNode.getNodeValue())) {
removeChild(thisNode);
nextNode = null;
} else {
nextNode = thisNode;
}
}
}
|
private void | refreshIndices(int fromIndex)
for (int i = fromIndex; i < children.size(); i++) {
children.get(i).index = i;
}
|
public org.w3c.dom.Node | removeChild(org.w3c.dom.Node oldChild)
LeafNodeImpl oldChildImpl = (LeafNodeImpl) oldChild;
if (oldChildImpl.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (oldChildImpl.parent != this) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
int index = oldChildImpl.index;
children.remove(index);
oldChildImpl.parent = null;
refreshIndices(index);
return oldChild;
|
public org.w3c.dom.Node | replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
LeafNodeImpl oldChildImpl = (LeafNodeImpl) oldChild;
LeafNodeImpl newChildImpl = (LeafNodeImpl) newChild;
if (oldChildImpl.document != document
|| newChildImpl.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (oldChildImpl.parent != this || newChildImpl.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
int index = oldChildImpl.index;
children.set(index, newChildImpl);
oldChildImpl.parent = null;
newChildImpl.parent = this;
refreshIndices(index);
return oldChildImpl;
|