Constructor and Description |
---|
TextNode(java.lang.String text)
Create a new TextNode representing the supplied (unencoded) text).
|
TextNode(java.lang.String text,
java.lang.String baseUri)
Deprecated.
use
TextNode(String) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
absUrl(java.lang.String key)
Get an absolute URL from a URL attribute that may be relative (i.e.
|
java.lang.String |
attr(java.lang.String key)
Get an attribute's value by its key.
|
Node |
attr(java.lang.String key,
java.lang.String value)
Set an attribute (key=value).
|
Attributes |
attributes()
Get all of the element's attributes.
|
java.lang.String |
baseUri()
Get the base URI of this node.
|
int |
childNodeSize()
Get the number of child nodes that this node holds.
|
static TextNode |
createFromEncoded(java.lang.String encodedText)
Create a new TextNode from HTML encoded (aka escaped) data.
|
static TextNode |
createFromEncoded(java.lang.String encodedText,
java.lang.String baseUri)
Deprecated.
use
createFromEncoded(String) instead, as LeafNodes don't carry base URIs. |
protected void |
doSetBaseUri(java.lang.String baseUri)
Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.
|
protected java.util.List<Node> |
ensureChildNodes() |
java.lang.String |
getWholeText()
Get the (unencoded) text of this text node, including any newlines and spaces present in the original.
|
boolean |
hasAttr(java.lang.String key)
Test if this element has an attribute.
|
protected boolean |
hasAttributes()
Check if this Node has an actual Attributes object.
|
boolean |
isBlank()
Test if this text node is blank -- that is, empty or only whitespace (including newlines).
|
java.lang.String |
nodeName()
Get the node name of this node.
|
Node |
removeAttr(java.lang.String key)
Remove an attribute from this element.
|
TextNode |
splitText(int offset)
Split this text node into two nodes at the specified string offset.
|
java.lang.String |
text()
Get the text content of this text node.
|
TextNode |
text(java.lang.String text)
Set the text content of this text node.
|
java.lang.String |
toString() |
addChildren, addChildren, after, after, before, before, childNode, childNodes, childNodesAsArray, childNodesCopy, clearAttributes, clone, doClone, equals, filter, hasParent, hasSameValue, html, indent, nextSibling, outerHtml, outerHtml, ownerDocument, parent, parentNode, previousSibling, remove, removeChild, reparentChild, replaceChild, replaceWith, root, setBaseUri, setParentNode, setSiblingIndex, shallowClone, siblingIndex, siblingNodes, traverse, unwrap, wrap
public TextNode(java.lang.String text)
text
- raw textcreateFromEncoded(String)
public TextNode(java.lang.String text, java.lang.String baseUri)
TextNode(String)
text
- raw textbaseUri
- base uri - ignored for this node typecreateFromEncoded(String, String)
public java.lang.String nodeName()
Node
public java.lang.String text()
getWholeText()
public TextNode text(java.lang.String text)
text
- unencoded textpublic java.lang.String getWholeText()
public boolean isBlank()
public TextNode splitText(int offset)
offset
- string offset point to split node at.public static TextNode createFromEncoded(java.lang.String encodedText, java.lang.String baseUri)
createFromEncoded(String)
instead, as LeafNodes don't carry base URIs.encodedText
- Text containing encoded HTML (e.g. <)baseUri
- Base uripublic static TextNode createFromEncoded(java.lang.String encodedText)
encodedText
- Text containing encoded HTML (e.g. <)protected final boolean hasAttributes()
Node
hasAttributes
in class Node
public final Attributes attributes()
Node
attributes
in class Node
public java.lang.String attr(java.lang.String key)
Node
To get an absolute URL from an attribute that may be a relative URL, prefix the key with abs
,
which is a shortcut to the Node.absUrl(java.lang.String)
method.
String url = a.attr("abs:href");
attr
in class Node
key
- The attribute key.Node.attributes()
,
Node.hasAttr(String)
,
Node.absUrl(String)
public Node attr(java.lang.String key, java.lang.String value)
Node
public boolean hasAttr(java.lang.String key)
Node
public Node removeAttr(java.lang.String key)
Node
removeAttr
in class Node
key
- The attribute to remove.public java.lang.String absUrl(java.lang.String key)
Node
<a href>
or
<img src>
).
E.g.: String absUrl = linkEl.absUrl("href");
If the attribute value is already absolute (i.e. it starts with a protocol, like
http://
or https://
etc), and it successfully parses as a URL, the attribute is
returned directly. Otherwise, it is treated as a URL relative to the element's Node.baseUri()
, and made
absolute using that.
As an alternate, you can use the Node.attr(java.lang.String)
method with the abs:
prefix, e.g.:
String absUrl = linkEl.attr("abs:href");
absUrl
in class Node
key
- The attribute keyNode.attr(java.lang.String)
,
URL.URL(java.net.URL, String)
public java.lang.String baseUri()
Node
protected void doSetBaseUri(java.lang.String baseUri)
Node
doSetBaseUri
in class Node
baseUri
- new URIpublic int childNodeSize()
Node
childNodeSize
in class Node
protected java.util.List<Node> ensureChildNodes()
ensureChildNodes
in class Node