public class

ConfigXmlUtils

extends Object
java.lang.Object
   ↳ com.atlassian.jira.functest.config.ConfigXmlUtils

Class Overview

Some helper methods for reading in JIRA XML manipulation.

Summary

Public Methods
static Element createNewElement(Element parent, String elementName)
Add a new child element to the passed parent.
static Element getElementByXpath(Document document, String xpath)
Return the element matched by the passed XPath.
static List<Element> getElementsByXpath(Document document, String xpath)
Find all the elements returned by the passed xpath.
static Integer getIntegerValue(Element element, String attribute)
Get the integer value of the passed attribute off the passed element.
static Long getLongValue(Element element, String attribute)
Get the long value of the passed attribute off the passed element.
static String getTextValue(Element element, String attribute)
Get the text value of the passed attribute off the passed element.
static List<Element> getTopElementsByName(Document document, String name)
Return all the elements directly under the root of the passed document with the passed name.
static void removeAttribute(Element element, String attributeName)
Remove the attribute from the passed element.
static boolean removeElement(Element element)
Remove the passed element from dom tree.
static void setAttribute(Element element, String attributeName, Object attributeValue)
Sets the attribute of the passed element.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static Element createNewElement (Element parent, String elementName)

Add a new child element to the passed parent. The element will be place after other elements of the same name, or if no other elements exist, as the first child of the parent.

Parameters
parent the node to add the element to.
elementName the name of the element to add.
Returns
  • the added element.

public static Element getElementByXpath (Document document, String xpath)

Return the element matched by the passed XPath. If the xpath matches more than one Node or matches a non-element, a IllegalArgumentException will be thrown. A null value will be returned if the xpath matches nothing.

Parameters
document the document to run the xpath over.
xpath the xpath to run.
Returns
  • the element matched or null if the xpath matched nothing.

public static List<Element> getElementsByXpath (Document document, String xpath)

Find all the elements returned by the passed xpath. Will throw an IllegalArgumentException if the passed xpath returns anything by Elements.

Parameters
document the document to run the xpath on.
xpath the xpath to run.
Returns
  • the elements returned from the xpath.
Throws
IllegalArgumentException if the xpath returns non-element nodes.

public static Integer getIntegerValue (Element element, String attribute)

Get the integer value of the passed attribute off the passed element. In JIRA XML backups, an attribute can be stored as either an XML attribute or as an element if necessary.

Parameters
element the element to get the attribute off.
attribute the name of the attribute to find.
Returns
  • the integer value of the attribute. Null will be returned if the attribute does not represent a long.

public static Long getLongValue (Element element, String attribute)

Get the long value of the passed attribute off the passed element. In JIRA XML backups, an attribute can be stored as either an XML attribute or as an element if necessary.

Parameters
element the element to get the attribute off.
attribute the name of the attribute to find.
Returns
  • the long value of the attribute. Null will be returned if the attribute does not represent a long.

public static String getTextValue (Element element, String attribute)

Get the text value of the passed attribute off the passed element. In JIRA XML backups, an attribute can be stored as either an XML attribute or as an element if necessary.

Parameters
element the element to get the attribute off.
attribute the name of the attribute to find.
Returns
  • the text value of the attribute.

public static List<Element> getTopElementsByName (Document document, String name)

Return all the elements directly under the root of the passed document with the passed name. Returns an empty list if no such elements exist.

Parameters
document the document to look through.
name the name of the elements to return.
Returns
  • the list of elements with the given name located under the root of the passed document. Returns an empty list if no such elements exist.

public static void removeAttribute (Element element, String attributeName)

Remove the attribute from the passed element. In JIRA XML backups, an attribute can be stored as either an XML attribute or as an element if necessary.

Parameters
element the element to remove the attribute from.
attributeName the name of the attribute to remove.

public static boolean removeElement (Element element)

Remove the passed element from dom tree.

Parameters
element the element to remove.
Returns
  • true if the element was remove, false otherwise.

public static void setAttribute (Element element, String attributeName, Object attributeValue)

Sets the attribute of the passed element.

Parameters
element the element to set the attribute on.
attributeName the name of the attribute to set.
attributeValue the value of the attribute.