本文整理匯總了Java中org.w3c.dom.DOMException.INDEX_SIZE_ERR屬性的典型用法代碼示例。如果您正苦於以下問題:Java DOMException.INDEX_SIZE_ERR屬性的具體用法?Java DOMException.INDEX_SIZE_ERR怎麽用?Java DOMException.INDEX_SIZE_ERR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.DOMException
的用法示例。
在下文中一共展示了DOMException.INDEX_SIZE_ERR屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: splitText
/**
* Break a text node into two sibling nodes. (Note that if the current node
* has no parent, they won't wind up as "siblings" -- they'll both be
* orphans.)
*
* @param offset
* The offset at which to split. If offset is at the end of the
* available data, the second node will be empty.
*
* @return A reference to the new node (containing data after the offset
* point). The original node will contain data up to that point.
*
* @throws DOMException(INDEX_SIZE_ERR)
* if offset is <0 or >length.
*
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
* if node is read-only.
*/
public Text splitText(int offset)
throws DOMException {
if (isReadOnly()) {
throw new DOMException(
DOMException.NO_MODIFICATION_ALLOWED_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
}
if (needsSyncData()) {
synchronizeData();
}
if (offset < 0 || offset > data.length() ) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
// split text into two separate nodes
Text newText =
getOwnerDocument().createTextNode(data.substring(offset));
setNodeValue(data.substring(0, offset));
// insert new text node
Node parentNode = getParentNode();
if (parentNode != null) {
parentNode.insertBefore(newText, nextSibling);
}
return newText;
}
示例2: checkIndex
void checkIndex(Node refNode, int offset) throws DOMException
{
if (offset < 0) {
throw new DOMException(
DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
int type = refNode.getNodeType();
// If the node contains text, ensure that the
// offset of the range is <= to the length of the text
if (type == Node.TEXT_NODE
|| type == Node.CDATA_SECTION_NODE
|| type == Node.COMMENT_NODE
|| type == Node.PROCESSING_INSTRUCTION_NODE) {
if (offset > refNode.getNodeValue().length()) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
}
else {
// Since the node is not text, ensure that the offset
// is valid with respect to the number of child nodes
if (offset > refNode.getChildNodes().getLength()) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
}
}
示例3: substringData
/**
* 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.
*
* @param offset Zero-based offset of first character to retrieve.
* @param count Number of characters to retrieve.
*
* If the sum of offset and count exceeds the length, all characters
* to end of data are returned.
*
* @throws DOMException(INDEX_SIZE_ERR) if offset is negative or
* greater than length, or if count is negative.
*
* @throws DOMException(WSTRING_SIZE_ERR) In some implementations,
* count may exceed the permitted length of strings. If so,
* substring() will throw this DOMException advising the user to
* instead retrieve the data in smaller chunks.
*/
public String substringData(int offset, int count)
throws DOMException {
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);
}
示例4: substringData
/**
* Extracts a range of data from the node.
* @param offset Start offset of substring to extract.
* @param count The number of 16-bit units to extract.
* @return The specified substring. If the sum of <code>offset</code> and
* <code>count</code> exceeds the <code>length</code>, then all 16-bit
* units to the end of the data are returned.
* @exception DOMException
* INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
* negative or greater than the number of 16-bit units in
* <code>data</code>, or if the specified <code>count</code> is
* negative.
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
* not fit into a <code>DOMString</code>.
*/
public String substringData(int offset,
int count)
throws DOMException {
if(fData == null) return null;
if(count < 0 || offset < 0 || offset > fData.length())
throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error");
if(offset+count >= fData.length())
return fData.substring(offset);
return fData.substring(offset, offset+count);
}