objectivehtml.htmlwidget
Class HtmlElement

java.lang.Object
  |
  +--objectivehtml.oms.OMSObject
        |
        +--objectivehtml.htmlwidget.HtmlElement
Direct Known Subclasses:
HtmlOptionItem, HtmlTableCaption, HtmlWidget

public abstract class HtmlElement
extends OMSObject

This abstract class is represents a html element and is the base class of all the html widgets in this library.

The class holds the start and eng tag for html element it represents. All attribute values for the html element are also contained in this class.

The class also allows you to change the quote type for this element. The quote type is used when the element is written to the output stream. All attribute values are quoted using the quote type. The default quote type is the double quote character ".

All classes that extend this class must implement the printHtml methods.

See Also:
setQuoteType(String), printHtml(JspWriter), printHtml(PrintWriter)

Field Summary
protected  java.util.HashMap m_hmAttributes
          The internal hash-map of (attribute, value) pairs for this element
protected  java.lang.String m_sEndTag
          The end tag of this element
protected  java.lang.String m_sQuoteType
          The quote type for this element
protected  java.lang.String m_sStartTag
          The start tag of this element
 
Constructor Summary
HtmlElement()
          Constructs an instance of the HtmlElement object.
 
Method Summary
protected  java.lang.String genEndTag(int nOutputType)
          Generates the end tag.
protected  java.lang.String genStartTag(int nOutputType)
          Generates the start tag with all the attribute values that have been set for this object.
protected  java.lang.String genStartTag(int nOutputType, java.lang.String sAttributeToBeEscaped, boolean bEscaped)
          Generates the start tag with all the attribute values that have been set for this object.
 java.lang.String getAttribute(java.lang.String sName)
          Returns the value of the specified attribute, the name is case-insensitive.
 java.util.HashMap getAttributes()
          Returns all the attributes of this element in a HashMap object.
 boolean getBooleanAttribute(java.lang.String sName)
          Returns the value of the specified boolean-attribute, the name is case-insensitive.
 java.lang.String getQuoteType()
          Returns the quote type.
 void printHtml(javax.servlet.jsp.JspWriter objWriter)
           This overloaded version is simply a wrapper for the other version of this method.
abstract  void printHtml(javax.servlet.jsp.JspWriter objWriter, int nOutputType)
          This virtual method must be implemented by all children classes.
protected  void printHtml(javax.servlet.jsp.JspWriter objWriter, int nOutputType, java.util.Collection clChildElements)
          Prints the html that represents this object to the output stream.
protected  void printHtml(javax.servlet.jsp.JspWriter objWriter, int nOutputType, java.lang.String sText, boolean bEscapeText)
          Prints the html that represents this object to the output stream.
 void printHtml(java.io.PrintWriter objWriter)
           This overloaded version is simply a wrapper for the other version of this method.
abstract  void printHtml(java.io.PrintWriter objWriter, int nOutputType)
          This virtual method must be implemented by all children classes.
protected  void printHtml(java.io.PrintWriter objWriter, int nOutputType, java.util.Collection clChildElements)
          Prints the html that represents this object to the output stream.
protected  void printHtml(java.io.PrintWriter objWriter, int nOutputType, java.lang.String sText, boolean bEscapeText)
          Prints the html that represents this object to the output stream.
 void setAttribute(java.lang.String sName, java.lang.String sValue)
          Sets a html attribute for this object.
 void setBooleanAttribute(java.lang.String sName, boolean bIsOn)
          Sets a html boolean-attribute for this object.
 void setQuoteType(java.lang.String sQuoteType)
          Sets the quote type.
 java.lang.String toString()
          Writes a string representing this element in html format.
 java.lang.String toString(int nOutputType)
          Writes a string representing this element.
 
Methods inherited from class objectivehtml.oms.OMSObject
compareClasses, connect, disconnect, emit, isAlive, setAlive, signal, slot, slot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_sStartTag

protected java.lang.String m_sStartTag
The start tag of this element

m_sEndTag

protected java.lang.String m_sEndTag
The end tag of this element

m_hmAttributes

protected java.util.HashMap m_hmAttributes
The internal hash-map of (attribute, value) pairs for this element

m_sQuoteType

protected java.lang.String m_sQuoteType
The quote type for this element
Constructor Detail

HtmlElement

public HtmlElement()
Constructs an instance of the HtmlElement object.
Method Detail

setQuoteType

public void setQuoteType(java.lang.String sQuoteType)
                  throws InvalidQuoteTypeException

