|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gdata.data.AttributeHelper
public class AttributeHelper
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. |
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. |
|
|
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. |
|
|
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. |
|
|
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 |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AttributeHelper(org.xml.sax.Attributes attrs)
attrs
- the SAX attributes to be processedMethod Detail |
---|
public java.lang.String consumeContent(boolean required) throws ParseException
required
- indicates attributes is required
null
for no text content
ParseException
- if required is set and the text content
is not definedpublic java.lang.String consume(java.lang.String name, boolean required) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attributes is required
ParseException
- if required is set and the attribute
is not definedpublic byte consumeByte(java.lang.String name, boolean required, byte defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid bytepublic byte consumeByte(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute is not
defined, or if the attribute value is not a valid bytepublic short consumeShort(java.lang.String name, boolean required, short defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid shortpublic short consumeShort(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid shortpublic int consumeInteger(java.lang.String name, boolean required, int defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used
if not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid integerpublic int consumeInteger(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid integerpublic long consumeLong(java.lang.String name, boolean required, long defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used
if not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid longpublic long consumeLong(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid longpublic java.math.BigInteger consumeBigInteger(java.lang.String name, boolean required, java.math.BigInteger defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid big integerpublic java.math.BigInteger consumeBigInteger(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid big integerpublic java.math.BigDecimal consumeBigDecimal(java.lang.String name, boolean required, java.math.BigDecimal defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid big decimalpublic java.math.BigDecimal consumeBigDecimal(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid big decimalpublic double consumeDouble(java.lang.String name, boolean required, double defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute is not defined,
or if the attribute value is not a valid doublepublic double consumeDouble(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute is not defined,
or if the attribute value is not a valid doublepublic float consumeFloat(java.lang.String name, boolean required, float defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used if
not present)
ParseException
- if required is set and the attribute is not defined,
or if the attribute value is not a valid floatpublic float consumeFloat(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute is not defined,
or if the attribute value is not a valid floatpublic boolean consumeBoolean(java.lang.String name, boolean required, boolean defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requireddefaultValue
- the default value for an optional attribute (used
if not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is neither true
nor false
.public boolean consumeBoolean(java.lang.String name, boolean required) throws ParseException
name
- attribute namerequired
- indicates attribute is required
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is neither true
nor false
.public DateTime consumeDateTime(java.lang.String name, boolean required) throws ParseException
DateTime
attribute and remove it from the list.
name
- attribute name or null
for text contentrequired
- indicates attribute is required
null
by default
ParseException
- if required is set and the attribute
is not defined, or if the date-time attribute cannot be parsedpublic <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
name
- attribute name or null
for text contentrequired
- indicates attribute is requiredenumClass
- enumeration classdefaultValue
- the default value for an optional attribute
(used if not present)enumToAttributeValue
- custom mapping of enum to attribute value
ParseException
- if required is set and the attribute is not defined,
or if the attribute value is not a valid enumerated
valuepublic <T extends java.lang.Enum<T>> T consumeEnum(java.lang.String name, boolean required, java.lang.Class<T> enumClass, T defaultValue) throws ParseException
name
- attribute name or null
for text contentrequired
- indicates attribute is requiredenumClass
- enumeration classdefaultValue
- the default value for an optional attribute (used
if not present)
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid
enumerated valuepublic <T extends java.lang.Enum<T>> T consumeEnum(java.lang.String name, boolean required, java.lang.Class<T> enumClass) throws ParseException
name
- attribute namerequired
- indicates attribute is requiredenumClass
- enumeration class
ParseException
- if required is set and the attribute
is not defined, or if the attribute value is not a valid
enumerated valuepublic void assertAllConsumed() throws ParseException
ParseException
- if an attribute in the default namespace
hasn't been removed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |