com.logabit.utils
Class Dom4jHelper

java.lang.Object
  extended by com.logabit.utils.Dom4jHelper

public class Dom4jHelper
extends java.lang.Object

This helper class provides some utility methods to extract attribute values from Dom4j objects and convert them into the appropriate datatype.

Author:
Stephan Niedermeier

Constructor Summary
Dom4jHelper()
           
 
Method Summary
static boolean getAsBoolean(org.dom4j.Element elem, java.lang.String attributeName, boolean defaultValue)
          Looks for an attribute with given name in the given dom4j element and if found, converts it to boolean.
static int getAsInteger(org.dom4j.Element elem, java.lang.String attributeName, int defaultValue)
          Looks for an attribute with given name in the given dom4j element and if found, converts it to integer.
static java.lang.String getAsString(org.dom4j.Element elem, java.lang.String attributeName, java.lang.String defaultValue)
          Looks for an attribute with given name in the given dom4j element and if found, converts it to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dom4jHelper

public Dom4jHelper()
Method Detail

getAsInteger

public static int getAsInteger(org.dom4j.Element elem,
                               java.lang.String attributeName,
                               int defaultValue)
Looks for an attribute with given name in the given dom4j element and if found, converts it to integer. If no such attribute was found or the conversion to integer was failed, the given default value will be returned instead. The boolean conversion follows the rules defined by ConvertHelper.convertToInteger(String, int).

Parameters:
elem - - The dom4j element wich contains the attributes.
attributeName - - The name of the attribute to extract.
defaultValue - - The default value to return if no attribute with given could be found or the conversion to integer was failed.
Returns:
The integer representation of the attribute value.

getAsBoolean

public static boolean getAsBoolean(org.dom4j.Element elem,
                                   java.lang.String attributeName,
                                   boolean defaultValue)
Looks for an attribute with given name in the given dom4j element and if found, converts it to boolean. If no such attribute was found or the conversion to boolean was failed, the given default value will be returned instead. The boolean conversion follows the rules defined by ConvertHelper.convertToBoolean(String, boolean).

Parameters:
elem - - The dom4j element wich contains the attributes.
attributeName - - The name of the attribute to extract.
defaultValue - - The default value to return if no attribute with given could be found or the conversion to boolean was failed.
Returns:
The boolean representation of the attribute value.

getAsString

public static java.lang.String getAsString(org.dom4j.Element elem,
                                           java.lang.String attributeName,
                                           java.lang.String defaultValue)
Looks for an attribute with given name in the given dom4j element and if found, converts it to string. If no such attribute was found or the conversion to string was failed, the given default value will be returned instead. The string conversion follows the rules defined by ConvertHelper.convertToString(String, String).

Parameters:
elem - - The dom4j element wich contains the attributes.
attributeName - - The name of the attribute to extract.
defaultValue - - The default value to return if no attribute with given could be found or the conversion to string was failed.
Returns:
The string representation of the attribute value.


Copyright © 2007. All Rights Reserved.