com.atlassian.jira.functest.config
Class ConfigXmlUtils

java.lang.Object
  extended by com.atlassian.jira.functest.config.ConfigXmlUtils

public class ConfigXmlUtils
extends Object

Some helper methods for reading in JIRA XML manipulation.


Method Summary
static org.dom4j.Element createNewElement(org.dom4j.Element parent, String elementName)
          Add a new child element to the passed parent.
static org.dom4j.Element getElementByXpath(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 Integer getIntegerValue(org.dom4j.Element element, String attribute)
          Get the integer value of the passed attribute off the passed element.
static Long getLongValue(org.dom4j.Element element, String attribute)
          Get the long value of the passed attribute off the passed element.
static String getTextValue(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 void removeAttribute(org.dom4j.Element element, String attributeName)
          Remove the attribute from the passed element.
static boolean removeElement(org.dom4j.Element element)
          Remove the passed element from dom tree.
static void setAttribute(org.dom4j.Element element, String attributeName, Object attributeValue)
          Sets the attribute of the passed element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createNewElement

public static org.dom4j.Element createNewElement(org.dom4j.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.

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

public static void removeAttribute(org.dom4j.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.

getTextValue

public static String getTextValue(org.dom4j.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.

getLongValue

public static Long getLongValue(org.dom4j.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.

getIntegerValue

public static Integer getIntegerValue(org.dom4j.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.

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

public static List<org.dom4j.Element> getElementsByXpath(org.dom4j.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.

getElementByXpath

public static org.dom4j.Element getElementByXpath(org.dom4j.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.

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.


Copyright © 2002-2012 Atlassian. All Rights Reserved.