org.mortbay.html

Class Element

Known Direct Subclasses:
Composite, DefList, Include, Tag

public abstract class Element
extends java.lang.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 String
ALIGN
static String
BGCOLOR
static String
BOTTOM
static String
CENTER
static String
CLASS
static String
COLOR
static String
HEIGHT
static String
ID
static String
LEFT
static String
MIDDLE
static String
RIGHT
static String
SIZE
static String
STYLE
static String
TOP
static String
VALIGN
static String
WIDTH
protected Hashtable
attributeMap
static String
noAttributes

Constructor Summary

Element()
Default constructor.
Element(String attributes)
Construct with attributes.

Method Summary

Element
attribute(String attributes)
Add element Attributes.
Element
attribute(String attribute, Object value)
Add quoted element Attributes and value.
Element
attribute(String attribute, long value)
Add quoted element Attributes and value.
String
attributes()
Element
attributes(String attributes)
Deprecated. Use attribute(String).
Element
bgColor(String color)
set BGCOLOR.
Element
bottom()
Bottom align.
Element
center()
Center.
Element
color(String color)
set color.
Element
cssClass(String c)
set CSS CLASS.
Element
cssID(String id)
set CSS ID.
int
height()
Element
height(String h)
set height.
Element
height(int h)
set height.
Element
left()
left justify.
Element
middle()
Middle align.
Element
right()
right justify.
Element
setAttributesFrom(Element e)
Set attributes from another Element.
int
size()
Element
size(String s)
set size.
Element
size(int s)
set size.
Element
style(String style)
set Style.
String
toString()
Convert Element to String.
Element
top()
Top align.
int
width()
Element
width(String w)
set width.
Element
width(int w)
set width.
void
write(OutputStream out)
Write Element to an OutputStream.
void
write(OutputStream out, String encoding)
Write Element to an OutputStream.
abstract void
write(Writer out)
Write element to a Writer.

Field Details

ALIGN

public static final String ALIGN

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

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

attributeMap

protected Hashtable attributeMap

noAttributes

public static final String noAttributes

Constructor Details

Element

public Element()
Default constructor.

Element

public Element(String attributes)
Construct with attributes.
Parameters:
attributes - The initial attributes of the element

Method Details

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 int height()

height

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

height

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

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 int size()

size

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

size

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

style

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

toString

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

top

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

width

public int width()

width

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

width

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

write

public void write(OutputStream out)
            throws IOException
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)
            throws IOException
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 abstract void write(Writer out)
            throws IOException
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.

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