Package org.apache.tapestry5.dom
Class Element
- java.lang.Object
- 
- org.apache.tapestry5.dom.Node
- 
- org.apache.tapestry5.dom.Element
 
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ElementaddClassName(java.lang.String... classNames)Deprecated.Deprecated in 5.4, as this is now special behavior for the "class" attribute.Elementattribute(java.lang.String name, java.lang.String value)Adds an attribute to the element, but only if the attribute name does not already exist.Elementattribute(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.Elementattributes(java.lang.String... namesAndValues)Convenience for invokingattribute(String, String)multiple times.CDatacdata(java.lang.String content)Adds and returns a new CDATA node.Elementcomment(java.lang.String text)Adds the comment and returns this element for further construction.ElementdefineNamespace(java.lang.String namespace, java.lang.String namespacePrefix)Defines a namespace for this element, mapping a URI to a prefix.Elementelement(java.lang.String name, java.lang.String... namesAndValues)Creates and returns a new Element node as a child of this node.ElementelementAt(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.ElementelementBefore(java.lang.String name, java.lang.String... namesAndValues)Inserts a new element before this element.ElementelementNS(java.lang.String namespace, java.lang.String name)Creates and returns a new Element within a namespace as a child of this node.Elementfind(java.lang.String path)Searchs for a child element with a particular name below this element.ElementforceAttributes(java.lang.String... namesAndValues)Forces changes to a number of attributes.ElementforceAttributesNS(java.lang.String namespace, java.lang.String... namesAndValues)Forces changes to a number of attributes in the global namespace.java.lang.StringgetAttribute(java.lang.String attributeName)java.util.Collection<Attribute>getAttributes()Returns the attributes for this Element as a (often empty) collection ofAttributes.java.lang.StringgetChildMarkup()java.util.List<Node>getChildren()Returns an unmodifiable list of children for this element.DocumentgetDocument()ElementgetElement(Predicate<Element> predicate)Tries to find an element under this element (including itself) accepted by the given predicate.ElementgetElementByAttributeValue(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.ElementgetElementById(java.lang.String id)Tries to find an element under this element (including itself) whose id is specified.java.lang.StringgetName()java.lang.StringgetNamespace()Returns the namespace for this element (which is typically a URL).protected java.util.Map<java.lang.String,java.lang.String>getNamespaceURIToPrefix()booleanisEmpty()Returns true if the element has no children, or has only text children that contain only whitespace.voidpop()Removes an element; the element's children take the place of the node within its container.Elementraw(java.lang.String text)Adds the raw text and returns this element for further construction.ElementremoveChildren()Removes all children from this element.Texttext(java.lang.String text)Adds and returns a new text node (the text node is returned so thatText.write(String)or [@linkText.writef(String, Object[])may be invoked .voidvisit(Visitor visitor)Depth-first visitor traversal of this Element and its Element children.- 
Methods inherited from class org.apache.tapestry5.dom.NodegetContainer, moveAfter, moveBefore, moveToBottom, moveToTop, remove, toMarkup, toString, wrap
 
- 
 
- 
- 
- 
Method Detail- 
getDocumentpublic Document getDocument() - Overrides:
- getDocumentin class- Node
 
 - 
attributepublic 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. The "class" attribute is treated specially: the new value is appended, after a space, to the existing value.- 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.
 
 - 
attributepublic 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. The "class" attribute of the default namespace is treated specially: the new value is appended, after a space, to the existing value.- Parameters:
- namespace- the namespace to contain the attribute, or null for the default namespace
- 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.
 
 - 
attributespublic Element attributes(java.lang.String... namesAndValues) Convenience for invokingattribute(String, String)multiple times.- Parameters:
- namesAndValues- alternating attribute names and attribute values
 
 - 
forceAttributespublic Element forceAttributes(java.lang.String... namesAndValues) Forces changes to a number of attributes. The new attributes overwrite previous values. Overriding an attribute's value to null will remove the attribute entirely.- Parameters:
- namesAndValues- alternating attribute names and attribute values
- Returns:
- this element
 
 - 
forceAttributesNSpublic Element forceAttributesNS(java.lang.String namespace, java.lang.String... namesAndValues) Forces changes to a number of attributes in the global namespace. The new attributes overwrite previous values (event for the "class" attribute). Overriding attribute's value to null will remove the attribute entirely. TAP5-708: don't use element namespace for attributes- Parameters:
- namespace- the namespace or null
- namesAndValues- alternating attribute name and value
- Returns:
- this element
 
 - 
elementpublic Element element(java.lang.String name, java.lang.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
 
 - 
elementBeforepublic Element elementBefore(java.lang.String name, java.lang.String... namesAndValues) Inserts a new element before this element.- Parameters:
- name- element name
- namesAndValues- attribute names and values
- Returns:
- the new element
- Since:
- 5.3
 
 - 
elementNSpublic 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.- Parameters:
- namespace- namespace to contain the element, or null
- name- element name to create within the namespace
- Returns:
- the newly created element
 
 - 
elementAtpublic 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.- Parameters:
- index- to insert at
- name- element name
- namesAndValues- attribute name / attribute value pairs
- Returns:
- the new element
 
 - 
commentpublic Element comment(java.lang.String text) Adds the comment and returns this element for further construction.
 - 
rawpublic Element raw(java.lang.String text) Adds the raw text and returns this element for further construction.
 - 
textpublic Text text(java.lang.String text) Adds and returns a new text node (the text node is returned so thatText.write(String)or [@linkText.writef(String, Object[])may be invoked .- Parameters:
- text- initial text for the node
- Returns:
- the new Text node
 
 - 
cdatapublic CData cdata(java.lang.String content) Adds and returns a new CDATA node.- Parameters:
- content- the content to be rendered by the node
- Returns:
- the newly created node
 
 - 
getElementByIdpublic Element getElementById(java.lang.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.
 
 - 
getElementByAttributeValuepublic 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.- Parameters:
- attributeName- the name of the attribute of the element being looked for
- attributeValue- the value of the attribute of the element being looked for
- Returns:
- the element if found. null if not found.
- Since:
- 5.2.3
 
 - 
getElementpublic Element getElement(Predicate<Element> predicate) Tries to find an element under this element (including itself) accepted by the given predicate.- Parameters:
- predicate- Predicate to accept the element
- Returns:
- the element if found. null if not found.
- Since:
- 5.2.3
 
 - 
findpublic Element find(java.lang.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.
 - 
getAttributepublic java.lang.String getAttribute(java.lang.String attributeName) 
 - 
getNamepublic java.lang.String getName() 
 - 
addClassNamepublic Element addClassName(java.lang.String... classNames) Deprecated.Deprecated in 5.4, as this is now special behavior for the "class" attribute.Adds one or more CSS class names to the "class" attribute.- Parameters:
- classNames- one or more CSS class names
- Returns:
- the element for further configuration
 
 - 
defineNamespacepublic Element defineNamespace(java.lang.String namespace, java.lang.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 causexmlns:attributes (to define the namespace and prefix) to be rendered.- Parameters:
- namespace- URI of the namespace
- namespacePrefix- prefix
- Returns:
- this element
 
 - 
getNamespacepublic java.lang.String getNamespace() Returns the namespace for this element (which is typically a URL). The namespace may be null.
 - 
poppublic void pop() Removes an element; the element's children take the place of the node within its container.
 - 
removeChildrenpublic Element removeChildren() Removes all children from this element.- Returns:
- the element, for method chaining
 
 - 
getNamespaceURIToPrefixprotected java.util.Map<java.lang.String,java.lang.String> getNamespaceURIToPrefix() - Overrides:
- getNamespaceURIToPrefixin class- Node
 
 - 
isEmptypublic boolean isEmpty() Returns true if the element has no children, or has only text children that contain only whitespace.- Since:
- 5.1.0.0
 
 - 
visitpublic void visit(Visitor visitor) Depth-first visitor traversal of this Element and its Element children. The traversal order is the same as render order.- Parameters:
- visitor- callback
- Since:
- 5.1.0.0
 
 - 
getChildMarkuppublic final java.lang.String getChildMarkup() - Returns:
- the concatenation of the String representations Node.toString()of its children.
 
 - 
getChildrenpublic java.util.List<Node> getChildren() Returns an unmodifiable list of children for this element. OnlyElements will have children. Also, note that unlike W3C DOM, attributes are not represented asNodes.- Returns:
- unmodifiable list of children nodes
 
 - 
getAttributespublic java.util.Collection<Attribute> getAttributes() Returns the attributes for this Element as a (often empty) collection ofAttributes. The order of the attributes within the collection is not specified. Modifying the collection will not affect the attributes (useforceAttributes(String[])to change existing attribute values, andattribute(String, String, String)to add new attribute values.- Returns:
- attribute collection
 
 
- 
 
-