private void debugNode(Node node, String message) {
if (logger.isDebugEnabled()) {
// Calculate the path to this element for debugging.
Node parent = node;
Stack stack = new ArrayListStack();
do {
stack.push(parent);
parent = parent.getParent();
} while (parent != null);
// Remove the fake parent node if there is one.
Node top = (Node) stack.peek();
if (top instanceof Element && ((Element) top).getName() == null) {
stack.pop();
}
StringBuffer path = new StringBuffer();
while (!stack.isEmpty()) {
Node pathNode = (Node) stack.pop();
if (pathNode instanceof Element) {
final String name = ((Element) pathNode).getName();
path.append(name);
} else {
path.append("(text)");
}
// Count the next and previous nodes
int nextCount = 0;
Node next = pathNode.getNext();
while (next != null) {
nextCount++;
next = next.getNext();
}
int previousCount = 0;
Node previous = pathNode.getPrevious();
while (previous != null) {
previousCount++;
previous = previous.getPrevious();
}
int position = previousCount + 1;
int total = position + nextCount;
path.append("[").append(position).append(":").append(total)
.append("]");
if (!stack.isEmpty()) {
path.append(" -> ");
}
}
logger.debug(