Returns the textual representation of the current node and all its child nodes. @return the text value of the node including child text
()
| 376 | * @return the text value of the node including child text |
| 377 | */ |
| 378 | public String text() { |
| 379 | if (value instanceof String) { |
| 380 | return (String) value; |
| 381 | } |
| 382 | if (value instanceof NodeList) { |
| 383 | return ((NodeList) value).text(); |
| 384 | } |
| 385 | if (value instanceof Collection coll) { |
| 386 | String previousText = null; |
| 387 | StringBuilder sb = null; |
| 388 | for (Object child : coll) { |
| 389 | String childText = null; |
| 390 | if (child instanceof String) { |
| 391 | childText = (String) child; |
| 392 | } else if (child instanceof Node) { |
| 393 | childText = ((Node) child).text(); |
| 394 | } |
| 395 | if (childText != null) { |
| 396 | if (previousText == null) { |
| 397 | previousText = childText; |
| 398 | } else { |
| 399 | if (sb == null) { |
| 400 | sb = new StringBuilder(); |
| 401 | sb.append(previousText); |
| 402 | } |
| 403 | sb.append(childText); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | if (sb != null) { |
| 408 | return sb.toString(); |
| 409 | } else { |
| 410 | return Objects.requireNonNullElse(previousText, ""); |
| 411 | } |
| 412 | } |
| 413 | return "" + value; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Returns an <code>Iterator</code> of the children of the node. |
no test coverage detected