HATS 7.5.1 Web API Reference

Publicly accessible methods not documented here are for IBM internal use only and may change in a future release of the product.

com.ibm.hats.transform.html
Class HTMLElement

java.lang.Object
  extended by com.ibm.hats.transform.html.HTMLElement
Direct Known Subclasses:
AccessibilityLabelElement, EnptuiScrollbarElement, ImageElement, InputElement, LinkElement, OptionElement, PopupElement, SelectElement

public class HTMLElement
extends Object

HTMLElement is the parent class for all objects which represent an HTML tag or a set of HTML tags. HTMLElements should be used when generating HTML content to maintain a consistency across all of code generating HTML output, as well as encourage more object-oriented programming. Objects subclassing HTMLElement should only have state, and should not have any dependency on other packages. Rendering of specific HTMLElement descendants should be handled by this class. Construction of HTMLElements is facilitated through the use of a HTMLElementFactory.

Simple Example:

 //obtain a StringBuffer called buffer
 
 //create element
 HTMLElement div = new HTMLElement("DIV");
 
 //configure element
 div.setStyle("background-color:green;");
 
 //render element
 div.render(buffer);
 buffer.append("Hello World");
 div.renderEndTag(buffer);
 
Output would look like:
Hello World

See Also:
HTMLElementFactory, Widget

Field Summary
static String ATTR_ACCESS_KEY
          Attribute map key
static String ATTR_ACTION
           
static String ATTR_ALT
          Attribute map key
static String ATTR_CLASS_NAME
          Attribute map key
static String ATTR_DIR
          Attribute map key
static String ATTR_FOR
          Attribute map key
static String ATTR_HREF
          Attribute map key
static String ATTR_ID
          Attribute map key
static String ATTR_IMG_ALT
          Attribute alt
static String ATTR_MAX_LENGTH
          Attribute map key
static String ATTR_NAME
          Attribute map key
static String ATTR_ON_BLUR
          Attribute map key
static String ATTR_ON_CHANGE
          Attribute map key
static String ATTR_ON_CLICK
          Attribute map key
static String ATTR_ON_CUT
           
static String ATTR_ON_DROP
           
static String ATTR_ON_FOCUS
          Attribute map key
static String ATTR_ON_KEY_DOWN
           
static String ATTR_ON_KEY_PRESS
          Attribute map key
static String ATTR_ON_KEY_UP
           
static String ATTR_ON_MOUSEDOWN
          Attribute map key
static String ATTR_ON_MOUSEOVER
          Attribute map key
static String ATTR_ON_PASTE
           
static String ATTR_SIZE
          Attribute map key
static String ATTR_SRC
          Attribute map key
static String ATTR_STYLE
          Attribute map key
static String ATTR_TARGET
          Attribute map key
static String ATTR_TYPE
          Attribute map key
static String ATTR_VALUE
          Attribute map key
static String CLASSNAME
           
static String FLAG_CHECKED
          Flag set key
static String FLAG_DISABLED
          Flag disabled key
static String FLAG_MULTIPLE
          Flag set key
static String FLAG_READ_ONLY
          Flag readonly
static String FLAG_SELECTED
          Flag set key
protected  String tagName
           
 
Constructor Summary
HTMLElement()
          Class constructor.
HTMLElement(String tagName)
          Class constructor which sets the name of the HTML tag.
HTMLElement(String tagName, boolean preserveAttributeOrder)
          Class constructor which sets the name of the HTML tag.
 
Method Summary
 void addFlag(String flag)
          Adds the named flag to this HTMLElement
 void appendClassName(String className)
          Sets the element's class name attribute.
 void appendStyle(String style)
          Adds the specified style String to the current style value, separated with a semi-colon character.
 void buildTag(StringBuffer buffer)
          Builds HTML output from the current state.
 void buildTag(StringBuffer buffer, boolean closeTag)
          Builds HTML output from the current state.
 String getAttribute(String name)
          Gets the value of the specified attribute of this HTMLElement
 String getClassName()
          Returns the CSS Class Name.
 String getDir()
          Gets the direction.
 String getId()
          Returns the id.
 String getName()
          Returns the name.
 String getStyle()
          Gets the style.
 String getTagName()
          Gets the tag name for this HTMLElement.
 boolean hasFlag(String flag)
          Determines whether or not this HTMLElement has the named flag set
 void removeFlag(String flag)
          Removes the named flag from this HTMLElement
 String render()
          Output this HTMLElement as a String.
 String render(boolean closeTag)
          Output this HTMLElement as a String.
 void render(StringBuffer buffer)
          Append this HTMLElement to the specified StringBuffer.
 void render(StringBuffer buffer, boolean closeTag)
          Append this HTMLElement to the specified StringBuffer.
 String renderEndTag()
          Converts the closing tag for this HTMLElement to a string.
 void renderEndTag(StringBuffer buffer)
          Appends the closing tag for this HTMLElement to specified StringBuffer.
 void setAlign(String dir)
          Sets the direction (dir) attribute.
 void setAttribute(String name, String value)
          Sets an named attribute on this HTMLElement.
 void setClassName(String className)
          Sets the className.
 void setDir(String dir)
          Sets the direction (dir) attribute.
 void setId(String id)
          Sets the id attribute.
 void setName(String name)
          Sets the name.
 void setStyle(String style)
          Sets the style attribute.
 void setTagName(String tagName)
          Sets the tag name for this HTMLElement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

public static final String CLASSNAME
See Also:
Constant Field Values

tagName

protected String tagName

ATTR_NAME

public static final String ATTR_NAME
Attribute map key

See Also:
Constant Field Values

ATTR_ID

public static final String ATTR_ID
Attribute map key

See Also:
Constant Field Values

ATTR_STYLE

public static final String ATTR_STYLE
Attribute map key

See Also:
Constant Field Values

ATTR_CLASS_NAME

public static final String ATTR_CLASS_NAME
Attribute map key

See Also:
Constant Field Values

ATTR_TYPE

public static final String ATTR_TYPE
Attribute map key

See Also:
Constant Field Values

ATTR_VALUE

public static final String ATTR_VALUE
Attribute map key

See Also:
Constant Field Values

ATTR_MAX_LENGTH

public static final String ATTR_MAX_LENGTH
Attribute map key

See Also:
Constant Field Values

ATTR_SIZE

public static final String ATTR_SIZE
Attribute map key

See Also:
Constant Field Values

ATTR_ON_CHANGE

public static final String ATTR_ON_CHANGE
Attribute map key

See Also:
Constant Field Values

ATTR_ON_FOCUS

public static final String ATTR_ON_FOCUS
Attribute map key

See Also:
Constant Field Values

ATTR_ON_CLICK

public static final String ATTR_ON_CLICK
Attribute map key

See Also:
Constant Field Values

ATTR_ON_MOUSEOVER

public static final String ATTR_ON_MOUSEOVER
Attribute map key

See Also:
Constant Field Values

ATTR_ON_MOUSEDOWN

public static final String ATTR_ON_MOUSEDOWN
Attribute map key

See Also:
Constant Field Values

ATTR_ON_BLUR

public static final String ATTR_ON_BLUR
Attribute map key

See Also:
Constant Field Values

ATTR_ON_KEY_PRESS

public static final String ATTR_ON_KEY_PRESS
Attribute map key

See Also:
Constant Field Values

ATTR_ON_KEY_UP

public static final String ATTR_ON_KEY_UP
See Also:
Constant Field Values

ATTR_ON_KEY_DOWN

public static final String ATTR_ON_KEY_DOWN
See Also:
Constant Field Values

ATTR_ACTION

public static final String ATTR_ACTION
See Also:
Constant Field Values

ATTR_ON_PASTE

public static final String ATTR_ON_PASTE
See Also:
Constant Field Values

ATTR_ON_DROP

public static final String ATTR_ON_DROP
See Also:
Constant Field Values

ATTR_ON_CUT

public static final String ATTR_ON_CUT
See Also:
Constant Field Values

ATTR_HREF

public static final String ATTR_HREF
Attribute map key

See Also:
Constant Field Values

ATTR_TARGET

public static final String ATTR_TARGET
Attribute map key

See Also:
Constant Field Values

FLAG_MULTIPLE

public static final String FLAG_MULTIPLE
Flag set key

See Also:
Constant Field Values

FLAG_SELECTED

public static final String FLAG_SELECTED
Flag set key

See Also:
Constant Field Values

ATTR_ACCESS_KEY

public static final String ATTR_ACCESS_KEY
Attribute map key

See Also:
Constant Field Values

FLAG_CHECKED

public static final String FLAG_CHECKED
Flag set key

See Also:
Constant Field Values

FLAG_DISABLED

public static final String FLAG_DISABLED
Flag disabled key

See Also:
Constant Field Values

FLAG_READ_ONLY

public static final String FLAG_READ_ONLY
Flag readonly

See Also:
Constant Field Values

ATTR_SRC

public static final String ATTR_SRC
Attribute map key

See Also:
Constant Field Values

ATTR_DIR

public static final String ATTR_DIR
Attribute map key

See Also:
Constant Field Values

ATTR_ALT

public static final String ATTR_ALT
Attribute map key

See Also:
Constant Field Values

ATTR_IMG_ALT

public static final String ATTR_IMG_ALT
Attribute alt

See Also:
Constant Field Values

ATTR_FOR

public static final String ATTR_FOR
Attribute map key

See Also:
Constant Field Values
Constructor Detail

HTMLElement

public HTMLElement()
Class constructor. Makes an instance with no name that does not preserve the order of added attributes.


HTMLElement

public HTMLElement(String tagName)
Class constructor which sets the name of the HTML tag. The ordering of added attributes is not preserved.

Parameters:
tagName -

HTMLElement

public HTMLElement(String tagName,
                   boolean preserveAttributeOrder)
Class constructor which sets the name of the HTML tag.

Parameters:
tagName -
preserveAttributeOrder - preserves the ordering of the attributes on render, if true.
Method Detail

render

public String render()
Output this HTMLElement as a String. The element is not closed.

Returns:
String

render

public String render(boolean closeTag)
Output this HTMLElement as a String.

Parameters:
closeTag - specifies whether to close the tag with a "/>"
Returns:
String

render

public void render(StringBuffer buffer)
Append this HTMLElement to the specified StringBuffer. The element is not closed.

Parameters:
buffer -

render

public void render(StringBuffer buffer,
                   boolean closeTag)
Append this HTMLElement to the specified StringBuffer.

Parameters:
buffer -
closeTag - specifies whether to close the tag with a "/>"

setTagName

public void setTagName(String tagName)
Sets the tag name for this HTMLElement.

Parameters:
tagName - the tag name for this element

getTagName

public String getTagName()
Gets the tag name for this HTMLElement.

Returns:
String tag name or null if no tag name.

getClassName

public String getClassName()
Returns the CSS Class Name.

Returns:
String class name or null if no class name.

getId

public String getId()
Returns the id.

Returns:
String ID or null if no ID.

getName

public String getName()
Returns the name.

Returns:
String name or null if no name.

appendClassName

public void appendClassName(String className)
Sets the element's class name attribute. Appends after a space character if a class name already exists.

Parameters:
className - The class name to set.

setClassName

public void setClassName(String className)
Sets the className. Replaces the existing class name, if any.

Parameters:
className - The className to set

setId

public void setId(String id)
Sets the id attribute. Replaces the existing value, if any.

Parameters:
id - The id to set

setName

public void setName(String name)
Sets the name. Replaces the existing value, if any.

Parameters:
name - The name to set

setDir

public void setDir(String dir)
Sets the direction (dir) attribute. Replaces the existing value, if any.

Parameters:
dir - either "ltr" or "rtl"

setAlign

public void setAlign(String dir)
Sets the direction (dir) attribute. Replaces the existing value, if any.

Parameters:
dir - either "ltr" or "rtl"

getDir

public String getDir()
Gets the direction.

Returns:
String value of dir attribute or null if none set.

getStyle

public String getStyle()
Gets the style.

Returns:
String value of style attribute or null if none is set.

setStyle

public void setStyle(String style)
Sets the style attribute. Replaces an existing value, if any.

Parameters:
style - The style to set

appendStyle

public void appendStyle(String style)
Adds the specified style String to the current style value, separated with a semi-colon character. Sets the style if the current style is null.

Parameters:
style - the style value to set or append.

buildTag

public void buildTag(StringBuffer buffer)
Builds HTML output from the current state. The element is not closed. Used as a shared method between rendering to a String or rendering to a StringBuffer.

Parameters:
buffer - to modify

buildTag

public void buildTag(StringBuffer buffer,
                     boolean closeTag)
Builds HTML output from the current state. Used as a shared method between rendering to a String or rendering to a StringBuffer.

Parameters:
buffer -
closeTag - terminate the built tag with a "/>" instead of just a ">"

renderEndTag

public String renderEndTag()
Converts the closing tag for this HTMLElement to a string. Calls renderEndTag(StringBuffer).

Returns:
String

renderEndTag

public void renderEndTag(StringBuffer buffer)
Appends the closing tag for this HTMLElement to specified StringBuffer. Override this method to do nothing if no closing tag is required.

Parameters:
buffer -

setAttribute

public void setAttribute(String name,
                         String value)
Sets an named attribute on this HTMLElement. Use a null value to remove the attribute. Replaces the named attribute, if it already exists, with the new value. If this object was created to preserve attribute order, the attributes will be render in the order they were set. Replacing an attribute value will not change its rendering order. To move an attribute to the end of the rendering order, it must be removed with elem.setAttribute(name, null); and then set again.

Parameters:
name - attribute name
value - value for the named attribute

getAttribute

public String getAttribute(String name)
Gets the value of the specified attribute of this HTMLElement

Parameters:
name - name of the attribute, case sensitive
Returns:
String value, or null if no such attribute is set.

hasFlag

public boolean hasFlag(String flag)
Determines whether or not this HTMLElement has the named flag set

Parameters:
flag - flag name
Returns:
boolean

addFlag

public void addFlag(String flag)
Adds the named flag to this HTMLElement

Parameters:
flag - flag name

removeFlag

public void removeFlag(String flag)
Removes the named flag from this HTMLElement

Parameters:
flag - flag name

HATS 7.5.1 (201005110649)