Package org.apache.wiki.util
Class XhtmlUtil
java.lang.Object
org.apache.wiki.util.XhtmlUtil
A utility class to generate XHTML objects and ultimately, serialised markup.
This class is incomplete but serves as a basic utility for JSPWiki, to be
expanded upon as needed.
This uses JDOM2 as its backing implementation.
Example
To generate a single element, an Element with PCDATA content, and then embed the latter in the former:
Element div = XhtmlUtil.element(XHTML.div);
Element p = XhtmlUtil.element(XHTML.p,"Some content");
div.addContent(p);
There is also a convenient link and link target constructor methods:
Element link = XhtmlUtil.link("hrefValue","linkText");
Element target = XhtmlUtil.target("targetIdValue","linkText");
- Since:
- 2.10
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.jdom2.output.Formatto print instead of -
Method Summary
Modifier and TypeMethodDescriptionstatic org.jdom2.ElementReturn an Element with an element type name matching the parameter.static org.jdom2.ElementReturn an Element with an element type name matching the parameter, and optional PCDATA (parsed character data, a String) content.static org.jdom2.ElementReturn an XHTML img element with an required 'src' attribute and optional 'alt' alternative text value.static org.jdom2.ElementReturn an XHTML form input element with optional 'type', 'name' and 'value' attributes.static org.jdom2.ElementReturn an XHTML link with a required 'href' attribute value and optional link (PCDATA) content.static Stringserialize(org.jdom2.Element element) Serializes the Element to a String using a compact serialization format.static Stringserialize(org.jdom2.Element element, boolean pretty) Serializes the Element to a String.static Stringserialize(org.jdom2.Element element, org.jdom2.output.Format format) Serializes the Element to a String.static voidstatic org.jdom2.ElementReturn an XHTML link target with a required 'id' attribute value.
-
Field Details
-
EXPAND_EMPTY_NODES
to printinstead of
-
-
Method Details
-
serialize
Serializes the Element to a String using a compact serialization format.- Parameters:
element- the element to serialize.- Returns:
- the serialized Element.
-
serialize
Serializes the Element to a String. If pretty is true, uses a pretty whitespace format, otherwise a compact format.- Parameters:
element- the element to serialize.pretty- if true, use a pretty whitespace format.- Returns:
- the serialized Element.
-
serialize
Serializes the Element to a String. Allows to use a custom format.- Parameters:
element- the element to serialize.format- custom format used to serialize the Element.- Returns:
- the serialized Element.
-
element
Return an Element with an element type name matching the parameter.- Parameters:
element- the XHTML element type.- Returns:
- a JDOM2 Element.
-
element
Return an Element with an element type name matching the parameter, and optional PCDATA (parsed character data, a String) content.- Parameters:
element- the XHTML element type.content- the optional PCDATA content.- Returns:
- a JDOM2 Element.
-
link
Return an XHTML link with a required 'href' attribute value and optional link (PCDATA) content.- Parameters:
href- the required 'href' value.content- the optional link (PCDATA) content.- Returns:
- a JDOM2 Element.
-
target
Return an XHTML link target with a required 'id' attribute value.- Parameters:
id- the required 'id' link target value.- Returns:
- a JDOM2 Element.
-
img
Return an XHTML img element with an required 'src' attribute and optional 'alt' alternative text value.- Parameters:
src- the required 'src' value.alt- the optional 'alt' alternative text value.- Returns:
- a JDOM2 Element.
-
input
Return an XHTML form input element with optional 'type', 'name' and 'value' attributes.- Parameters:
type- the optional 'type' value.name- the optional 'name' value.value- the optional 'value' value.- Returns:
- a JDOM2 Element.
-
setClass
-