org.apache.tapestry.dom
Class Element

java.lang.Object
  extended by org.apache.tapestry.dom.Node
      extended by org.apache.tapestry.dom.Element

public final class Element
extends Node

An element that will render with a begin tag and attributes, a body, and an end tag. Also acts as a factory for enclosed Element, Text and Comment nodes.

TODO: Support for CDATA nodes. Do we need Entity nodes?


Method Summary
 Element addClassName(String... className)
          Adds one or more CSS class names to the "class" attribute.
 void attribute(String name, String value)
          Adds an attribute to the element, but only if the attribute name does not already exist.
 void attribute(String namespace, String name, String value)
          Adds a namespaced attribute to the element, but only if the attribute name does not already exist.
 void attributes(String... namesAndValues)
          Convenience for invoking attribute(String, String) multiple times.
 CData cdata(String content)
          Adds an returns a new CDATA node.
 Element comment(String text)
          Adds the comment and returns this element for further construction.
 Element defineNamespace(String namespace, String namespacePrefix)
          Defines a namespace for this element, mapping a URI to a prefix.
 Element element(String name, String... namesAndValues)
          Creates and returns a new Element node as a child of this node.
 Element elementAt(int index, String name, String... namesAndValues)
           
 Element elementNS(String namespace, String name)
          Creates and returns a new Element within a namespace as a child of this node.
 Element find(String path)
          Searchs for a child element with a particular name below this element.
 void forceAttributes(String... namesAndValues)
          Forces changes to a number of attributes.
 String getAttribute(String attributeName)
           
 Document getDocument()
           
 Element getElementById(String id)
          Tries to find an element under this element (including itself) whose id is specified.
 String getName()
           
 Element getParent()
          Returns the containing element for this element.
 Element raw(String text)
          Adds the raw text and returns this element for further construction.
 Text text(String text)
          Adds and returns a new text node (the text node is returned so that Text.write(String) or [@link Text.writef(String, Object[]) may be invoked .
 void toMarkup(PrintWriter writer)
          Writes the markup for this node to the writer.
 
Methods inherited from class org.apache.tapestry.dom.Node
getChildMarkup, getChildren, getContainer, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getDocument

public Document getDocument()

getParent

public Element getParent()
Returns the containing element for this element. This will be null for the root element of a document.


attribute

public void attribute(String name,
                      String value)
Adds an attribute to the element, but only if the attribute name does not already exist.

Parameters:
name - the name of the attribute to add
value - the value for the attribute. A value of null is allowed, and no attribute will be added to the element.

attribute

public void attribute(String namespace,
                      String name,
                      String value)
Adds a namespaced attribute to the element, but only if the attribute name does not already exist.

Parameters:
namespace - the namespace to contain the attribute, or null
name - the name of the attribute to add
value - the value for the attribute. A value of null is allowed, and no attribute will be added to the element.

attributes

public void attributes(String... namesAndValues)
Convenience for invoking attribute(String, String) multiple times.

Parameters:
namesAndValues - alternating attribute names and attribute values

forceAttributes

public void forceAttributes(String... namesAndValues)
Forces changes to a number of attributes. The new attributes overwrite previous values.


element

public Element element(String name,
                       String... namesAndValues)
Creates and returns a new Element node as a child of this node.

Parameters:
name - the name of the element to create
namesAndValues - alternating attribute names and attribute values

elementNS

public Element elementNS(String namespace,
                         String name)
Creates and returns a new Element within a namespace as a child of this node.

Parameters:
namespace - namespace to contain the element, or null
name - element name to create within the namespace
Returns:
the newly created element

elementAt

public Element elementAt(int index,
                         String name,
                         String... namesAndValues)

comment

public Element comment(String text)
Adds the comment and returns this element for further construction.


raw

public Element raw(String text)
Adds the raw text and returns this element for further construction.


text

public Text text(String text)
Adds and returns a new text node (the text node is returned so that Text.write(String) or [@link Text.writef(String, Object[]) may be invoked .

Parameters:
text - initial text for the node
Returns:
the new Text node

cdata

public CData cdata(String content)
Adds an returns a new CDATA node.

Parameters:
content - the content to be rendered by the node
Returns:
the newly created node

toMarkup

public void toMarkup(PrintWriter writer)
Description copied from class: Node
Writes the markup for this node to the writer.

Specified by:
toMarkup in class Node

getElementById

public Element getElementById(String id)
Tries to find an element under this element (including itself) whose id is specified. Performs a width-first search of the document tree.

Parameters:
id - the value of the id attribute of the element being looked for
Returns:
the element if found. null if not found.

find

public Element find(String path)
Searchs for a child element with a particular name below this element. The path parameter is a slash separated series of element names.

Parameters:
path -
Returns:

getAttribute

public String getAttribute(String attributeName)

getName

public String getName()

addClassName

public Element addClassName(String... className)
Adds one or more CSS class names to the "class" attribute. No check for duplicates is made. Note that CSS class names are case insensitive on the client.

Parameters:
className - one or more CSS class names
Returns:
the element for further configuration

defineNamespace

public Element defineNamespace(String namespace,
                               String namespacePrefix)
Defines a namespace for this element, mapping a URI to a prefix. This will affect how namespaced elements and attributes nested within the element are rendered, and will also cause xmlns: attributes (to define the namespace and prefix) to be rendered.

Parameters:
namespace - URI of the namespace
namespacePrefix - prefix
Returns:
this element


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.