Sets the quote type. The only valid quote types allowed are ", ' or a null string.

The default quote type is ". If the html-type is xhtml then this setting is ignored, for xhtml the quote type is always the double quote character.

Parameters:
sQuoteType - the new quote type
Throws:
InvalidQuoteTypeException - if the quote type specified is not allowed
See Also:
getQuoteType()

getQuoteType

public java.lang.String getQuoteType()
Returns the quote type.
Returns:
the quote type for this object
See Also:
setQuoteType(String)

genStartTag

protected java.lang.String genStartTag(int nOutputType)

Generates the start tag with all the attribute values that have been set for this object. The output generated will depend on the output-type specified. The output-types currently supported are listed in the OutputType class.

This overloaded version is simply a wrapper for the other version of this method. i.e.

 		genStartTag(nOutputType, null, false);
 
Parameters:
nOutputType - the output type
Returns:
the start tag with all the attribute values
See Also:
genStartTag(int, String, boolean), OutputType, genEndTag(int), printHtml(JspWriter), printHtml(PrintWriter)

genStartTag

protected java.lang.String genStartTag(int nOutputType,
                                       java.lang.String sAttributeToBeEscaped,
                                       boolean bEscaped)

Generates the start tag with all the attribute values that have been set for this object. The output generated will depend on the output-type specified. The output-types currently supported are listed in the OutputType class.

This overloaded version can escape the characters of an attribute given by sAttributeToBeEscaped. The value of this attribute is escaped with the htmlSpecialChars() method.

This method is used internally by the printHtml methods to generate the output strings.

Parameters:
nOutputType - the output type
sAttributeToBeEscaped - the attribute to be escaped
bEscaped - true if the attribute should be escaped, false otherwise
Returns:
the start tag with all the attribute values
See Also:
OutputType, HtmlUtils.htmlSpecialChars(String), genEndTag(int), printHtml(JspWriter), printHtml(PrintWriter)

genEndTag

protected java.lang.String genEndTag(int nOutputType)

Generates the end tag. Not all HtmlElement objects need to have an end tag.

This method is used internally by the printHtml methods to generate the output strings.

Parameters:
nOutputType - the output type
Returns:
the end tag
See Also:
genStartTag(int), printHtml(JspWriter), printHtml(PrintWriter)

setAttribute

public void setAttribute(java.lang.String sName,
                         java.lang.String sValue)
                  throws InvalidAttributeException

Sets a html attribute for this object. The name of the attribute is case-insensitive.

Setting an attribute with this method and calling a wrapper method will result in the same effect on the object. e.g. Calling setAttribute("value", "Some text."), is the same as calling setValue("Some text.").

To clear the attribute specify the null reference for the value. If you specify an empty string, the attribute is still written out by printHtml methods but with a blank value. If the attribute is cleared the attribute is not written out at all.

Parameters:
sName - the name of the attribute
sValue - the value of the attribute, if null is specified then the attribute will be cleared
Throws:
InvalidAttributeException - if the name is not valid
See Also:
getAttribute(String), setBooleanAttribute(String, boolean)

setBooleanAttribute

public void setBooleanAttribute(java.lang.String sName,
                                boolean bIsOn)
                         throws InvalidAttributeException

Sets a html boolean-attribute for this object. The name of the attribute is case-insensitive.

Setting a boolean-attribute with this method and calling a wrapper method will result in the same effect on the object. e.g. Calling setBooleanAttribute("disabled", true), is the same as calling setDisabled(true).

Parameters:
sName - the name of the attribute
bIsOn - true if attribute should be set, if false is specified then the attribute is cleared
Throws:
InvalidAttributeException - if the name is not valid
See Also:
getBooleanAttribute(String), setAttribute(String, String)

getAttributes

public java.util.HashMap getAttributes()
Returns all the attributes of this element in a HashMap object. The key is the attribute name which maps to the attribute value. The HashMap object returned is a shallow copy and can be safely modified.
Returns:
a HashMap object of all the attributes

getAttribute

public java.lang.String getAttribute(java.lang.String sName)
Returns the value of the specified attribute, the name is case-insensitive.
Returns:
the value of the attribute, null if the attribute is not set or if its a boolean-attribute
See Also:
setAttribute(String, String), getBooleanAttribute(String)

getBooleanAttribute

