edu.nrao.sss.html
Class HtmlElement

java.lang.Object
  extended by edu.nrao.sss.html.HtmlElement
Direct Known Subclasses:
HtmlAnchor, HtmlTable, HtmlTableCell, HtmlTableRow

public abstract class HtmlElement
extends Object

Parent to other HTML elements.

Version Info:

$Revision: 501 $
$Date: 2007-04-04 09:13:28 -0600 (Wed, 04 Apr 2007) $
$Author: dharland $

Since:
2007-03-16
Author:
David M. Harland

Field Summary
static String NBSP_HTML
          HTML representation of a non-breaking space.
static String NBSP_TEXT
          Plain text representation of NBSP_HTML.
static String NBSP_UNICODE
          The unicode text into which java's HTML parsers convert NBSP_HTML.
 
Method Summary
 HtmlAttribute addAttribute(HtmlAttribute newAttribute)
          Adds newAttribute to this element.
protected  void copyAttributesOf(HtmlElement other)
          Copies the attributes of the other element into this one.
 HtmlAttribute getAttribute(HTML.Attribute attributeType)
          Returns the attribute of the given type held by this element, if any.
 Collection<HtmlAttribute> getAttributes()
          Returns the attributes of this element.
 String getAttributeValue(HTML.Attribute attributeType)
          Returns the value of the given attribute, or the empty string ("") if this element has no such attribute.
 HTML.Tag getTag()
          Returns the HTML tag for this element.
abstract  boolean isSimple()
          Returns true if this is a simple element.
 int removeAllAttributes()
          Removes all attributes from this element.
 HtmlAttribute removeAttribute(HTML.Attribute unwantedType)
          Removes from this element its attribute of the given type.
 void writeHtmlTo(Writer device, int padding, boolean newLine)
          Writes this element to the given device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NBSP_HTML

public static final String NBSP_HTML
HTML representation of a non-breaking space.

See Also:
Constant Field Values

NBSP_UNICODE

public static final String NBSP_UNICODE
The unicode text into which java's HTML parsers convert NBSP_HTML. When writing HTML elements to HTML text, this is the value used for a non-breaking space. This representation is ASCII 0xA0, or unicode 00A0.

See Also:
Constant Field Values

NBSP_TEXT

public static final String NBSP_TEXT
Plain text representation of NBSP_HTML. When writing HTML elements to plain (non-HTML) text, this is the value used for a non-breaking space. This representation is the normal space character, ASCII 32 (0x20).

See Also:
Constant Field Values
Method Detail

getTag

public HTML.Tag getTag()
Returns the HTML tag for this element.

Returns:
the HTML tag for this element.

isSimple

public abstract boolean isSimple()
Returns true if this is a simple element. A simple element is one that may not have content, such as the line break (<br/>) element.

Returns:
true if this is a simple element.

addAttribute

public HtmlAttribute addAttribute(HtmlAttribute newAttribute)
Adds newAttribute to this element. If this element currently holds an attribute of the same type as newAttribute, it is replaced by newAttribute.

Parameters:
newAttribute - a new attribute for this element. If this value is null this method does nothing.
Returns:
an attribute of the same type as newAttribute, or null if this element had no attribute of that type.

removeAttribute

public HtmlAttribute removeAttribute(HTML.Attribute unwantedType)
Removes from this element its attribute of the given type.

Parameters:
unwantedType - the type of attribute to remove from this element.
Returns:
the attribute of the given type held by this element, or null if it held no such attribute.

removeAllAttributes

public int removeAllAttributes()
Removes all attributes from this element.

Returns:
the number of attributes of this element prior to their removal.

getAttribute

public HtmlAttribute getAttribute(HTML.Attribute attributeType)
Returns the attribute of the given type held by this element, if any. If this element holds no such element, null is returned.

Parameters:
attributeType - the type of attribute desired.
Returns:
the attribute of the given type held by this element, if any. If this element holds no such element, null is returned.

getAttributes

public Collection<HtmlAttribute> getAttributes()
Returns the attributes of this element.

The returned collection is not held by this element, so any changes made to it will be not reflected in this object. The attributes in the collection, however, are those held by this element.

Returns:
the attributes of this element. The collection is guaranteed to be non-null, but could be empty.

getAttributeValue

public String getAttributeValue(HTML.Attribute attributeType)
Returns the value of the given attribute, or the empty string ("") if this element has no such attribute.

Parameters:
attributeType - the name of an attribute of this element for which a value is sought.
Returns:
the value of the given attribute.

copyAttributesOf

protected void copyAttributesOf(HtmlElement other)
Copies the attributes of the other element into this one.

Parameters:
other - a provider of HTML attributes.

writeHtmlTo

public void writeHtmlTo(Writer device,
                        int padding,
                        boolean newLine)
                 throws IOException
Writes this element to the given device.

Parameters:
device - the destination of the HTML.
padding - the number of spaces to write before writing this element.
newLine - if this value is true, a new-line character is written after this element.
Throws:
IOException - if anything goes wrong while writing.


Copyright © 2009. All Rights Reserved.