com.raritantechnologies.utils
Class AttributeUtils

java.lang.Object
  extended bycom.raritantechnologies.utils.AttributeUtils

public final class AttributeUtils
extends java.lang.Object

Author:
jim TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Method Summary
static boolean checkBooleanAttribute(org.w3c.dom.Element elem, java.lang.String attrib, java.lang.String defaultString, boolean defaultValue)
          Tests a DOM element for the presence of an attribute, and sets a boolean flag based on its presence and string value (if any).
static int checkIntValue(org.w3c.dom.Element elem, java.lang.String attrib, int defaultInt)
           
static java.lang.String checkStringAttribute(org.w3c.dom.Element elem, java.lang.String attrib, java.lang.String defaultValue)
           
static AttributeUtils getInstance()
          Gets the unique instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static final AttributeUtils getInstance()
Gets the unique instance of this class.
Using Double-checked locking.
See this page for more information.

Returns:
the unique instance of this class

checkBooleanAttribute

public static boolean checkBooleanAttribute(org.w3c.dom.Element elem,
                                            java.lang.String attrib,
                                            java.lang.String defaultString,
                                            boolean defaultValue)

Tests a DOM element for the presence of an attribute, and sets a boolean flag based on its presence and string value (if any). Example:

 boolean myFlag = DOMUtils.checkBooleanAttribute(tagElement,
     "myFlagAttrib", "true", true);
 

will set myFlag to true if (and only if) a myFlagAttrib attribute is present on the tag and has the string value "true"; otherwise, myFlag will be false

Note: These use cases will illustrate the method's behavior:

Another way of looking at this is as follows:

checkBooleanAttribute will return its defaultValue if the attribute is present and contains any value other than the defaultString.

Parameters:
elem - - The DOM element containing the tag to be inspected.
attrib - - The DOM element attribute that determines the value.
defaultString - - The String reprentation of the default value.
defaultValue - - The boolean value to return if the default case is selected.
Returns:

checkStringAttribute

public static java.lang.String checkStringAttribute(org.w3c.dom.Element elem,
                                                    java.lang.String attrib,
                                                    java.lang.String defaultValue)
Parameters:
elem -
attrib -
defaultValue -
Returns:

checkIntValue

public static int checkIntValue(org.w3c.dom.Element elem,
                                java.lang.String attrib,
                                int defaultInt)
Parameters:
elem -
attrib -
defaultInt -
Returns: