net.sf.jolene.dom
Class HTMLElement

java.lang.Object
  extended by net.sf.jolene.dom.HTMLElement
All Implemented Interfaces:
java.lang.Cloneable, IAttributes, ICollection, IStyles
Direct Known Subclasses:
Button, CheckBox, Form, Grid, Header, Image, Input, Label, Radio, Select, Text, TextArea

public abstract class HTMLElement
extends java.lang.Object
implements IAttributes, IStyles, java.lang.Cloneable

Base class for all html elements.

Since:
Oct 11, 2003
Author:
Dan Howard

Method Summary
 void clear()
          Clears this element's attributes.
 HTMLElement clone()
          Core clone implementation.
 java.lang.String getAfterText()
          Gets the afterText string for the object.
 java.lang.String getAttribute(java.lang.String key)
          Return the html attribute specified by the key or null if it's not found.
 java.lang.String getBeforeText()
          Gets the beforeText string for the object.
 java.lang.String getContent()
          

Returns the content of the HTMLElement.

 java.lang.String getName()
          Gets the element name.
 java.lang.String getStyle(java.lang.String key)
          Get the element style based on a style name.
 Tags getTag()
          Get the tag for the element.
 java.lang.String getValue()
          Gets the current value of the element.
 boolean hasAttribute(java.lang.String key)
          Indicates if the specified attribute exists.
 boolean hasStyle(java.lang.String key)
          Indicates if a style exists.
 boolean isChecked()
          Returns true if a Radio or CheckBox is checked.
 boolean isDisabled()
          Returns true if the element is disabled
 boolean isReadonly()
          Returns true if the element is readonly
 boolean isRenderable()
          Returns whether this element is rendered.
 java.util.Set<java.lang.String> keySet()
          Returns the set of attribute names.
 java.lang.String removeAttribute(java.lang.String key)
          Remove the specified attribute.
 java.lang.String removeStyle(java.lang.String key)
          Removes a style from the element.
 void resetStyles(java.lang.String style)
          Sets the styles on the element based on the formatted style string, clearing all exisiting styles first.
 void resetStyles(Styles style)
          Sets the styles on the element based on the Style parameter, clearing all exisiting styles first.
 void setAfterText(java.lang.String string)
          Sets the afterText string for the object.
 java.lang.String setAttribute(java.lang.String key, java.lang.String value)
          Sets the specified attribute.
 void setBeforeText(java.lang.String string)
          Sets the beforeText string for the object.
 void setChecked(boolean checked)
          Sets the element checked attribute.
 void setContent(java.lang.String content)
          Sets the content of the HTMLElement.
 void setDisabled(boolean disabled)
          Set the element to be disabled.
 void setName(java.lang.String name)
          Set the element name.
 void setReadonly(boolean readonly)
          Set the element to be readonly.
 void setRenderable(boolean renderable)
          Sets whether this element is rendered.
 java.lang.String setStyle(java.lang.String key, java.lang.String value)
          Set the element style.
 void setStyles(java.lang.String style)
          Sets the styles on the element based on a formatted style string.
 void setStyles(Styles styles)
          Sets styles on the Style object based on the Style parameter.
 void setValue(java.lang.String value)
          Sets the value of the element.
 void swapWith(java.lang.String swapWith)
          Replace this element's string representation with the specified string.
 java.lang.String toString()
          Renders the element as an html string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

clear

public void clear()
Clears this element's attributes.

Specified by:
clear in interface ICollection

clone

public HTMLElement clone()
Core clone implementation. Safely clones HTMLElement objects. Used by the DocumentFactory.

Overrides:
clone in class java.lang.Object
Returns:
HTMLElement
See Also:
DocumentFactory

getAfterText

public java.lang.String getAfterText()
Gets the afterText string for the object. The afterText is any string value that you want to be rendered immediatley after the object itself.

Returns:
String

getAttribute

public final java.lang.String getAttribute(java.lang.String key)
Return the html attribute specified by the key or null if it's not found.

Specified by:
getAttribute in interface IAttributes
Parameters:
key - case insensitive attribute name.
Returns:
attribute value string.

getBeforeText

public java.lang.String getBeforeText()
Gets the beforeText string for the object. The beforeText is any string value that you want to be rendered immediatley before the object itself.

Returns:
String

getContent

public java.lang.String getContent()

Returns the content of the HTMLElement. The content is part of the element between the end of the start tag and the beginning of the end tag. In the example below Button text is the content.

<button name="test">Button text</button>

Note that some elements do not have content. For these elements this content property has no effect on the rendering of the element.

Elements which have a content.


Elements which do NOT have a content.

Note also that for TextArea, Text and Label the content is also the value. In this case the value and content properties are interchangable.

Returns:
String content part of the HTMLElement

getName

public java.lang.String getName()
Gets the element name.

Returns:
name of the html element.

getStyle

public java.lang.String getStyle(java.lang.String key)
Get the element style based on a style name.

Specified by:
getStyle in interface IStyles
Parameters:
key - case insensitive style name.
Returns:
String value for the specified style or null if not found.

getTag

public Tags getTag()
Get the tag for the element.

