org.mortbay.html

Class Element

public abstract class Element extends Object

HTML Element.

This abstract class is the base for all HTML Elements. The feature of an abstract HTML Element is that it can be added to HTML Pages, HTML Composites and several other HTML Elements derivations. Elements may also have attributes set, which are handled by the derived Element.

Version: $Id: Element.java,v 1.10 2005/08/13 00:01:23 gregwilkins Exp $

Author: Greg Wilkins

See Also: Page Composite

Field Summary
static StringALIGN
protected HashtableattributeMap
static StringBGCOLOR
static StringBOTTOM
static StringCENTER
static StringCLASS
static StringCOLOR
static StringHEIGHT
static StringID
static StringLEFT
static StringMIDDLE
static StringnoAttributes
static StringRIGHT
static StringSIZE
static StringSTYLE
static StringTOP
static StringVALIGN
static StringWIDTH
Constructor Summary
Element()
Default constructor.
Element(String attributes)
Construct with attributes.
Method Summary
Elementattribute(String attributes)
Add element Attributes.
Elementattribute(String attribute, Object value)
Add quoted element Attributes and value.
Elementattribute(String attribute, long value)
Add quoted element Attributes and value.
Stringattributes()
Elementattributes(String attributes)
Add element Attributes.
ElementbgColor(String color)
set BGCOLOR.
Elementbottom()
Bottom align.
Elementcenter()
Center.
Elementcolor(String color)
set color.
ElementcssClass(String c)
set CSS CLASS.
ElementcssID(String id)
set CSS ID.
Elementheight(int h)
set height.
Elementheight(String h)
set height.
intheight()
Elementleft()
left justify.
Elementmiddle()
Middle align.
Elementright()
right justify.
ElementsetAttributesFrom(Element e)
Set attributes from another Element.
Elementsize(int s)
set size.
Elementsize(String s)
set size.
intsize()
Elementstyle(String style)
set Style.
Elementtop()
Top align.
StringtoString()
Convert Element to String.
Elementwidth(int w)
set width.
Elementwidth(String w)
set width.
intwidth()
abstract voidwrite(Writer out)
Write element to a Writer.
voidwrite(OutputStream out)
Write Element to an OutputStream.
voidwrite(OutputStream out, String encoding)
Write Element to an OutputStream.

Field Detail

ALIGN

public static final String ALIGN

attributeMap

protected Hashtable attributeMap

BGCOLOR

public static final String BGCOLOR

BOTTOM

public static final String BOTTOM

CENTER

public static final String CENTER

CLASS

public static final String CLASS

COLOR

public static final String COLOR

HEIGHT

public static final String HEIGHT

ID

public static final String ID

LEFT

public static final String LEFT

MIDDLE

public static final String MIDDLE

noAttributes

public static final String noAttributes

RIGHT

public static final String RIGHT

SIZE

public static final String SIZE

STYLE

public static final String STYLE

TOP

public static final String TOP

VALIGN

public static final String VALIGN

WIDTH

public static final String WIDTH

Constructor Detail

Element

public Element()
Default constructor.

Element

public Element(String attributes)
Construct with attributes.

Parameters: attributes The initial attributes of the element

Method Detail

attribute

public Element attribute(String attributes)
Add element Attributes. The attributes are added to the Element attributes (separated with a space). The attributes are available to the derived class in the protected member String attributes

Parameters: attributes String of HTML attributes to add to the element. A null attribute clears the current attributes.

Returns: This Element so calls can be chained.

attribute

public Element attribute(String attribute, Object value)
Add quoted element Attributes and value.

Parameters: attribute String of HTML attribute tag value String value of the attribute to be quoted

Returns: This Element so calls can be chained.

attribute

public Element attribute(String attribute, long value)
Add quoted element Attributes and value.

Parameters: attribute String of HTML attribute tag value String value of the attribute to be quoted

Returns: This Element so calls can be chained.

attributes

public String attributes()

attributes

public Element attributes(String attributes)

Deprecated: Use attribute(String).

Add element Attributes. The attributes are added to the Element attributes (separated with a space). The attributes are available to the derived class in the protected member String attributes

Parameters: attributes String of HTML attributes to add to the element.

Returns: This Element so calls can be chained.

bgColor

public Element bgColor(String color)
set BGCOLOR. Convenience method equivalent to attribute("bgcolor",color). Not applicable to all Elements.

bottom

public Element bottom()
Bottom align. Convenience method equivalent to attribute("valign","bottom"). Not applicable to all Elements.

center

public Element center()
Center. Convenience method equivalent to attribute("align","center"). Not applicable to all Elements.

color

public Element color(String color)
set color. Convenience method equivalent to attribute("color",color). Not applicable to all Elements.

cssClass

public Element cssClass(String c)
set CSS CLASS.

cssID

public Element cssID(String id)
set CSS ID. Convenience method equivalent to attribute("id",id).

height

public Element height(int h)
set height. Convenience method equivalent to attribute("height",h). Not applicable to all Elements.

height

public Element height(String h)
set height. Convenience method equivalent to attribute("height",h). Not applicable to all Elements.

height

public int height()

left

public Element left()
left justify. Convenience method equivalent to attribute("align","left"). Not applicable to all Elements.

middle

public Element middle()
Middle align. Convenience method equivalent to attribute("valign","middle"). Not applicable to all Elements.

right

public Element right()
right justify. Convenience method equivalent to attribute("align","right"). Not applicable to all Elements.

setAttributesFrom

public Element setAttributesFrom(Element e)
Set attributes from another Element.

Parameters: e Element

Returns: This Element

size

public Element size(int s)
set size. Convenience method equivalent to attribute("size",s). Not applicable to all Elements.

size

public Element size(String s)
set size. Convenience method equivalent to attribute("size",s). Not applicable to all Elements.

size

public int size()

style

public Element style(String style)
set Style. Convenience method equivalent to attribute("style",style).

top

public Element top()
Top align. Convenience method equivalent to attribute("valign","top"). Not applicable to all Elements.

toString

public String toString()
Convert Element to String. Uses write() to convert the HTML Element to a string.

Returns: String of the HTML element

width

public Element width(int w)
set width. Convenience method equivalent to attribute("width",w). Not applicable to all Elements.

width

public Element width(String w)
set width. Convenience method equivalent to attribute("width",w). Not applicable to all Elements.

width

public int width()

write

public abstract void write(Writer out)
Write element to a Writer. This abstract method is called by the Page or other containing Element to write the HTML for this element. This must be implemented by the derived Element classes.

Parameters: out Writer to write the element to.

write

public void write(OutputStream out)
Write Element to an OutputStream. Calls print(Writer) and checks errors Elements that override this method should also override write(Writer) to avoid infinite recursion.

Parameters: out OutputStream to write the element to.

write

public void write(OutputStream out, String encoding)
Write Element to an OutputStream. Calls print(Writer) and checks errors Elements that override this method should also override write(Writer) to avoid infinite recursion.

Parameters: out OutputStream to write the element to.

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.