* @param elemValue the new element text
*/
public void editElement(String elemValue) {
if (input != null) {
NodeList list = input.getChildNodes();
CharacterData textNode = null;
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i) instanceof IDOMText) {
IDOMText text = (IDOMText) list.item(i);
if (!text.isElementContentWhitespace()) {
// This is a naive assumption that the first text space
// is the one we want to edit. What to do?
textNode = text;
break;
}
}
}
// If new value is empty...
if (elemValue == null || elemValue.trim().equals("")) { //$NON-NLS-1$
// ...and existing value is non-empty...
if (textNode != null && !textNode.getData().trim().equals("")) { //$NON-NLS-1$
// ...remove the existing element.
input.removeChild(textNode);
}
}
// If new value is non-empty...
else {
// ...ensure we have an existing element, and...
if (textNode == null) {
textNode = input.getOwnerDocument().createTextNode(""); //$NON-NLS-1$
input.appendChild(textNode);
}
// ...if existing value is different...
if (!elemValue.equals(textNode.getData())) {
// ...change the existing element.
textNode.setData(elemValue);
}
}
}
}