|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tapestry5.dom.Node
org.apache.tapestry5.dom.Element
public final class Element
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(java.lang.String... className)
Adds one or more CSS class names to the "class" attribute. |
Element |
attribute(java.lang.String name,
java.lang.String value)
Adds an attribute to the element, but only if the attribute name does not already exist. |
Element |
attribute(java.lang.String namespace,
java.lang.String name,
java.lang.String value)
Adds a namespaced attribute to the element, but only if the attribute name does not already exist. |
Element |
attributes(java.lang.String... namesAndValues)
Convenience for invoking attribute(String, String) multiple times. |
CData |
cdata(java.lang.String content)
Adds and returns a new CDATA node. |
Element |
comment(java.lang.String text)
Adds the comment and returns this element for further construction. |
Element |
defineNamespace(java.lang.String namespace,
java.lang.String namespacePrefix)
Defines a namespace for this element, mapping a URI to a prefix. |
Element |
element(java.lang.String name,
java.lang.String... namesAndValues)
Creates and returns a new Element node as a child of this node. |
Element |
elementAt(int index,
java.lang.String name,
java.lang.String... namesAndValues)
Creates a new element, as a child of the current index, at the indicated index. |
Element |
elementBefore(java.lang.String name,
java.lang.String... namesAndValues)
Inserts a new element before this element. |
Element |
elementNS(java.lang.String namespace,
java.lang.String name)
Creates and returns a new Element within a namespace as a child of this node. |
Element |
find(java.lang.String path)
Searchs for a child element with a particular name below this element. |
Element |
forceAttributes(java.lang.String... namesAndValues)
Forces changes to a number of attributes. |
Element |
forceAttributesNS(java.lang.String namespace,
java.lang.String... namesAndValues)
Forces changes to a number of attributes in the global namespace. |
java.lang.String |
getAttribute(java.lang.String attributeName)
|
java.util.Collection<Attribute> |
getAttributes()
Returns the attributes for this Element as a (often empty) collection of Attribute s. |
java.lang.String |
getChildMarkup()
|
java.util.List<Node> |
getChildren()
Returns an unmodifiable list of children for this element. |
Document |
getDocument()
|
Element |
getElement(Predicate<Element> predicate)
Tries to find an element under this element (including itself) accepted by the given predicate. |
Element |
getElementByAttributeValue(java.lang.String attributeName,
java.lang.String attributeValue)
Tries to find an element under this element (including itself) whose given attribute has a given value. |
Element |
getElementById(java.lang.String id)
Tries to find an element under this element (including itself) whose id is specified. |
java.lang.String |
getName()
|
java.lang.String |
getNamespace()
Returns the namespace for this element (which is typically a URL). |
protected java.util.Map<java.lang.String,java.lang.String> |
getNamespaceURIToPrefix()
|
boolean |
isEmpty()
Returns true if the element has no children, or has only text children that contain only whitespace. |
void |
pop()
Removes an element; the element's children take the place of the node within its container. |
Element |
raw(java.lang.String text)
Adds the raw text and returns this element for further construction. |
Element |
removeChildren()
Removes all children from this element. |
Text |
text(java.lang.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 |
visit(Visitor visitor)
Depth-first visitor traversal of this Element and its Element children. |
Methods inherited from class org.apache.tapestry5.dom.Node |
---|
getContainer, moveAfter, moveBefore, moveToBottom, moveToTop, remove, toMarkup, toString, wrap |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public Document getDocument()
getDocument
in class Node
public Element attribute(java.lang.String name, java.lang.String value)
name
- the name of the attribute to addvalue
- the value for the attribute. A value of null is allowed, and no attribute will be added to the
element.public Element attribute(java.lang.String namespace, java.lang.String name, java.lang.String value)
namespace
- the namespace to contain the attribute, or nullname
- the name of the attribute to addvalue
- the value for the attribute. A value of null is allowed, and no attribute will be added to the
element.public Element attributes(java.lang.String... namesAndValues)
attribute(String, String)
multiple times.
namesAndValues
- alternating attribute names and attribute valuespublic Element forceAttributes(java.lang.String... namesAndValues)
namesAndValues
- alternating attribute names and attribute values
public Element forceAttributesNS(java.lang.String namespace, java.lang.String... namesAndValues)
namespace
- the namespace or nullnamesAndValues
- alternating attribute name and value
public Element element(java.lang.String name, java.lang.String... namesAndValues)
name
- the name of the element to createnamesAndValues
- alternating attribute names and attribute valuespublic Element elementBefore(java.lang.String name, java.lang.String... namesAndValues)
name
- element namenamesAndValues
- attribute names and values
public Element elementNS(java.lang.String namespace, java.lang.String name)
namespace
- namespace to contain the element, or nullname
- element name to create within the namespace
public Element elementAt(int index, java.lang.String name, java.lang.String... namesAndValues)
index
- to insert atname
- element namenamesAndValues
- attribute name / attribute value pairs
public Element comment(java.lang.String text)
public Element raw(java.lang.String text)
public Text text(java.lang.String text)
Text.write(String)
or [@link
Text.writef(String, Object[])
may be invoked .
text
- initial text for the node
public CData cdata(java.lang.String content)
content
- the content to be rendered by the node
public Element getElementById(java.lang.String id)
id
- the value of the id attribute of the element being looked for
public Element getElementByAttributeValue(java.lang.String attributeName, java.lang.String attributeValue)
attributeName
- the name of the attribute of the element being looked forattributeValue
- the value of the attribute of the element being looked for
public Element getElement(Predicate<Element> predicate)
predicate
- Predicate to accept the element
public Element find(java.lang.String path)
public java.lang.String getAttribute(java.lang.String attributeName)
public java.lang.String getName()
public Element addClassName(java.lang.String... className)
className
- one or more CSS class names
public Element defineNamespace(java.lang.String namespace, java.lang.String namespacePrefix)
xmlns:
attributes (to define
the namespace and prefix) to be rendered.
namespace
- URI of the namespacenamespacePrefix
- prefix
public java.lang.String getNamespace()
public void pop()
public Element removeChildren()
protected java.util.Map<java.lang.String,java.lang.String> getNamespaceURIToPrefix()
getNamespaceURIToPrefix
in class Node
public boolean isEmpty()
public void visit(Visitor visitor)
visitor
- callbackpublic final java.lang.String getChildMarkup()
Node.toString()
of its children.public java.util.List<Node> getChildren()
Element
s will
have children. Also, note that unlike W3C DOM, attributes are not represented as
Node
s.
public java.util.Collection<Attribute> getAttributes()
Attribute
s. The order of the attributes within the collection is not specified.
Modifying the collection will not affect the attributes (use forceAttributes(String[])
to change
existing attribute values, and attribute(String, String, String)
to add new attribute values.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |