Class ZHtml.Document

java.lang.Object
org.spiderwiz.zutils.ZHtml.Node
org.spiderwiz.zutils.ZHtml.Document
Enclosing class:
ZHtml

public class ZHtml.Document
extends ZHtml.Node
Represents the root node of an HTML document.

The root node of an HTML document is the node that is tagged html.

  • Method Details

    • addParagraph

      public ZHtml.Paragraph addParagraph​(String text)
      Appends a paragraph (p tag) that wraps the given text to the document body.

      The given text can contain any character, including characters that have special HTML meanings. When the document is converted to HTML using toHtml(), special characters are escaped.

      Parameters:
      text - the plain text that are wrapped by the paragraph tag.
      Returns:
      the added Paragraph node.
    • addDiv

      public ZHtml.Div addDiv()
      Appends a div element (div tag) to the document body.
      Returns:
      the added Div node.
    • addHeading

      public ZHtml.Heading addHeading​(String text, int level)
      Appends a heading (h tag) wrapping the given text and having the given level to the document body.

      The tag has the form of <hlevel>.

      The given text can contain any character, including characters that have special HTML meanings. The method does the necessary HTML escaping.

      Parameters:
      text - the plain text wrapped by the heading tag.
      level - the level of the heading tag.
      Returns:
      the added Heading node.
    • addHeading

      public ZHtml.Heading addHeading​(String text, int level, String align)
      Appends a heading (h tag) wrapping the given text, having the given level and aligned to the given direction to the document body.

      The tag has the form of <hlevel>.

      The given text can contain any character, including characters that have special HTML meanings. The method does the necessary HTML escaping.

      The alignment direction is applied to text-align style attached to the node.

      Parameters:
      text - the plain text that are wrapped by the heading tag.
      level - the level of the heading tag.
      align - alignment direction - "left", "center" or "right". Null or empty values default to "left".
      Returns:
      the added Heading node.
    • addHeading

      public ZHtml.Heading addHeading​(ZHtml.Node node, int level)
      Appends a heading (h tag) wrapping the given node and having the given level to the document body.

      The tag has the form of <hlevel>.

      Parameters:
      node - the Node object that are wrapped by the heading tag.
      level - the level of the heading tag.
      Returns:
      the added Heading node.
    • addHeading

      public ZHtml.Heading addHeading​(ZHtml.Node node, int level, String align)
      Appends a heading (h tag) wrapping the given node, having the given level and aligned to the given direction to the document body.

      The tag has the form of <hlevel>.

      Parameters:
      node - the Node object that are wrapped by the heading tag.
      level - the level of the heading tag.
      align - alignment direction - "left", "center" or "right". Null or empty value defaults to "left".
      Returns:
      the added Heading node.
    • addTable

      public ZHtml.Table addTable​(String[] headers, String width)
      Appends a table (table tag) with the given list of column headers and of the specified width to the document body.

      The headers are placed in the table as a row (tr tag) of header cells (th tags).

      The width can be any allowed value in width property of the table tag. If it is null, "100%" is assumed.

      Parameters:
      headers - an array of column headers to display in the table.
      width - the table width. Null value defaults to "100%".
      Returns:
      the added Table node.
    • toHtml

      public String toHtml()
      Returns the document with all its added nodes as an HTML text.
      Returns:
      the document with all its added nodes as an HTML text.