Class XhtmlUtil

java.lang.Object
org.apache.wiki.util.XhtmlUtil

public final class XhtmlUtil
extends java.lang.Object
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

    Fields
    Modifier and Type Field Description
    static org.jdom2.output.Format EXPAND_EMPTY_NODES
    to print instead of
  • Method Summary

    Modifier and Type Method Description
    static org.jdom2.Element element​(XHTML element)
    Return an Element with an element type name matching the parameter.
    static org.jdom2.Element element​(XHTML element, java.lang.String content)
    Return an Element with an element type name matching the parameter, and optional PCDATA (parsed character data, a String) content.
    static org.jdom2.Element img​(java.lang.String src, java.lang.String alt)
    Return an XHTML img element with an required 'src' attribute and optional 'alt' alternative text value.
    static org.jdom2.Element input​(java.lang.String type, java.lang.String name, java.lang.String value)
    Return an XHTML form input element with optional 'type', 'name' and 'value' attributes.
    static org.jdom2.Element link​(java.lang.String href, java.lang.String content)
    Return an XHTML link with a required 'href' attribute value and optional link (PCDATA) content.
    static java.lang.String serialize​(org.jdom2.Element element)
    Serializes the Element to a String using a compact serialization format.
    static java.lang.String serialize​(org.jdom2.Element element, boolean pretty)
    Serializes the Element to a String.
    static java.lang.String serialize​(org.jdom2.Element element, org.jdom2.output.Format format)
    Serializes the Element to a String.
    static void setClass​(org.jdom2.Element element, java.lang.String classValue)  
    static org.jdom2.Element target​(java.lang.String id, java.lang.String content)
    Return an XHTML link target with a required 'id' attribute value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EXPAND_EMPTY_NODES

      public static final org.jdom2.output.Format EXPAND_EMPTY_NODES
      to print instead of
  • Method Details

    • serialize

      public static java.lang.String serialize​(org.jdom2.Element element)
      Serializes the Element to a String using a compact serialization format.
      Parameters:
      element - the element to serialize.
      Returns:
      the serialized Element.
    • serialize

      public static java.lang.String serialize​(org.jdom2.Element element, boolean pretty)
      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

      public static java.lang.String serialize​(org.jdom2.Element element, org.jdom2.output.Format format)
      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

      public static org.jdom2.Element element​(XHTML element)
      Return an Element with an element type name matching the parameter.
      Parameters:
      element - the XHTML element type.
      Returns:
      a JDOM2 Element.
    • element

      public static org.jdom2.Element element​(XHTML element, java.lang.String content)
      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

      public static org.jdom2.Element link​(java.lang.String href, java.lang.String content)
      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

      public static org.jdom2.Element target​(java.lang.String id, java.lang.String content)
      Return an XHTML link target with a required 'id' attribute value.
      Parameters:
      id - the required 'id' link target value.
      Returns:
      a JDOM2 Element.
    • img

      public static org.jdom2.Element img​(java.lang.String src, java.lang.String alt)
      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

      public static org.jdom2.Element input​(java.lang.String type, java.lang.String name, java.lang.String value)
      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

      public static void setClass​(org.jdom2.Element element, java.lang.String classValue)