/** * Extracts a range of data from the node. * * @return Returns the specified substring. If the sum of offset and count exceeds the length, then * all 16-bit units to the end of the data are returned. */ public String substringData(int offset, int count) throws DOMException { if (offset < 0 || offset > this.getLength() || count < 0) { throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } int end = Math.min(count + offset, textValue.length()); return this.textValue.substring(offset, end); }
/** Sets the text value of data. */ public void setData(String data) throws DOMException { if (!this.isReadonly()) { this.textValue.replace(0, this.getLength(), data); } else { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null)); } }
/** Inserts a string at the specified offset. */ public void insertData(int offset, String data) throws DOMException { int length = this.getLength(); if (this.isReadonly()) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null)); } if (offset < 0 || offset > length - 1) { throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } this.textValue.insert(offset, data); }