Returns:
the tag for the element.

getValue

public java.lang.String getValue()
Gets the current value of the element.

Returns:
String

hasAttribute

public boolean hasAttribute(java.lang.String key)
Indicates if the specified attribute exists.

Specified by:
hasAttribute in interface IAttributes
Parameters:
key - case insensitive attribute name.
Returns:
true if the attribute exists.

hasStyle

public boolean hasStyle(java.lang.String key)
Indicates if a style exists.

Specified by:
hasStyle in interface IStyles
Parameters:
key - case instensitive style key name.
Returns:
true if the style exists in the string.

isChecked

public boolean isChecked()
Returns true if a Radio or CheckBox is checked.

Returns:
checked

isDisabled

public boolean isDisabled()
Returns true if the element is disabled

Returns:
disabled

isReadonly

public boolean isReadonly()
Returns true if the element is readonly

Returns:
readonly

isRenderable

public boolean isRenderable()
Returns whether this element is rendered. If this is false then the element will be rendered as an empty string.

Returns:
boolean

keySet

public java.util.Set<java.lang.String> keySet()
Returns the set of attribute names.

Specified by:
keySet in interface ICollection
Returns:
set of attribute names.

removeAttribute

public java.lang.String removeAttribute(java.lang.String key)
Remove the specified attribute.

Specified by:
removeAttribute in interface IAttributes
Parameters:
key - case insensitive attribute name.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

removeStyle

public java.lang.String removeStyle(java.lang.String key)
Removes a style from the element.

Specified by:
removeStyle in interface IStyles
Parameters:
key - Style key name to remove.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

resetStyles

public final void resetStyles(java.lang.String style)
Sets the styles on the element based on the formatted style string, clearing all exisiting styles first.

Specified by:
resetStyles in interface IStyles
Parameters:
style - string in a format like azimuth:behind;background:aliceblue;background-color:aquamarine;border-bottom-style:solid;clip:auto;border-top-width:medium;

resetStyles

public final void resetStyles(Styles style)
Sets the styles on the element based on the Style parameter, clearing all exisiting styles first.

Parameters:
style - a Style object.

setAfterText

public void setAfterText(java.lang.String string)
Sets the afterText string for the object. The afterText is any string value that you want to be rendered immediately after the object itself.

Example:

 document.forms(0).elements("Submit").setAfterText(" Click this button to submit this form.");
 
This would render the following back to the browser:
 <input type="SUBMIT" name="Submit" value="Submit"> Click this button to submit this form.
 

Parameters:
string - text after object

setAttribute

public final java.lang.String setAttribute(java.lang.String key,
                                           java.lang.String value)
Sets the specified attribute.

Specified by:
setAttribute in interface IAttributes
Parameters:
key - case insensitive attribute name.
value - value of the attribute.
Returns:
previous value associated with specified key, or null if there was no attribute for the key.

setBeforeText

public void setBeforeText(java.lang.String string)
Sets the beforeText string for the object. The beforeText is any string value that you want to be rendered immediatley before the object itself.

Example:

 document.forms(0).elements("Name").setBeforeText("Name: ");
 
This would render the following back to the browser:
 Name: <input type="text" name="Name">
 

Parameters:
string - of text

setChecked

public void setChecked(boolean checked)
Sets the element checked attribute. Used for Radios and Checkboxes.

Parameters:
checked - to indicate if the checkbox is checked or not.

setContent

public void setContent(java.lang.String content)
Sets the content of the HTMLElement.

Parameters:
content - text or value to set.
See Also:
getContent()

setDisabled

public void setDisabled(boolean disabled)
Set the element to be disabled.

Parameters:
disabled - indicator for a disabled element.

setName

public void setName(java.lang.String name)
Set the element name.

Parameters:
name - name of the html element.

setReadonly

public void setReadonly(boolean readonly)
Set the element to be readonly.

Parameters:
readonly - indicator for a readonly element.

setRenderable

public void setRenderable(boolean renderable)
Sets whether this element is rendered. If this is false then the element will be rendered as an empty string.

Parameters:
renderable - true or false

setStyle

public java.lang.String setStyle(java.lang.String key,
                                 java.lang.String value)
Set the element style.

Specified by:
setStyle in interface IStyles
Parameters:
key - Style key name.
value - Style value.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

setStyles

public final void setStyles(java.lang.String style)
Sets the styles on the element based on a formatted style string. Expects the string to be in style format.

Specified by:
setStyles in interface IStyles
Parameters:
style - string in a format like azimuth:behind;background:aliceblue;background-color:aquamarine;border-bottom-style:solid;clip:auto;border-top-width:medium;

setStyles

public final void setStyles(Styles styles)
Sets styles on the Style object based on the Style parameter.

Parameters:
styles - a Style object.

setValue

public void setValue(java.lang.String value)
Sets the value of the element.

Parameters:
value - value of object

swapWith

public void swapWith(java.lang.String swapWith)
Replace this element's string representation with the specified string.

Parameters:
swapWith - any string you wish to render instead of this object.

toString

public java.lang.String toString()
Renders the element as an html string.

Overrides:
toString in class java.lang.Object