Class ConfigXmlUtils
java.lang.Object
com.atlassian.jira.functest.config.ConfigXmlUtils
Some helper methods for reading in JIRA XML manipulation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.dom4j.ElementcreateNewElement(org.dom4j.Element parent, String elementName) Add a new child element to the passed parent.static org.dom4j.ElementgetElementByXpath(org.dom4j.Document document, String xpath) Return the element matched by the passed XPath.static List<org.dom4j.Element> getElementsByXpath(org.dom4j.Document document, String xpath) Find all the elements returned by the passed xpath.static IntegergetIntegerValue(org.dom4j.Element element, String attribute) Get the integer value of the passed attribute off the passed element.static LonggetLongValue(org.dom4j.Element element, String attribute) Get the long value of the passed attribute off the passed element.static StringgetTextValue(org.dom4j.Element element, String attribute) Get the text value of the passed attribute off the passed element.static List<org.dom4j.Element> getTopElementsByName(org.dom4j.Document document, String name) Return all the elements directly under the root of the passed document with the passed name.static voidremoveAttribute(org.dom4j.Element element, String attributeName) Remove the attribute from the passed element.static booleanremoveElement(org.dom4j.Element element) Remove the passed element from dom tree.static voidsetAttribute(org.dom4j.Element element, String attributeName, Object attributeValue) Sets the attribute of the passed element.
-
Method Details
-
createNewElement
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.
-
setAttribute
public static void setAttribute(org.dom4j.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.
-
removeAttribute
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.
-
getTextValue
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.
-
getLongValue
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.
-
getIntegerValue
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.
-
removeElement
public static boolean removeElement(org.dom4j.Element element) Remove the passed element from dom tree.- Parameters:
element- the element to remove.- Returns:
- true if the element was remove, false otherwise.
-
getElementsByXpath
Find all the elements returned by the passed xpath. Will throw anIllegalArgumentExceptionif the passed xpath returns anything byElements.- 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.
-
getElementByXpath
Return the element matched by the passed XPath. If the xpath matches more than one Node or matches a non-element, aIllegalArgumentExceptionwill 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.
-
getTopElementsByName
public static List<org.dom4j.Element> getTopElementsByName(org.dom4j.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.
-