throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
Node node = fStartContainer;
Node stopNode = fEndContainer;
StringBuffer sb = new StringBuffer();
if (fStartContainer.getNodeType() == Node.TEXT_NODE
|| fStartContainer.getNodeType() == Node.CDATA_SECTION_NODE
) {
if (fStartContainer == fEndContainer) {
sb.append(fStartContainer.getNodeValue().substring(fStartOffset, fEndOffset));
return sb.toString();
}
sb.append(fStartContainer.getNodeValue().substring(fStartOffset));
node=nextNode (node,true); //fEndContainer!=fStartContainer
}
else { //fStartContainer is not a TextNode
node=node.getFirstChild();
if (fStartOffset>0) { //find a first node within a range, specified by fStartOffset
int counter=0;
while (counter<fStartOffset && node!=null) {
node=node.getNextSibling();
counter++;
}
}
if (node == null) {
node = nextNode(fStartContainer,false);
}
}
if ( fEndContainer.getNodeType()!= Node.TEXT_NODE &&
fEndContainer.getNodeType()!= Node.CDATA_SECTION_NODE ){
int i=fEndOffset;
stopNode = fEndContainer.getFirstChild();
while( i>0 && stopNode!=null ){
--i;
stopNode = stopNode.getNextSibling();
}
if ( stopNode == null )
stopNode = nextNode( fEndContainer, false );
}
while (node != stopNode) { //look into all kids of the Range