public class AttributeHelper extends Object
assertAllConsumed() usually
called from
XmlParser.ElementHandler.processEndElement().| Modifier and Type | Class and Description |
|---|---|
static interface |
AttributeHelper.EnumToAttributeValue<T extends Enum<T>>
Defines a custom mapping of an enum value to an attribute value (similar to
a closure).
|
static 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.
|
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,String> |
attrs
Maps attribute local name to string value.
|
| Constructor and Description |
|---|
AttributeHelper(Attributes attrs)
Creates a helper tied to a specific set of SAX attributes.
|
| Modifier and Type | Method and Description |
|---|---|
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)
Gets the value of a big decimal 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.
|
BigInteger |
consumeBigInteger(String name,
boolean required)
Gets the value of a big integer 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.
|
boolean |
consumeBoolean(String name,
boolean required)
Gets the value of a boolean 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.
|
byte |
consumeByte(String name,
boolean required)
Gets the value of a byte 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.
|
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)
Gets the value of a double 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.
|
<T extends Enum<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>> |
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>> |
consumeEnum(String name,
boolean required,
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(String name,
boolean required)
Gets the value of a float attribute and remove it from the list.
|
float |
consumeFloat(String name,
boolean required,
float defaultValue)
Gets the value of a float 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.
|
int |
consumeInteger(String name,
boolean required,
int defaultValue)
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)
Gets the value of a short 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.
|
public AttributeHelper(Attributes attrs)
attrs - the SAX attributes to be processedpublic String consumeContent(boolean required) throws ParseException
required - indicates attributes is requirednull for no text contentParseException - if required is set and the text content
is not definedpublic String consume(String name, boolean required) throws ParseException
name - attribute name or null for text contentrequired - indicates attributes is requiredParseException - if required is set and the attribute
is not definedpublic byte consumeByte(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute is not
defined, or if the attribute value is not a valid bytepublic short consumeShort(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is not a valid shortpublic int consumeInteger(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is not a valid integerpublic long consumeLong(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is not a valid longpublic BigInteger consumeBigInteger(String name, boolean required, 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 BigInteger consumeBigInteger(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is not a valid big integerpublic BigDecimal consumeBigDecimal(String name, boolean required, 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 BigDecimal consumeBigDecimal(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is not a valid big decimalpublic double consumeDouble(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute is not defined,
or if the attribute value is not a valid doublepublic float consumeFloat(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute is not defined,
or if the attribute value is not a valid floatpublic boolean consumeBoolean(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(String name, boolean required) throws ParseException
name - attribute namerequired - indicates attribute is requiredParseException - if required is set and the attribute
is not defined, or if the attribute value is neither true
nor false.public DateTime consumeDateTime(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 requirednull by defaultParseException - if required is set and the attribute
is not defined, or if the date-time attribute cannot be parsedpublic <T extends Enum<T>> T consumeEnum(String name, boolean required, 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 valueParseException - if required is set and the attribute is not defined,
or if the attribute value is not a valid enumerated
valuepublic <T extends Enum<T>> T consumeEnum(String name, boolean required, 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 Enum<T>> T consumeEnum(String name, boolean required, Class<T> enumClass) throws ParseException
name - attribute namerequired - indicates attribute is requiredenumClass - enumeration classParseException - 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 removedCopyright © 2012. All Rights Reserved.