1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.dom;
16
17 import org.htmlunit.html.DomText;
18 import org.htmlunit.javascript.HtmlUnitScriptable;
19 import org.htmlunit.javascript.configuration.JsxClass;
20 import org.htmlunit.javascript.configuration.JsxConstructor;
21 import org.htmlunit.javascript.configuration.JsxFunction;
22 import org.htmlunit.javascript.configuration.JsxGetter;
23
24 /**
25 * A JavaScript object for {@code Text}.
26 *
27 * @author David K. Taylor
28 * @author Chris Erskine
29 * @author Ahmed Ashour
30 * @author Chuck Dumont
31 * @author Ronald Brill
32 * @author Frank Danek
33 */
34 @JsxClass(domClass = DomText.class)
35 public class Text extends CharacterData {
36
37 /**
38 * JavaScript constructor.
39 */
40 @Override
41 @JsxConstructor
42 public void jsConstructor() {
43 super.jsConstructor();
44 }
45
46 /**
47 * Split a Text node in two.
48 * @param offset the character position at which to split the Text node
49 * @return the Text node that was split from this node
50 */
51 @JsxFunction
52 public HtmlUnitScriptable splitText(final int offset) {
53 final DomText domText = (DomText) getDomNodeOrDie();
54 return getScriptableFor(domText.splitText(offset));
55 }
56
57 /**
58 * Returns wholeText value.
59 * @return wholeText value
60 */
61 @JsxGetter
62 public String getWholeText() {
63 return ((DomText) getDomNodeOrDie()).getWholeText();
64 }
65 }