com.atlassian.jira.functest.framework.util.dom
Class DomKit

java.lang.Object
  extended by com.atlassian.jira.functest.framework.util.dom.DomKit

public class DomKit
extends Object

This is some methods to manipulate the DOM and text in it

Since:
v3.13

Constructor Summary
DomKit()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomKit

public DomKit()
Method Detail

getNonValidatingDocumentBuilder

public static DocumentBuilder getNonValidatingDocumentBuilder()
Retrieves a thread-specific non validating DocumentBuilder. We do this because they are expensive to build.

Returns:
the DocumentBuilder serving the current thread.

getHtmlElement

public static Element getHtmlElement(Document document)
Returns the first HTML element of the Document or null if there isnt one

Parameters:
document - the Document to search
Returns:
an Element of tag name body

getBodyElement

public static Element getBodyElement(Document document)
Returns the first BODY element of the Document or null if there isnt one

Parameters:
document - the Document to search
Returns:
an Element of tag name body

getFirstParentByTag

public static Element getFirstParentByTag(Element element,
                                          String parentTagName)
Parameters:
element - the element to start searching from
parentTagName - the tag name of the parent to retrieve
Returns:
the first parent element of this tag name, or null if not found

getTextNodes

public static Text[] getTextNodes(Element element)
Gets all the text nodes of an Element. Does a deep walk of the node tree.

Parameters:
element - the Element in play
Returns:
a non null array of TextNodes

getCollapsedText

public static String getCollapsedText(Node node)
Returns the collapsed text of the specified Node. The collapsing of text text is done in the following way :

So if ^ represent spaces then the string "^^^^some^bold%^text^and^someother^text" will become "some bold text and someother text".

Parameters:
node - the Node to search
Returns:
the collapsed text as a String

getRawText

public static String getRawText(Node node)
This returns a deep search of the raw text of a specified node.

Parameters:
node - the Node in question
Returns:
the raw text of the noed with no trim processing done.

getInnerHTML

public static String getInnerHTML(Node node)
This will return an "canonical" version of the HTML that makes up the given Node, exclusing itself.

HTML tags will be converted to lower case if they are not already.

Parameters:
node - the Node in play
Returns:
a text representation of the innards of the Node
Throws:
RuntimeException - if the parsing is unsuccessful

getHTML

public static String getHTML(Node node)
This will return an "canonical" version of the HTML that makes up the given 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.

Parameters:
node - the Node in play
Returns:
a text representation of the innards of the Element
Throws:
RuntimeException - if the parsing is unsuccessful

copyDOM

public static Node copyDOM(Node srcNode,
                           boolean convertTagsToLowerCase)
This will copy the Node' s from srcNode into a new DocumentFragment

Parameters:
srcNode - the source element to copy from
convertTagsToLowerCase - whether to copy the element tags to lower case
Returns:
the copied Node
Throws:
IllegalArgumentException - if the srcNode is not a Document or Element

betterNode

public static Node betterNode(Node node)
This returns a 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

Parameters:
node - the Node to make into a better one
Returns:
a proxied implementation of Node that has the new functionality


Copyright © 2002-2013 Atlassian. All Rights Reserved.