xmlwise
Class XmlElementAttributes

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<java.lang.String,java.lang.String>
          extended by xmlwise.XmlElementAttributes
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.String>

public class XmlElementAttributes
extends java.util.HashMap<java.lang.String,java.lang.String>

This is a hash map containing all attributes of a single element.

Aside from the hash map methods, it also has convenience methods for extracting integers, booleans and doubles.

Author:
Christoffer Lerno
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
XmlElementAttributes(org.w3c.dom.Element element)
          Creates an object given an Element object.
 
Method Summary
 boolean getBoolean(java.lang.String attribute)
          Get an boolean attribute.
 double getDouble(java.lang.String attribute)
          Get a double attribute.
 int getInt(java.lang.String attribute)
          Get an integer attribute.
 java.lang.String toXml()
          Renders the content of the attributes as Xml.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

XmlElementAttributes

public XmlElementAttributes(org.w3c.dom.Element element)
Creates an object given an Element object.

Parameters:
element - the element to read from.
Method Detail

getInt

public int getInt(java.lang.String attribute)
           throws XmlParseException
Get an integer attribute.

Parameters:
attribute - the name of the attribute.
Returns:
the integer value of the attribute.
Throws:
XmlParseException - if we fail to parse this attribute as an int, or the attribute is missing.

getDouble

public double getDouble(java.lang.String attribute)
                 throws XmlParseException
Get a double attribute.

Parameters:
attribute - the name of the attribute.
Returns:
the double value of the attribute.
Throws:
XmlParseException - if we fail to parse this attribute as an double, or the attribute is missing.

getBoolean

public boolean getBoolean(java.lang.String attribute)
                   throws XmlParseException
Get an boolean attribute.

"true", "yes" and "y" are all interpreted as true. (Case-independent)

"false", "no" and "no" are all interpreted at false. (Case-independent)

Parameters:
attribute - the name of the attribute.
Returns:
the boolean value of the attribute.
Throws:
XmlParseException - if the attribute value does match true or false as defined, or the attribute is missing.

toXml

public java.lang.String toXml()
Renders the content of the attributes as Xml. Does not do proper XML-escaping.

Returns:
this attribute suitable for xml, in the format " attribute1='value1' attribute2='value2' ..."