public class DomKit extends Object
Constructor and Description |
---|
DomKit() |
Modifier and Type | Method and Description |
---|---|
static Node |
betterNode(Node node)
This returns a
Node implementation that has better toString() attached to it. |
static Node |
copyDOM(Node srcNode,
boolean convertTagsToLowerCase)
This will copy the
Node ' s from srcNode into a new DocumentFragment |
static Element |
getBodyElement(Document document)
Returns the first BODY element of the Document or null if there isnt one
|
static String |
getCollapsedText(Node node)
Returns the collapsed text of the specified Node.
|
static Element |
getFirstParentByTag(Element element,
String parentTagName) |
static String |
getHTML(Node node)
This will return an "canonical" version of the HTML that makes up the given
Element , including itself. |
static Element |
getHtmlElement(Document document)
Returns the first HTML element of the Document or null if there isnt one
|
static String |
getInnerHTML(Node node)
This will return an "canonical" version of the HTML that makes up the given
Node , exclusing itself. |
static DocumentBuilder |
getNonValidatingDocumentBuilder()
Retrieves a thread-specific non validating
DocumentBuilder . |
static String |
getRawText(Node node)
This returns a deep search of the raw text of a specified node.
|
static Text[] |
getTextNodes(Element element)
Gets all the text nodes of an Element.
|
public static DocumentBuilder getNonValidatingDocumentBuilder()
DocumentBuilder
. We do this because they are expensive to build.DocumentBuilder
serving the current thread.public static Element getHtmlElement(Document document)
document
- the Document to searchpublic static Element getBodyElement(Document document)
document
- the Document to searchpublic static Element getFirstParentByTag(Element element, String parentTagName)
element
- the element to start searching fromparentTagName
- the tag name of the parent to retrievepublic static Text[] getTextNodes(Element element)
element
- the Element in playpublic static String getCollapsedText(Node node)
So if ^ represent spaces then the string "^^^^some^bold%^text^and^someother^text" will become "some bold text and someother text".
node
- the Node to searchpublic static String getRawText(Node node)
node
- the Node
in questionpublic static String getInnerHTML(Node node)
Node
, exclusing itself.
HTML tags will be converted to lower case if they are not already.
node
- the Node in playRuntimeException
- if the parsing is unsuccessfulpublic static String getHTML(Node node)
Element
, including itself.
HTML tags will be converted to lower case if they are not already. This is a suitabe default in JIRA even if the object model of browsers and HttpUnit use uppercase for tags. It matches the JSP code we use in lower case.
node
- the Node in playRuntimeException
- if the parsing is unsuccessfulpublic static Node copyDOM(Node srcNode, boolean convertTagsToLowerCase)
Node
' s from srcNode into a new DocumentFragment
srcNode
- the source element to copy fromconvertTagsToLowerCase
- whether to copy the element tags to lower caseIllegalArgumentException
- if the srcNode is not a Document
or Element
public static Node betterNode(Node node)
Node
implementation that has better toString() attached to it. Its useful inside a debugger
so you can easily see what content a node has. Each Node
that is linked to from this node
will also get the better toString() methods applied to it.
You can call this function safely on already wrapped Node objects since it can detect if they have already been wrapped
node
- the Node to make into a better oneNode
that has the new functionalityCopyright © 2002-2022 Atlassian. All Rights Reserved.