org.mortbay.html

Class Composite

public class Composite extends Element

HTML Composite Element.

This class is can be used a either an abstract or concrete holder of other HTML elements. Used directly, it allow multiple HTML Elements to be added which are produced sequentially. Derived used of Composite may wrap each contain Element in special purpose HTML tags (e.g. list).

Notes
Elements are added to the Composite either as HTML Elements or as Strings. Other objects added to the Composite are converted to Strings

Version: $Id: Composite.java,v 1.6 2004/05/09 20:31:28 gregwilkins Exp $

Author: Greg Wilkins

See Also: Element

Field Summary
protected ArrayListelements
The vector of elements in this Composite.
protected Compositenest
Constructor Summary
Composite()
Default constructor.
Composite(String attributes)
Default constructor.
Method Summary
Compositeadd(Object o)
Add an Object to the Composite by converting it to a Element or.
Stringcontents()
Contents of the composite.
Compositenest(Composite c)
Nest a Composite within a Composite.
booleanreplace(Object oldObj, Object newObj)
Replace an object within the composite.
Compositereset()
Empty the contents of this Composite .
CompositesetNest(Composite c)
Explicit set of the Nested component.
intsize()
The number of Elements in this Composite.
Compositeunnest()
Recursively unnest the composites.
voidwrite(Writer out)
Write the composite.

Field Detail

elements

protected ArrayList elements
The vector of elements in this Composite.

nest

protected Composite nest

Constructor Detail

Composite

public Composite()
Default constructor.

Composite

public Composite(String attributes)
Default constructor.

Method Detail

add

public Composite add(Object o)
Add an Object to the Composite by converting it to a Element or. String

Parameters: o The Object to add. If it is a String or Element, it is added directly, otherwise toString() is called.

Returns: This Composite (for chained commands)

contents

public String contents()
Contents of the composite.

nest

public Composite nest(Composite c)
Nest a Composite within a Composite. The passed Composite is added to this Composite. Adds to this composite are actually added to the nested Composite. Calls to nest are passed the nested Composite

Returns: The Composite to unest on to return to the original state.

replace

public boolean replace(Object oldObj, Object newObj)
Replace an object within the composite.

reset

public Composite reset()
Empty the contents of this Composite .

setNest

public Composite setNest(Composite c)
Explicit set of the Nested component. No add is performed. setNest() obeys any current nesting and sets the nesting of the nested component.

size

public int size()
The number of Elements in this Composite.

Returns: The number of elements in this Composite

unnest

public Composite unnest()
Recursively unnest the composites.

write

public void write(Writer out)
Write the composite. The default implementation writes the elements sequentially. May be overridden for more specialized behaviour.

Parameters: out Writer to write the element to.

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