A node within the DOM.
Method from org.apache.tapestry5.dom.Node Detail: |
void addChild(Node child) {
ensureChildren();
children.add(child);
child.container = this;
}
|
Element asElement() {
return null;
}
|
void clearChildren() {
children = null;
}
|
public final String getChildMarkup() {
PrintOutCollector collector = new PrintOutCollector();
writeChildMarkup(getDocument(), collector.getPrintWriter(), null);
return collector.getPrintOut();
}
|
public List<Node> getChildren() {
return children == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(children);
}
|
public Node getContainer() {
return container;
}
Returns the containing node for this node, or null if this node is the root element of the document. |
public Document getDocument() {
return container.getDocument();
}
|
protected Map<String, String> getNamespaceURIToPrefix() {
// For non-Elements, the container (which should be an Element) will provide the mapping.
return container.getNamespaceURIToPrefix();
}
|
boolean hasChildren() {
return children != null && !children.isEmpty();
}
|
int indexOfNode(Node node) {
ensureChildren();
int index = children.indexOf(node);
if (index < 0) throw new IllegalArgumentException("Existing element not a child of this node.");
return index;
}
|
void insertChildAt(int index,
Node child) {
ensureChildren();
children.add(index, child);
child.container = this;
}
|
public Node moveAfter(Element element) {
validateElement(element);
remove();
element.getContainer().insertChildAfter(element, this);
return this;
}
Moves this node so that it becomes a sibling of the element, ordered just after the element. |
public Node moveBefore(Element element) {
validateElement(element);
remove();
element.getContainer().insertChildBefore(element, this);
return this;
}
Moves this node so that it becomes a sibling of the element, ordered just before the element. |
public Node moveToBottom(Element element) {
validateElement(element);
remove();
element.addChild(this);
return this;
}
Moves this node so that it the last child of the element. |
public Node moveToTop(Element element) {
validateElement(element);
remove();
element.insertChildAt(0, this);
return this;
}
Moves this node so that it becomes this first child of the element, shifting existing elements forward. |
public void remove() {
getContainer().remove(this);
container = null;
}
Removes a node from its container, setting its container property to null, and removing it from its container's
list of children. |
void remove(Node node) {
if (children == null || !children.remove(node))
throw new IllegalArgumentException("Node to remove was not present as a child of this node.");
}
Removes a child node from this node. |
public void toMarkup(PrintWriter writer) {
toMarkup(getDocument(), writer, getNamespaceURIToPrefix());
}
Writes the markup for this node to the writer. |
abstract void toMarkup(Document document,
PrintWriter writer,
Map<String, String> namespaceURIToPrefix)
Implemented by each subclass, with the document passed in for efficiency. |
public String toString() {
PrintOutCollector collector = new PrintOutCollector();
toMarkup(collector.getPrintWriter());
return collector.getPrintOut();
}
|
public Element wrap(String elementName,
String namesAndValues) {
Element containerElement = container.asElement();
int index = containerElement.indexOfNode(this);
// Insert the new element just before this node.
Element element =
containerElement.elementAt(index, elementName, namesAndValues);
// Move this node inside the new element.
moveToTop(element);
return element;
}
Wraps a node inside a new element. The new element is created before the node, then the node is moved inside the
new element. |
void writeChildMarkup(Document document,
PrintWriter writer,
Map<String, String> namespaceURIToPrefix) {
if (children == null) return;
for (Node child : children)
child.toMarkup(document, writer, namespaceURIToPrefix);
}
|