当前位置: 首页>>代码示例>>Java>>正文


Java DOMException.INDEX_SIZE_ERR属性代码示例

本文整理汇总了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;

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:TextImpl.java

示例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));
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:RangeImpl.java

示例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);

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:CharacterDataImpl.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:TextImpl.java


注:本文中的org.w3c.dom.DOMException.INDEX_SIZE_ERR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。