in mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeMixin.java [354:424]
public final Object internalGetCharacterData(ElementAction elementAction)
throws CoreModelException {
if (getState() == COMPACT) {
return content;
} else {
Object textContent = null;
StringBuilder buffer = null;
int depth = 0;
CoreChildNode child = coreGetFirstChild();
boolean visited = false;
while (child != null) {
if (visited) {
visited = false;
} else if (child instanceof CoreElement) {
switch (elementAction) {
case RETURN_NULL:
return null;
case RECURSE:
CoreChildNode firstChild = ((CoreElement) child).coreGetFirstChild();
if (firstChild != null) {
child = firstChild;
depth++;
continue;
}
// Fall through
case SKIP:
// Just continue
}
} else {
if (child instanceof CoreCharacterDataNode
|| child instanceof CoreCDATASection) {
Object textValue =
((CoreCharacterDataContainer) child).coreGetCharacterData();
if (textValue instanceof CharacterData
|| ((String) textValue).length() != 0) {
if (textContent == null) {
// This is the first non empty text node. Just save the string.
textContent = textValue;
} else {
// We've already seen a non empty text node before. Concatenate
// using
// a StringBuilder.
if (buffer == null) {
// This is the first text node we need to append. Initialize the
// StringBuilder.
buffer = new StringBuilder(textContent.toString());
}
buffer.append(textValue.toString());
}
}
}
}
CoreChildNode nextSibling = child.coreGetNextSibling();
if (depth > 0 && nextSibling == null) {
depth--;
child = (CoreChildNode) child.coreGetParent();
visited = true;
} else {
child = nextSibling;
}
}
if (textContent == null) {
// We didn't see any text nodes. Return an empty string.
return "";
} else if (buffer != null) {
return buffer.toString();
} else {
return textContent;
}
}
}