NextApp Echo
App Container 1.0.5

nextapp.echoservlet.html
Class Element

java.lang.Object
  extended bynextapp.echoservlet.html.Element
All Implemented Interfaces:
Renderable, java.io.Serializable
Direct Known Subclasses:
ScriptElement, StyleElement, TriCellTable

public class Element
extends java.lang.Object
implements Renderable, java.io.Serializable

A representation of an HTML element designed to reside in a hierarchy of elements (an HTML document) and be rendered with good performance.

See Also:
Serialized Form

Field Summary
private  java.util.Map attributes
           
private  boolean closingTagRequired
           
private  ElementContent contents
           
private  java.lang.String name
           
private  boolean sticky
           
private  boolean whitespaceRelevant
           
 
Fields inherited from interface nextapp.echoservlet.html.Renderable
INDENT_STRING
 
Constructor Summary
Element(java.lang.String name)
          Creates a new Element of the specified name with a required closing tag.
Element(java.lang.String name, boolean closingTagRequired)
          Creates a new Element of the specified name and closing tag requirement.
 
Method Summary
 void add(int index, Renderable child)
          Adds a renderable object to the element at a specified index.
 void add(Renderable child)
          Adds a renderable object to the element.
 void addAttribute(java.lang.String attr)
          Adds a null attribute to the element.
 void addAttribute(java.lang.String attr, int value)
          Adds an integer attribute to the element.
 void addAttribute(java.lang.String attr, java.lang.String value)
          Adds the a text attribute to the element.
 void addElement(Element child)
          Deprecated. The add() method with the equivalent signature should now be used.
 void addElement(int index, Element child)
          Deprecated. The add() method with the equivalent signature should now be used.
 void addElementContent(ElementContent content)
          Deprecated. The add() method with the equivalent signature should now be used.
 void addElementContent(int index, ElementContent content)
          Deprecated. The add() method with the equivalent signature should now be used.
 void addHtml(int index, java.lang.String html)
          Adds raw HTML to the body of the element at a specified index.
 void addHtml(java.lang.String html)
          Adds raw HTML to the body of the element.
 void addText(int index, java.lang.String text, boolean encodeNewLines)
          Adds plain text to the body of the element at a specified index.
 void addText(java.lang.String text)
          Adds plain text to the body of the element.
 void addText(java.lang.String text, boolean encodeNewLines)
          Adds plain text to the body of the element.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the given attribute.
 java.lang.String getName()
          Returns the name of the element.
 int indexOf(java.lang.Object child)
          Returns the index of the specified object if it is a child of this Element.
 boolean isSticky()
          Determines whether the elment is "sticky" Sticky elements will be rendered immediately after and adjacent to the previous element (without whitespace).
 void render(java.io.PrintWriter pw)
          Renders this element and its children to a PrintWriter.
 void render(java.io.PrintWriter pw, int depth, boolean parentWhitespaceRelevant)
          Renders this element and its children to a PrintWriter.
 void setClosingTagRequired(boolean closingTagRequired)
          Sets whether the element requires an explicit closing tag.
 void setSticky(boolean sticky)
          Sets whether the element is "sticky" Sticky elements will be rendered immediately after and adjacent to the previous element (without whitespace).
 void setWhitespaceRelevant(boolean whitespaceRelevant)
          Sets whether the rendering of this element is adversely effected by white space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name

attributes

private java.util.Map attributes

contents

private ElementContent contents

whitespaceRelevant

private boolean whitespaceRelevant

sticky

private boolean sticky

closingTagRequired

private boolean closingTagRequired
Constructor Detail

Element

public Element(java.lang.String name)
Creates a new Element of the specified name with a required closing tag.

Parameters:
name - The name of the element.

Element

public Element(java.lang.String name,
               boolean closingTagRequired)
Creates a new Element of the specified name and closing tag requirement.

Parameters:
name - The name of the element.
closingTagRequired - Specifies whether a closing tag should be applied if no child elements or content is added to the element.
Method Detail

add

public void add(Renderable child)
Adds a renderable object to the element.

Parameters:
child - The renderable object to add to the element.

add

public void add(int index,
                Renderable child)
Adds a renderable object to the element at a specified index.

Parameters:
index - The index at which to add the renderable.
child - The renderable object to add to the element.

addAttribute

public void addAttribute(java.lang.String attr)
Adds a null attribute to the element.

Parameters:
attr - The name of the attribute.

addAttribute

public void addAttribute(java.lang.String attr,
                         int value)
Adds an integer attribute to the element.

Parameters:
attr - The name of the attribute.
value - The value of the attribute.

addAttribute

