public class

AttributeHelper

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

Class Overview

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 processEndElement().

Summary

Nested Classes
interface AttributeHelper.EnumToAttributeValue<T extends Enum<T>> Defines a custom mapping of an enum value to an attribute value (similar to a closure). 
class AttributeHelper.LowerCaseEnumToAttributeValue<T extends 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. 
Fields
protected final Map<String, String> attrs Maps attribute local name to string value.
private String content element's text content or null for no text content
private boolean contentConsumed if the content has been consumed
private Set<String> dups set of attributes that are duplicated
Public Constructors
AttributeHelper(Attributes attrs)
Creates a helper tied to a specific set of SAX attributes.
Public Methods
void assertAllConsumed()
Makes sure all attributes have been removed from the list.
String consume(String name, boolean required)
Gets the value of an attribute and remove it from the list.
BigDecimal consumeBigDecimal(String name, boolean required, BigDecimal defaultValue)
Gets the value of a big decimal attribute and remove it from the list.
BigDecimal consumeBigDecimal(String name, boolean required)
Gets the value of a big decimal attribute and remove it from the list.
BigInteger consumeBigInteger(String name, boolean required, BigInteger defaultValue)
Gets the value of a big integer attribute and remove it from the list.
BigInteger consumeBigInteger(String name, boolean required)
Gets the value of a big integer attribute and remove it from the list.
boolean consumeBoolean(String name, boolean required, boolean defaultValue)
Gets the value of a boolean attribute and remove it from the list.
boolean consumeBoolean(String name, boolean required)
Gets the value of a boolean attribute and remove it from the list.
byte consumeByte(String name, boolean required, byte defaultValue)
Gets the value of a byte attribute and remove it from the list.
byte consumeByte(String name, boolean required)
Gets the value of a byte attribute and remove it from the list.
String consumeContent(boolean required)
Gets the element's text content and removes it from the list.
DateTime consumeDateTime(String name, boolean required)
Gets the value of a DateTime attribute and remove it from the list.
double consumeDouble(String name, boolean required, double defaultValue)
Gets the value of a double attribute and remove it from the list.
double consumeDouble(String name, boolean required)
Gets the value of a double attribute and remove it from the list.
<T extends Enum<T>> T consumeEnum(String name, boolean required, Class<T> enumClass, T defaultValue)
Gets the value of an enumerated attribute and remove it from the list.
<T extends Enum<T>> T consumeEnum(String name, boolean required, Class<T> enumClass)
Gets the value of an enumerated attribute and remove it from the list.
<T extends Enum<T>> T consumeEnum(String name, boolean required, Class<T> enumClass, T defaultValue, 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(String name, boolean required, float defaultValue)
Gets the value of a float attribute and remove it from the list.
float consumeFloat(String name, boolean required)
Gets the value of a float attribute and remove it from the list.
int consumeInteger(String name, boolean required, int defaultValue)
Gets the value of an integer attribute and remove it from the list.
int consumeInteger(String name, boolean required)
Gets the value of an integer attribute and remove it from the list.
long consumeLong(String name, boolean required)
Gets the value of a long attribute and remove it from the list.
long consumeLong(String name, boolean required, long defaultValue)
Gets the value of a long attribute and remove it from the list.
short consumeShort(String name, boolean required, short defaultValue)
Gets the value of a short attribute and remove it from the list.
short consumeShort(String name, boolean required)
Gets the value of a short attribute and remove it from the list.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected final Map<String, String> attrs

Maps attribute local name to string value.

private String content

element's text content or null for no text content

private boolean contentConsumed

if the content has been consumed

private Set<String> dups

set of attributes that are duplicated

Public Constructors

public AttributeHelper (Attributes attrs)

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

Parameters
attrs The SAX attributes to be processed

Public Methods

public void assertAllConsumed ()

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

public String consume (String name, boolean required)

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

public BigDecimal consumeBigDecimal (String name, boolean required, BigDecimal defaultValue)

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

public BigDecimal consumeBigDecimal (String name, boolean required)

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

public BigInteger consumeBigInteger (String name, boolean required, BigInteger defaultValue)

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

public BigInteger consumeBigInteger (String name, boolean required)

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

public boolean consumeBoolean (String name, boolean required, boolean defaultValue)

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.

public boolean consumeBoolean (String name, boolean required)

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.

public byte consumeByte (String name, boolean required, byte defaultValue)

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

public byte consumeByte (String name, boolean required)

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

public String consumeContent (boolean required)

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

public DateTime consumeDateTime (String name, boolean required)

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

public double consumeDouble (String name, boolean required, double defaultValue)

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

public double consumeDouble (String name, boolean required)

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

public T consumeEnum (String name, boolean required, Class<T> enumClass, T defaultValue)

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

public T consumeEnum (String name, boolean required, Class<T> enumClass)

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

public T consumeEnum (String name, boolean required, Class<T> enumClass, T defaultValue, 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.

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

public float consumeFloat (String name, boolean required, float defaultValue)

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

public float consumeFloat (String name, boolean required)

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

public int consumeInteger (String name, boolean required, int defaultValue)

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

public int consumeInteger (String name, boolean required)

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

public long consumeLong (String name, boolean required)

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

public long consumeLong (String name, boolean required, long defaultValue)

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

public short consumeShort (String name, boolean required, short defaultValue)

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

public short consumeShort (String name, boolean required)

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