public boolean getBooleanAttribute(java.lang.String sName)
Returns the value of the specified boolean-attribute, the name is case-insensitive.
Returns:
true if the attribute is set, false otherwise null if the attribute is not set
See Also:
setBooleanAttribute(String, boolean), getAttribute(String)

printHtml

public void printHtml(java.io.PrintWriter objWriter)
               throws java.io.IOException

This overloaded version is simply a wrapper for the other version of this method. i.e.

 		printHtml(objWriter, OutputType.HTML);
 

This version should be used by servlets.

Parameters:
objWriter - the output stream for a servlet object
Throws:
java.io.IOException - if it cannot write the output
See Also:
OutputType, printHtml(JspWriter)

printHtml

public abstract void printHtml(java.io.PrintWriter objWriter,
                               int nOutputType)
                        throws java.io.IOException

This virtual method must be implemented by all children classes. The method prints out the contents of itself in the specified output-type onto the output stream.

The output generated will depend on the output-type specified. The output-types currently supported are listed in the OutputType class.

This version should be used by servlets.

Parameters:
objWriter - the output stream for a servlet object
nOutputType - the output type
Throws:
java.io.IOException - if it cannot write the output
See Also:
OutputType, printHtml(JspWriter)

printHtml

public void printHtml(javax.servlet.jsp.JspWriter objWriter)
               throws java.io.IOException

This overloaded version is simply a wrapper for the other version of this method. i.e.

 		printHtml(objWriter, OutputType.HTML);
 

This version should be used by Jsp pages.

Parameters:
objWriter - the output stream for a servlet object
Throws:
java.io.IOException - if it cannot write the output
See Also:
OutputType, printHtml(JspWriter)

printHtml

public abstract void printHtml(javax.servlet.jsp.JspWriter objWriter,
                               int nOutputType)
                        throws java.io.IOException

This virtual method must be implemented by all children classes. The method prints out the contents of itself in the specified output-type onto the output stream.

The output generated will depend on the output-type specified. The output-types currently supported are listed in the OutputType class.

This version should be used by jsp pages.

Parameters:
objWriter - the output stream for a jsp object
nOutputType - the output type
Throws:
java.io.IOException - if it cannot write the output
See Also:
OutputType, printHtml(PrintWriter)

printHtml

protected void printHtml(java.io.PrintWriter objWriter,
                         int nOutputType,
                         java.lang.String sText,
                         boolean bEscapeText)
                  throws java.io.IOException

Prints the html that represents this object to the output stream.

This is a helper version of printHtml. Should only be used by other classes in this toolkit.

Parameters:
objWriter - the output stream for a Servlet object
nOutputType - the output type
sText - the text between the start and end tag
bEscapeText - indicates if the text is to be escaped
Throws:
java.io.IOException - if it cannot write the output

printHtml

protected void printHtml(javax.servlet.jsp.JspWriter objWriter,
                         int nOutputType,
                         java.lang.String sText,
                         boolean bEscapeText)
                  throws java.io.IOException

Prints the html that represents this object to the output stream.

This is a helper version of printHtml. Should only be used by other classes in this toolkit.

Parameters:
objWriter - the output stream for a Jsp page
nOutputType - the output type
sText - the text between the start and end tag
bEscapeText - indicates if the text is to be escaped
Throws:
java.io.IOException - if it cannot write the output

printHtml

protected void printHtml(java.io.PrintWriter objWriter,
                         int nOutputType,
                         java.util.Collection clChildElements)
                  throws java.io.IOException

Prints the html that represents this object to the output stream.

This is a helper version of printHtml. Should only be used by other classes in this toolkit.

Parameters:
objWriter - the output stream for a Servlet object
nOutputType - the output type
clChildElements - a collection of children widgets
Throws:
java.io.IOException - if it cannot write the output

printHtml

protected void printHtml(javax.servlet.jsp.JspWriter objWriter,
                         int nOutputType,
                         java.util.Collection clChildElements)
                  throws java.io.IOException

Prints the html that represents this object to the output stream.

This is a helper version of printHtml. Should only be used by other classes in this toolkit.

Parameters:
objWriter - the output stream for a Jsp page
nOutputType - the output type
clChildElements - a collection of children widgets
Throws:
java.io.IOException - if it cannot write the output

toString

public java.lang.String toString(int nOutputType)
Writes a string representing this element.
Parameters:
nOutputType - the output type
Returns:
a string representing this element

toString

public java.lang.String toString()
Writes a string representing this element in html format.
Overrides:
toString in class java.lang.Object
Returns:
a string representing this element in html