# Google Data APIs Client Library (1.43.0)

## com.google.gdata.data
Class AttributeHelper

    java.lang.Object
      com.google.gdata.data.AttributeHelper

    public class AttributeHelper

extends java.lang.Object

Helps accessing tag attributes. The helper only checks attributes in the default namespace ("") and rejects unknown attributes. The idea is to remove (consume) attributes as they are read from the list and at the end make sure that all attributes have been read, to detect whether unknown attributes have been specified. This is done by the method `assertAllConsumed()` usually called from `XmlParser.ElementHandler.processEndElement()`.

Nested Class Summary
`static interface` `AttributeHelper.EnumToAttributeValue<T extends java.lang.Enum<T>>` Defines a custom mapping of an enum value to an attribute value (similar to a closure).
`static class` `AttributeHelper.LowerCaseEnumToAttributeValue<T extends java.lang.Enum<T>>` Implements the most common custom mapping of an enum value to an attribute value using the lower-case form of the enum name.

Field Summary
`protected java.util.Map<java.lang.String,java.lang.String>` `attrs` Maps attribute local name to string value.

Constructor Summary
`AttributeHelper(org.xml.sax.Attributes attrs)` Creates a helper tied to a specific set of SAX attributes.

Method Summary
`void` `assertAllConsumed()` Makes sure all attributes have been removed from the list.
`java.lang.String` `consume(java.lang.String name, boolean required)` Gets the value of an attribute and remove it from the list.
`java.math.BigDecimal` `consumeBigDecimal(java.lang.String name, boolean required)` Gets the value of a big decimal attribute and remove it from the list.
`java.math.BigDecimal` `consumeBigDecimal(java.lang.String name, boolean required, java.math.BigDecimal defaultValue)` Gets the value of a big decimal attribute and remove it from the list.
`java.math.BigInteger` `consumeBigInteger(java.lang.String name, boolean required)` Gets the value of a big integer attribute and remove it from the list.
`java.math.BigInteger` `consumeBigInteger(java.lang.String name, boolean required, java.math.BigInteger defaultValue)` Gets the value of a big integer attribute and remove it from the list.
`boolean` `consumeBoolean(java.lang.String name, boolean required)` Gets the value of a boolean attribute and remove it from the list.
`boolean` `consumeBoolean(java.lang.String name, boolean required, boolean defaultValue)` Gets the value of a boolean attribute and remove it from the list.
`byte` `consumeByte(java.lang.String name, boolean required)` Gets the value of a byte attribute and remove it from the list.
`byte` `consumeByte(java.lang.String name, boolean required, byte defaultValue)` Gets the value of a byte attribute and remove it from the list.
`java.lang.String` `consumeContent(boolean required)` Gets the element's text content and removes it from the list.
`DateTime` `consumeDateTime(java.lang.String name, boolean required)` Gets the value of a `DateTime` attribute and remove it from the list.
`double` `consumeDouble(java.lang.String name, boolean required)` Gets the value of a double attribute and remove it from the list.
`double` `consumeDouble(java.lang.String name, boolean required, double defaultValue)` Gets the value of a double attribute and remove it from the list.

`

`<T extends java.lang.Enum<T>> T`

`

`consumeEnum(java.lang.String name, boolean required, java.lang.Class<T> enumClass)`
Gets the value of an enumerated attribute and remove it from the list.

`

`<T extends java.lang.Enum<T>> T`

`

`consumeEnum(java.lang.String name, boolean required, java.lang.Class<T> enumClass, T defaultValue)`
Gets the value of an enumerated attribute and remove it from the list.

`

`<T extends java.lang.Enum<T>> T`

`

`consumeEnum(java.lang.String name, boolean required, java.lang.Class<T> enumClass, T defaultValue, AttributeHelper.EnumToAttributeValue<T> enumToAttributeValue)`
Gets the value of an enumerated attribute and remove it from the list, using a custom mapping of enum to attribute value.

