CharacterDataImplpublic abstract class CharacterDataImpl extends ChildNode CharacterData is an abstract Node that can carry character data as its
Value. It provides shared behavior for Text, CData, and
possibly other node types. All offsets are 0-based.
Since ProcessingInstructionImpl inherits from this class to reuse the
setNodeValue method, this class isn't declared as implementing the interface
CharacterData. This is done by relevant subclasses (TexImpl, CommentImpl).
This class doesn't directly support mutation events, however, it notifies
the document when mutations are performed so that the document class do so. |
Fields Summary |
---|
static final long | serialVersionUIDSerialization version. | protected String | data | private static transient NodeList | singletonNodeListEmpty child nodes. |
Constructors Summary |
---|
public CharacterDataImpl()
//
// Constructors
//
| protected CharacterDataImpl(CoreDocumentImpl ownerDocument, String data)Factory constructor.
super(ownerDocument);
this.data = data;
|
Methods Summary |
---|
public void | appendData(java.lang.String data)Concatenate additional characters onto the end of the data
stored in this node. Note that this, and insert(), are the paths
by which a DOM could wind up accumulating more data than the
language's strings can easily handle. (See above discussion.)
if (isReadOnly()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
if (data == null) {
return;
}
if (needsSyncData()) {
synchronizeData();
}
setNodeValue(this.data + data);
| public void | deleteData(int offset, int count)Remove a range of characters from the node's value. Throws a
DOMException if the offset is beyond the end of the
string. However, a deletion _count_ that exceeds the available
data is accepted as a delete-to-end request.
internalDeleteData(offset, count, false);
| public org.w3c.dom.NodeList | getChildNodes()Returns an empty node list.
return singletonNodeList;
| public java.lang.String | getData()Retrieve character data currently stored in this node.
if (needsSyncData()) {
synchronizeData();
}
return data;
| public int | getLength()Report number of characters currently stored in this node's
data. It may be 0, meaning that the value is an empty string.
if (needsSyncData()) {
synchronizeData();
}
return data.length();
| public java.lang.String | getNodeValue()
if (needsSyncData()) {
synchronizeData();
}
return data;
| public void | insertData(int offset, java.lang.String data)Insert additional characters into the data stored in this node,
at the offset specified.
internalInsertData(offset, data, false);
| void | internalDeleteData(int offset, int count, boolean replace)NON-DOM INTERNAL: Within DOM actions, we sometimes need to be able
to control which mutation events are spawned. This version of the
deleteData operation allows us to do so. It is not intended
for use by application programs.
CoreDocumentImpl ownerDocument = ownerDocument();
if (ownerDocument.errorChecking) {
if (isReadOnly()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
if (count < 0) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
}
if (needsSyncData()) {
synchronizeData();
}
int tailLength = Math.max(data.length() - count - offset, 0);
try {
String value = data.substring(0, offset) +
(tailLength > 0 ? data.substring(offset + count, offset + count + tailLength) : "");
setNodeValueInternal(value, replace);
// notify document
ownerDocument.deletedText(this, offset, count);
}
catch (StringIndexOutOfBoundsException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
| void | internalInsertData(int offset, java.lang.String data, boolean replace)NON-DOM INTERNAL: Within DOM actions, we sometimes need to be able
to control which mutation events are spawned. This version of the
insertData operation allows us to do so. It is not intended
for use by application programs.
CoreDocumentImpl ownerDocument = ownerDocument();
if (ownerDocument.errorChecking && isReadOnly()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
if (needsSyncData()) {
synchronizeData();
}
try {
String value =
new StringBuffer(this.data).insert(offset, data).toString();
setNodeValueInternal(value, replace);
// notify document
ownerDocument.insertedText(this, offset, data.length());
}
catch (StringIndexOutOfBoundsException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
| public void | replaceData(int offset, int count, java.lang.String data)Replace a series of characters at the specified (zero-based)
offset with a new string, NOT necessarily of the same
length. Convenience method, equivalent to a delete followed by an
insert. Throws a DOMException if the specified offset is beyond
the end of the existing data.
CoreDocumentImpl ownerDocument = ownerDocument();
// The read-only check is done by deleteData()
// ***** This could be more efficient w/r/t Mutation Events,
// specifically by aggregating DOMAttrModified and
// DOMSubtreeModified. But mutation events are
// underspecified; I don't feel compelled
// to deal with it right now.
if (ownerDocument.errorChecking && isReadOnly()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
if (needsSyncData()) {
synchronizeData();
}
//notify document
ownerDocument.replacingData(this);
// keep old value for document notification
String oldvalue = this.data;
internalDeleteData(offset, count, true);
internalInsertData(offset, data, true);
ownerDocument.replacedCharacterData(this, oldvalue, this.data);
| public void | setData(java.lang.String value)Store character data into this node.
setNodeValue(value);
| public void | setNodeValue(java.lang.String value)Sets the content, possibly firing related events,
and updating ranges (via notification to the document)
setNodeValueInternal(value);
// notify document
ownerDocument().replacedText(this);
| protected void | setNodeValueInternal(java.lang.String value)Convenience wrapper for calling setNodeValueInternal when
we are not performing a replacement operation
setNodeValueInternal(value, false);
| protected void | setNodeValueInternal(java.lang.String value, boolean replace)This function added so that we can distinguish whether
setNodeValue has been called from some other DOM functions.
or by the client.
This is important, because we do one type of Range fix-up,
from the high-level functions in CharacterData, and another
type if the client simply calls setNodeValue(value).
CoreDocumentImpl ownerDocument = ownerDocument();
if (ownerDocument.errorChecking && isReadOnly()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
// revisit: may want to set the value in ownerDocument.
// Default behavior, overridden in some subclasses
if (needsSyncData()) {
synchronizeData();
}
// keep old value for document notification
String oldvalue = this.data;
// notify document
ownerDocument.modifyingCharacterData(this, replace);
this.data = value;
// notify document
ownerDocument.modifiedCharacterData(this, oldvalue, value, replace);
| public java.lang.String | substringData(int offset, int count)Substring is more than a convenience function. In some
implementations of the DOM, where the stored data may exceed the
length that can be returned in a single string, the only way to
read it all is to extract it in chunks via this method.
if (needsSyncData()) {
synchronizeData();
}
int length = data.length();
if (count < 0 || offset < 0 || offset > length - 1) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
int tailIndex = Math.min(offset + count, length);
return data.substring(offset, tailIndex);
|
|