Search in sources :

Example 6 with DomCharacterData

use of com.gargoylesoftware.htmlunit.html.DomCharacterData in project htmlunit by HtmlUnit.

the class XMLDOMCharacterData method setData.

/**
 * Sets the node data depending on the node type.
 * @param newData the node data depending on the node type
 */
@JsxSetter
public void setData(final String newData) {
    if (newData == null || "null".equals(newData)) {
        throw Context.reportRuntimeError("Type mismatch.");
    }
    final DomCharacterData domCharacterData = getDomNodeOrDie();
    domCharacterData.setData(newData);
}
Also used : DomCharacterData(com.gargoylesoftware.htmlunit.html.DomCharacterData) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 7 with DomCharacterData

use of com.gargoylesoftware.htmlunit.html.DomCharacterData in project htmlunit by HtmlUnit.

the class XMLDOMCharacterData method replaceData.

/**
 * Replaces the specified number of characters with the supplied string.
 * @param offset the offset, in characters, at which to start replacing string data
 * @param count the number of characters to replace
 * @param data the new data that replaces the old string data
 */
@JsxFunction
public void replaceData(final int offset, final int count, final String data) {
    if (offset < 0) {
        throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data.");
    }
    if (count < 0) {
        throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data.");
    }
    if (data == null || "null".equals(data)) {
        throw Context.reportRuntimeError("Type mismatch.");
    }
    final DomCharacterData domCharacterData = getDomNodeOrDie();
    if (offset > domCharacterData.getLength()) {
        throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data.");
    }
    domCharacterData.replaceData(offset, count, data);
}
Also used : DomCharacterData(com.gargoylesoftware.htmlunit.html.DomCharacterData) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

DomCharacterData (com.gargoylesoftware.htmlunit.html.DomCharacterData)7 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)5 DomAttr (com.gargoylesoftware.htmlunit.html.DomAttr)1 DomComment (com.gargoylesoftware.htmlunit.html.DomComment)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)1 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)1 HTMLScriptElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLScriptElement)1 HTMLStyleElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLStyleElement)1 HTMLTemplateElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTemplateElement)1