Java Code Examples for org.w3c.dom.DOMException#INDEX_SIZE_ERR

The following examples show how to use org.w3c.dom.DOMException#INDEX_SIZE_ERR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 2
Source File: RangeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 3
Source File: TextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 4
Source File: TextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 5
Source File: RangeImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 6
Source File: RangeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 7
Source File: RangeImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 8
Source File: TextImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 9
Source File: TextImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 10
Source File: RangeImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 11
Source File: TextImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 12
Source File: TextImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 13
Source File: CharacterDataImpl.java    From marklogic-contentpump with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public String substringData(int offset, int count) throws DOMException {
    if ((offset < 0) || (count < 0)) {
        throw new DOMException(DOMException.INDEX_SIZE_ERR, null);
    }
    String data = getData();
    if (offset > data.length()) {
        throw new DOMException(DOMException.INDEX_SIZE_ERR, null);
    }
    if (offset + count > data.length()) {
        return data.substring(offset);
    } else {
        return data.substring(offset, offset + count);
    }
}
 
Example 14
Source File: RangeImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 15
Source File: CharacterDataImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);

}
 
Example 16
Source File: CharacterDataImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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);

}
 
Example 17
Source File: CharacterDataImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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);

}
 
Example 18
Source File: TextImpl.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: TextImpl.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: TextImpl.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}