`float` `consumeFloat(java.lang.String name, boolean required)` Gets the value of a float attribute and remove it from the list.
`float` `consumeFloat(java.lang.String name, boolean required, float defaultValue)` Gets the value of a float attribute and remove it from the list.
`int` `consumeInteger(java.lang.String name, boolean required)` Gets the value of an integer attribute and remove it from the list.
`int` `consumeInteger(java.lang.String name, boolean required, int defaultValue)` Gets the value of an integer attribute and remove it from the list.
`long` `consumeLong(java.lang.String name, boolean required)` Gets the value of a long attribute and remove it from the list.
`long` `consumeLong(java.lang.String name, boolean required, long defaultValue)` Gets the value of a long attribute and remove it from the list.
`short` `consumeShort(java.lang.String name, boolean required)` Gets the value of a short attribute and remove it from the list.
`short` `consumeShort(java.lang.String name, boolean required, short defaultValue)` Gets the value of a short attribute and remove it from the list.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### attrs

    protected final java.util.Map<java.lang.String,java.lang.String> attrs

  Maps attribute local name to string value.

Constructor Detail

### AttributeHelper

    public AttributeHelper(org.xml.sax.Attributes attrs)

  Creates a helper tied to a specific set of SAX attributes.

  Parameters:
    `attrs` - the SAX attributes to be processed

Method Detail

### consumeContent

    public java.lang.String consumeContent(boolean required)
                                    throws ParseException

  Gets the element's text content and removes it from the list.

  Parameters:
    `required` - indicates attributes is required
  Returns:
    element's text content or `null` for no text content
  Throws:
    `ParseException` - if required is set and the text content is not defined

### consume

    public java.lang.String consume(java.lang.String name,
                                    boolean required)
                             throws ParseException

  Gets the value of an attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attributes is required
  Returns:
    attribute value or null if not available
  Throws:
    `ParseException` - if required is set and the attribute is not defined

### consumeByte

    public byte consumeByte(java.lang.String name,
                            boolean required,
                            byte defaultValue)
                     throws ParseException

  Gets the value of a byte attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the byte value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid byte

### consumeByte

    public byte consumeByte(java.lang.String name,
                            boolean required)
                     throws ParseException

  Gets the value of a byte attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the byte value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid byte

### consumeShort

    public short consumeShort(java.lang.String name,
                              boolean required,
                              short defaultValue)
                       throws ParseException

  Gets the value of a short attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the short value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid short

### consumeShort

    public short consumeShort(java.lang.String name,
                              boolean required)
                       throws ParseException

  Gets the value of a short attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the short value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid short

### consumeInteger

    public int consumeInteger(java.lang.String name,
                              boolean required,
                              int defaultValue)
                       throws ParseException

  Gets the value of an integer attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the integer value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid integer

### consumeInteger

    public int consumeInteger(java.lang.String name,
                              boolean required)
                       throws ParseException

  Gets the value of an integer attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the integer value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid integer

### consumeLong

    public long consumeLong(java.lang.String name,
                            boolean required,
                            long defaultValue)
                     throws ParseException

  Gets the value of a long attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the long value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid long

### consumeLong

    public long consumeLong(java.lang.String name,
                            boolean required)
                     throws ParseException

  Gets the value of a long attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the long value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid long

### consumeBigInteger

    public java.math.BigInteger consumeBigInteger(java.lang.String name,
                                                  boolean required,
                                                  java.math.BigInteger defaultValue)
                                           throws ParseException

  Gets the value of a big integer attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the big integer value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid big integer

### consumeBigInteger

    public java.math.BigInteger consumeBigInteger(java.lang.String name,
                                                  boolean required)
                                           throws ParseException

  Gets the value of a big integer attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the big integer value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid big integer

### consumeBigDecimal

    public java.math.BigDecimal consumeBigDecimal(java.lang.String name,
                                                  boolean required,
                                                  java.math.BigDecimal defaultValue)
                                           throws ParseException

  Gets the value of a big decimal attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the big decimal value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid big decimal

