net.dontdrinkandroot.utils.xml

## Class DomUtils

- java.lang.Object
- - net.dontdrinkandroot.utils.xml.DomUtils

    public class DomUtils
    extends Object

### Field Summary

Fields
`static org.slf4j.Logger` `LOGGER`

### Constructor Summary

Constructors
`protected` `DomUtils()` Disabled constructor, utility class.

### Method Summary

Methods
`protected static boolean` `checkPreconditions(Element element)` Checks if the element is null or does only contain whitespace text.
`static String` `getAttributeText(Element element, String tagName, String attrName)` Get the attribute text of a single child of an element by its tag name.
`static Element` `getChildByTagName(Element element, String name)` Get a single child of an element by its tag name.
`static List<Element>` `getChildrenByTagName(Element element, String name)` Get the children of an element with a specified tag name.
`static String` `getElementText(Element element, String name)` Get the element text of a single child of an element by its tag name.
`static Boolean` `toBoolean(Element element)`
`static Boolean` `toBoolean(Element element, String attributeName)`
`static ISO_3166_1_alpha2` `toCountry(Element element)`
`static Date` `toDateFromSecondsTimestamp(Element element, String attName)`
`static Double` `toDouble(Element element)`
`static Double` `toDouble(Element element, String attributeName)`
`static Float` `toFloat(Element element)`
`static Float` `toFloat(Element element, String attributeName)`
`static URL` `toHttpURL(Element element)`
`static Integer` `toInteger(Element element)`
`static Integer` `toInteger(Element element, String attributeName)`
`static Long` `toLong(Element element)`
`static Long` `toLong(Element element, String attributeName)`
`static String` `toNonEmptyString(Element element)` Retrieve the element body as a string.
`static String` `toNonEmptyString(Element element, String attributeName)`
`static URI` `toURI(Element element)`
`static URL` `toURL(Element element)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### LOGGER

    public static final org.slf4j.Logger LOGGER

### Constructor Detail

#### DomUtils

    protected DomUtils()

Disabled constructor, utility class.

### Method Detail

#### toNonEmptyString

    public static String toNonEmptyString(Element element)

Retrieve the element body as a string.

Parameters:
  `element` - The element to process.
Returns:
  The element body as string or null.

#### toNonEmptyString

    public static String toNonEmptyString(Element element,
                          String attributeName)

#### toInteger

    public static Integer toInteger(Element element)

#### toInteger

    public static Integer toInteger(Element element,
                    String attributeName)

#### toLong

    public static Long toLong(Element element)

#### toLong

    public static Long toLong(Element element,
              String attributeName)

#### toFloat

    public static Float toFloat(Element element)

#### toFloat

    public static Float toFloat(Element element,
                String attributeName)

#### toDouble

    public static Double toDouble(Element element)

#### toDouble

    public static Double toDouble(Element element,
                  String attributeName)

#### toBoolean

    public static Boolean toBoolean(Element element)

#### toBoolean

    public static Boolean toBoolean(Element element,
                    String attributeName)

#### toURL

    public static URL toURL(Element element)

#### toHttpURL

    public static URL toHttpURL(Element element)

#### toCountry

    public static ISO_3166_1_alpha2 toCountry(Element element)

#### toDateFromSecondsTimestamp

    public static Date toDateFromSecondsTimestamp(Element element,
                                  String attName)

#### toURI

    public static URI toURI(Element element)

#### getChildByTagName

    public static Element getChildByTagName(Element element,
                            String name)

Get a single child of an element by its tag name.

Parameters:
  `element` - The element to search the child for.
  `name` - The tag name of the child to search.
Returns:
  The child if found or null.

#### getElementText

    public static String getElementText(Element element,
                        String name)

Get the element text of a single child of an element by its tag name.

Parameters:
  `element` - The element to search the child for.
  `name` - The tag name of the child to search.
Returns:
  The element text of the child if found or null if not found or the text is empty.

#### getAttributeText

    public static String getAttributeText(Element element,
                          String tagName,
                          String attrName)

Get the attribute text of a single child of an element by its tag name.

Parameters:
  `element` - The element to search the child for.
  `name` - The tag name of the child to search.
  `attrName` - The name of the attribute.
Returns:
  The attribute text of the child if found or null.

#### getChildrenByTagName

    public static List<Element> getChildrenByTagName(Element element,
                                     String name)

Get the children of an element with a specified tag name.

Parameters:
  `element` - The element to search the children for.
  `name` - The tag name of the children to search for.
Returns:
  A List of the matching children (can be empty of no children found).

#### checkPreconditions

    protected static boolean checkPreconditions(Element element)

Checks if the element is null or does only contain whitespace text.

Parameters:
  `element` - The element to check.
Returns:
  True if the element can be processed.