org.almendra.commons.util.xml
Class JDOMUtility

java.lang.Object
  extended by org.almendra.commons.util.xml.JDOMUtility

public class JDOMUtility
extends java.lang.Object

JDOMUtility provides several utility methods to deal with Element objects of the JDOM XML parser.

Author:
Oliver Plohmann

Method Summary
static org.jdom.Element getChild(org.jdom.Element element, java.lang.String tagName)
          Answer the child element of an JDOM element with a given tag name.
static org.jdom.Element getChild(org.jdom.Element element, java.lang.String tagName, boolean mustBeNonNull)
          Answer the child element of an JDOM element with a given tag name.
static java.util.List getChildren(org.jdom.Element element, java.lang.String tagName)
          Answer all children of an JDOM element with a given tag name.
static java.util.List getChildren(org.jdom.Element element, java.lang.String tagName, boolean mustBeNonEmpty)
          Answer all children of an JDOM element with a given tag name.
static java.lang.String getChildText(org.jdom.Element element, java.lang.String tagName)
          Answer the child text of some JDOM element with a given tag name.
static java.lang.String getSingleChildContent(org.jdom.Element element, java.lang.String tagName)
          Answer the child text of the single child of some JDOM element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChild

public static org.jdom.Element getChild(org.jdom.Element element,
                                        java.lang.String tagName)
                                 throws XMLParseException
Answer the child element of an JDOM element with a given tag name. By default, element must have a child, otherwise an XMLParseException is thrown.

Parameters:
element - JDOM element to ask for a specific sub-element
tagName - tag name of the child element
Returns:
the child element with the given tag name
Throws:
XMLParseException - thrown if no child found with the given tag name

getChild

public static org.jdom.Element getChild(org.jdom.Element element,
                                        java.lang.String tagName,
                                        boolean mustBeNonNull)
                                 throws XMLParseException
Answer the child element of an JDOM element with a given tag name.

Parameters:
element - JDOM element to ask for a specific sub-element
tagName - tag name of the child element
mustBeNonNull - throw an XMLParseException in case child must exist
Returns:
the child element with the given tag name
Throws:
XMLParseException - thrown if no child found with the given tag name

getChildren

public static java.util.List getChildren(org.jdom.Element element,
                                         java.lang.String tagName)
                                  throws XMLParseException
Answer all children of an JDOM element with a given tag name. By default, element must have children, otherwise XMLParseException is thrown.

Parameters:
element - JDOM element to ask for a specific child elements
tagName - tag name of the child elements
Returns:
list of child elements
Throws:
XMLParseException - thrown if no child elements exists for the given tag name

getChildren

public static java.util.List getChildren(org.jdom.Element element,
                                         java.lang.String tagName,
                                         boolean mustBeNonEmpty)
                                  throws XMLParseException
Answer all children of an JDOM element with a given tag name.

Parameters:
element - JDOM element to ask for a specific child elements
tagName - tag name of the child elements
mustBeNonEmpty - specifiy whether element without children is allowed
Returns:
list of child elements
Throws:
XMLParseException

getChildText

public static java.lang.String getChildText(org.jdom.Element element,
                                            java.lang.String tagName)
                                     throws XMLParseException
Answer the child text of some JDOM element with a given tag name.

Parameters:
element - JDOM element to ask for text of specific child element
tagName - tag name of the child element
Returns:
child text of child with given tag name
Throws:
XMLParseException - thrown if no child elements exists for the given tag name

getSingleChildContent

public static java.lang.String getSingleChildContent(org.jdom.Element element,
                                                     java.lang.String tagName)
                                              throws XMLParseException
Answer the child text of the single child of some JDOM element.

Parameters:
element - JDOM element to ask for child text
tagName - tag name of the child element
Returns:
child text of single child
Throws:
XMLParseException - thrown if less or more than a single chil exist