### consumeBigDecimal

    public java.math.BigDecimal consumeBigDecimal(java.lang.String name,
                                                  boolean required)
                                           throws ParseException

  Gets the value of a big decimal attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the big decimal value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid big decimal

### consumeDouble

    public double consumeDouble(java.lang.String name,
                                boolean required,
                                double defaultValue)
                         throws ParseException

  Gets the value of a double attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the double value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid double

### consumeDouble

    public double consumeDouble(java.lang.String name,
                                boolean required)
                         throws ParseException

  Gets the value of a double attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the double value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid double

### consumeFloat

    public float consumeFloat(java.lang.String name,
                              boolean required,
                              float defaultValue)
                       throws ParseException

  Gets the value of a float attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the float value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid float

### consumeFloat

    public float consumeFloat(java.lang.String name,
                              boolean required)
                       throws ParseException

  Gets the value of a float attribute and remove it from the list.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the float value of this attribute, 0 by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid float

### consumeBoolean

    public boolean consumeBoolean(java.lang.String name,
                                  boolean required,
                                  boolean defaultValue)
                           throws ParseException

  Gets the value of a boolean attribute and remove it from the list. The accepted values are based upon xsd:boolean syntax (true, false, 1, 0).

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    the boolean value of this attribute
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is neither `true` nor `false`.

### consumeBoolean

    public boolean consumeBoolean(java.lang.String name,
                                  boolean required)
                           throws ParseException

  Gets the value of a boolean attribute and remove it from the list. The accepted values are based upon xsd:boolean syntax (true, false, 1, 0).

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
  Returns:
    the boolean value of this attribute, false by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is neither `true` nor `false`.

### consumeDateTime

    public DateTime consumeDateTime(java.lang.String name,
                                    boolean required)
                             throws ParseException

  Gets the value of a `DateTime` attribute and remove it from the list.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
  Returns:
    the date-time value of this attribute, `null` by default
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the date-time attribute cannot be parsed

### consumeEnum

    public <T extends java.lang.Enum<T>> T consumeEnum(java.lang.String name,
                                                       boolean required,
                                                       java.lang.Class<T> enumClass,
                                                       T defaultValue,
                                                       AttributeHelper.EnumToAttributeValue<T> enumToAttributeValue)
                                            throws ParseException

  Gets the value of an enumerated attribute and remove it from the list, using a custom mapping of enum to attribute value.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `enumClass` - enumeration class
    `defaultValue` - the default value for an optional attribute (used if not present)
    `enumToAttributeValue` - custom mapping of enum to attribute value
  Returns:
    an enumerated value
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid enumerated value

### consumeEnum

    public <T extends java.lang.Enum<T>> T consumeEnum(java.lang.String name,
                                                       boolean required,
                                                       java.lang.Class<T> enumClass,
                                                       T defaultValue)
                                            throws ParseException

  Gets the value of an enumerated attribute and remove it from the list. Enumerated values are case-insensitive.

  Parameters:
    `name` - attribute name or `null` for text content
    `required` - indicates attribute is required
    `enumClass` - enumeration class
    `defaultValue` - the default value for an optional attribute (used if not present)
  Returns:
    an enumerated value
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid enumerated value

### consumeEnum

    public <T extends java.lang.Enum<T>> T consumeEnum(java.lang.String name,
                                                       boolean required,
                                                       java.lang.Class<T> enumClass)
                                            throws ParseException

  Gets the value of an enumerated attribute and remove it from the list. Enumerated values are case-insensitive.

  Parameters:
    `name` - attribute name
    `required` - indicates attribute is required
    `enumClass` - enumeration class
  Returns:
    an enumerated value or null if not present
  Throws:
    `ParseException` - if required is set and the attribute is not defined, or if the attribute value is not a valid enumerated value

### assertAllConsumed

    public void assertAllConsumed()
                           throws ParseException

  Makes sure all attributes have been removed from the list. To all attribute in the default namespace must correspond exactly one call to consume*().

  Throws:
    `ParseException` - if an attribute in the default namespace hasn't been removed