com.taggercat.tags
Class HTMLTagBuilder

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<java.lang.String,java.lang.String>
              extended by com.taggercat.tags.HTMLTagBuilder
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.String>

public class HTMLTagBuilder
extends java.util.LinkedHashMap<java.lang.String,java.lang.String>

A simple class to help build HTML tags.

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
HTMLTagBuilder(java.lang.String tagname)
          Creates the HTML tag
HTMLTagBuilder(java.lang.String tagname, boolean xhtml)
          Creates an HTML tag
HTMLTagBuilder(java.lang.String tagname, java.lang.String type)
          Creates an HTML input type tag
HTMLTagBuilder(java.lang.String tagname, java.lang.String type, boolean xhtml)
          Creates an HTML input type tag
 
Method Summary
 HTMLTagBuilder add(java.lang.String attributeName)
          Adds an boolean type attribute; such as enabled, readonly etc.
 HTMLTagBuilder addAttribute(java.lang.String attributeName, int value)
          Adds an attribute and its value, only if it is greater than zero
 HTMLTagBuilder addAttribute(java.lang.String attributeName, java.lang.String value)
          Adds an attribute and its value; empty values are not added when not the value attributeName
 java.lang.StringBuilder getCloseHTMLTag()
          Gets the tags corresponding closing tag, for tags such as textareas
 java.lang.String getHTMLBodyTag(java.lang.String bodyContent)
          Get a complete body tag, such as that for a textarea, or option.
 java.lang.StringBuilder getHTMLTag()
          Gets the HTML representation of the the tag
 java.lang.String put(java.lang.String key, java.lang.String value)
           
 void setChecked()
          Sets the checked attribute
 void setChecked(boolean state)
          Sets or clears the checked attribute
 void setDisabled()
          Sets the disabled attribute
 void setDisabled(boolean state)
          Sets or clears the disabled attribute
 void setReadOnly()
          Sets the readonly attribute
 void setReadOnly(boolean state)
          Sets or clears the readonly attribute
 void setSelected()
          Sets or clears the selected attribute
 void setSelected(boolean state)
          Sets or clears the selected attribute
 java.lang.String toString()
           
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

HTMLTagBuilder

public HTMLTagBuilder(java.lang.String tagname,
                      java.lang.String type,
                      boolean xhtml)
Creates an HTML input type tag

Parameters:
tagname - the tag name
type - the type of element
xhtml - set true to generate XHTML style tags

HTMLTagBuilder

public HTMLTagBuilder(java.lang.String tagname,
                      java.lang.String type)
Creates an HTML input type tag

Parameters:
tagname - the tag name
type - the type of element

HTMLTagBuilder

public HTMLTagBuilder(java.lang.String tagname,
                      boolean xhtml)
Creates an HTML tag

Parameters:
tagname - the tag name
xhtml - set true to generate XHTML style tags

HTMLTagBuilder

public HTMLTagBuilder(java.lang.String tagname)
Creates the HTML tag

Parameters:
tagname - the name of the tag
Method Detail

add

public HTMLTagBuilder add(java.lang.String attributeName)
Adds an boolean type attribute; such as enabled, readonly etc. These attributes are significant by their existence, not specifically their value. The value is set to the attribute name.

Parameters:
attributeName - the attribute name to add
Returns:
the HTMLTag

addAttribute

public HTMLTagBuilder addAttribute(java.lang.String attributeName,
                                   java.lang.String value)
Adds an attribute and its value; empty values are not added when not the value attributeName

Parameters:
attributeName - the attribute name to add
value - the value of the attribute name
Returns:
the HTMLTag

addAttribute

public HTMLTagBuilder addAttribute(java.lang.String attributeName,
                                   int value)
Adds an attribute and its value, only if it is greater than zero

Parameters:
attributeName - the attribute name to add
value - the value of the attribute name
Returns:
the HTMLTag

getHTMLTag

public java.lang.StringBuilder getHTMLTag()
Gets the HTML representation of the the tag

Returns:
the HTML representation of the the tag

getCloseHTMLTag

public java.lang.StringBuilder getCloseHTMLTag()
Gets the tags corresponding closing tag, for tags such as textareas

Returns:
the closing tag

setChecked

public void setChecked()
Sets the checked attribute


setDisabled

public void setDisabled()
Sets the disabled attribute


setReadOnly

public void setReadOnly()
Sets the readonly attribute


setSelected

public void setSelected()
Sets or clears the selected attribute


setChecked

public void setChecked(boolean state)
Sets or clears the checked attribute

Parameters:
state - the new state

setDisabled

public void setDisabled(boolean state)
Sets or clears the disabled attribute

Parameters:
state - the new state

setReadOnly

public void setReadOnly(boolean state)
Sets or clears the readonly attribute

Parameters:
state - the new state

setSelected

public void setSelected(boolean state)
Sets or clears the selected attribute

Parameters:
state - the new state

getHTMLBodyTag

public java.lang.String getHTMLBodyTag(java.lang.String bodyContent)
Get a complete body tag, such as that for a textarea, or option.

Parameters:
bodyContent -
Returns:
the complete tag

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap<java.lang.String,java.lang.String>

put

public java.lang.String put(java.lang.String key,
                            java.lang.String value)
Specified by:
put in interface java.util.Map<java.lang.String,java.lang.String>
Overrides:
put in class java.util.HashMap<java.lang.String,java.lang.String>