public void addAttribute(java.lang.String attr,
                         java.lang.String value)
Adds the a text attribute to the element.

Parameters:
attr - The name of the attribute.
value - The value of the attribute.

addElement

public void addElement(Element child)
Deprecated. The add() method with the equivalent signature should now be used.

Adds a child element to the element.

Parameters:
child - The child element to add to the element.

addElement

public void addElement(int index,
                       Element child)
Deprecated. The add() method with the equivalent signature should now be used.

Adds a child element to the element at a specified index.

Parameters:
index - The index at which to add the child element.
child - The child element to add to the element.

addElementContent

public void addElementContent(ElementContent content)
Deprecated. The add() method with the equivalent signature should now be used.

Adds content from an ElementContent object to this element.

Parameters:
content - The content to add.

addElementContent

public void addElementContent(int index,
                              ElementContent content)
Deprecated. The add() method with the equivalent signature should now be used.

Adds content from an ElementContent object to this element at a specified index.

Parameters:
index - The index at which to add the element content.
content - The content to add.

addHtml

public void addHtml(java.lang.String html)
Adds raw HTML to the body of the element. The given HTML string will not be encoded.

Parameters:
html - Encoded HTML content to be added to this element.

addHtml

public void addHtml(int index,
                    java.lang.String html)
Adds raw HTML to the body of the element at a specified index. The given HTML string will not be encoded.

Parameters:
index - The index at which to add the HTML.
html - Encoded HTML content to be added to this element.

addText

public void addText(java.lang.String text)
Adds plain text to the body of the element. This text will automatically be encoded into valid HTML.


addText

public void addText(java.lang.String text,
                    boolean encodeNewLines)
Adds plain text to the body of the element. This text will automatically be encoded into valid HTML.

Parameters:
text - Unencoded text to be added as HTML to the body of the element.
encodeNewLines - A flag indicating if new line characters should be translated to <BR>s.

addText

public void addText(int index,
                    java.lang.String text,
                    boolean encodeNewLines)
Adds plain text to the body of the element at a specified index. This text will automatically be encoded into valid HTML.

Parameters:
index - The index at which to add the text.
text - Unencoded text to be added as HTML to the body of the element.
encodeNewLines - A flag indicating if new line characters should be translated to <BR>s.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of the given attribute.

Parameters:
name - The name of the attribute.
Returns:
The attribute value.

getName

public java.lang.String getName()
Returns the name of the element.

Returns:
The name of the element.

indexOf

public int indexOf(java.lang.Object child)
Returns the index of the specified object if it is a child of this Element. If the object is not found, -1 is returned.

Parameters:
child - The child object whose index is desired.
Returns:
The index of the specified object.

isSticky

public boolean isSticky()
Determines whether the elment is "sticky" Sticky elements will be rendered immediately after and adjacent to the previous element (without whitespace).

Returns:
True if the element is sticky.

render

public void render(java.io.PrintWriter pw)
Renders this element and its children to a PrintWriter.

Parameters:
pw - The print writer to render the element to.

render

public void render(java.io.PrintWriter pw,
                   int depth,
                   boolean parentWhitespaceRelevant)
Renders this element and its children to a PrintWriter. The element will be indented to the specified depth, and its children will be indented to the specified depth + 1. If white space is relevant (whitespaceRelevant==true), then no white space will be left between this element's opening and closing tags.

Specified by:
render in interface Renderable
Parameters:
pw - The print writer to render the element to.
depth - The indentation depth to indent the element to.
parentWhitespaceRelevant - A flag indicating whether the parent element had the WhitespaceRelevant property set.

setClosingTagRequired

public void setClosingTagRequired(boolean closingTagRequired)
Sets whether the element requires an explicit closing tag. An element will always be explicitly closed if it has child elements.

Parameters:
closingTagRequired - True if the tag should be explicitly closed event if it has no child elements. False if the tag should be explicitly closed only when it has child elements.

setSticky

public void setSticky(boolean sticky)
Sets whether the element is "sticky" Sticky elements will be rendered immediately after and adjacent to the previous element (without whitespace).

Parameters:
sticky - True if the element should be sticky.

setWhitespaceRelevant

public void setWhitespaceRelevant(boolean whitespaceRelevant)
Sets whether the rendering of this element is adversely effected by white space. If this flag is set, child elements will be rendered immediately adjacent to the opening and closing tags of this element, with no whitespace in between. If white space is not relevant, this flag should be left in its default false state as the document will be more human-readable.

Parameters:
whitespaceRelevant - True if this tag is sensitive to whitespace inside it.

NextApp Echo
App Container 1.0.5