info.informatica.html.tag
Class Attributes

java.lang.Object
  extended by info.informatica.html.tag.Attributes

public class Attributes
extends Object

Tag attributes.

When accessing individual attributes, the attribute parser can be fooled if we search for an attribute name (call it 'attrname'), and this name happens to coincide with a value in this form: name=" attrname ", i.e. with white spaces contiguous to double quotes. This is very unlikely to happen in practice.

Furthermore, this cannot happen when accessing all tags with getAttributeMap.

Author:
amengual at informatica dot info

Method Summary
 void append(String text)
           
 void appendAttribute(String attrname, String attrvalue)
           
 boolean containsAttribute(String attrname)
          Determines wheteher a given attribute is set or not.
static Attributes create(HTMLTag tag)
           
static Attributes create(HTMLTag tag, String attributes)
           
 String getAttribute(String attrname)
          Gets the value of an attribute.
 Map<String,String> getAttributeMap()
          Gets a Map of all the attributes.
 int length()
           
 String removeAttribute(String attrname)
          Removes an attribute.
 void setAttribute(String attrname, String attrvalue)
          Set attribute value
 void setAttributes(String attributes)
          Set the attribute string.
 void setDummyAttribute(String attrname)
          Set a dummy attribute.
 String toString()
          Returns a String with the attributes, including a leading space.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setAttributes

public void setAttributes(String attributes)
Set the attribute string.

Parameters:
attributes - the String containing the attributes.

create

public static Attributes create(HTMLTag tag)

create

public static Attributes create(HTMLTag tag,
                                String attributes)

getAttribute

public String getAttribute(String attrname)
                    throws TagParsingException
Gets the value of an attribute.

Parameters:
attrname - lowercase name of the attribute
Returns:
a String with the requested attribute, or null if the attribute does not exist.
Throws:
TagParsingException

removeAttribute

public String removeAttribute(String attrname)
                       throws TagParsingException
Removes an attribute.

Parameters:
attrname - lowercase name of the attribute to be removed
Returns:
a String with the value of the removed attribute, or null if no such attribute is present.
Throws:
TagParsingException

containsAttribute

public boolean containsAttribute(String attrname)
Determines wheteher a given attribute is set or not. It just tests for the presence of the attribute, not for its value.

For example, containsAttribute("disabled") would return true for the tag <sometag name="mytag" disabled="false">.


setAttribute

public void setAttribute(String attrname,
                         String attrvalue)
                  throws TagParsingException
Set attribute value

Throws:
TagParsingException

setDummyAttribute

public void setDummyAttribute(String attrname)
                       throws TagParsingException
Set a dummy attribute.

This method should be avoided, as dummy attributes are obsolete and not accepted in XHTML.

Throws:
TagParsingException

append

public void append(String text)

appendAttribute

public void appendAttribute(String attrname,
                            String attrvalue)

length

public int length()

toString

public String toString()
Returns a String with the attributes, including a leading space.

Overrides:
toString in class Object

getAttributeMap

public Map<String,String> getAttributeMap()
                                   throws TagParsingException
Gets a Map of all the attributes.

Returns:
a Map with the attribute names as keys, mapped to their corresponding attribute values. The map is not thread-safe.
Throws:
TagParsingException