}
public static void replaceData(CharacterData charData, int offset,
int count, String arg) throws DOMException {
if (charData.isReadOnly()) {
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
"CharacterData node is read only: " + charData);
} else {
if (count < 0) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
"Illegal value for count: " + count);
}
String text = charData.getText();
if (text != null) {
int length = text.length();
if ((offset < 0) || (offset >= length)) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset);
} else {
StringBuffer buffer = new StringBuffer(text);
buffer.replace(offset, offset + count, arg);
charData.setText(buffer.toString());