Class SimpleHtmlWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class SimpleHtmlWriter extends HtmlWriter
Utility class for creating custom HTML.
Example:

String table = new SimpleHtmlWriter().sTag("table").sTag("tr").sTag("td") .append("hello").eTag("td").eTag("tr").eTag("table").toString();

See Also:
  • Constructor Details

  • Method Details

    • append

      public SimpleHtmlWriter append(char c)
      Specified by:
      append in interface Appendable
      Overrides:
      append in class HtmlWriter
    • append

      public SimpleHtmlWriter append(char[] value)
      Description copied from class: SerializerWriter
      Appends the specified characters to this writer.
      Overrides:
      append in class HtmlWriter
      Parameters:
      value - The characters to append to this writer.
      Returns:
      This object.
    • append

      public SimpleHtmlWriter append(int indent, char c)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class HtmlWriter
      Parameters:
      indent - The number of tabs to indent.
      c - The character to write.
      Returns:
      This object.
    • append

      public SimpleHtmlWriter append(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class HtmlWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • append

      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class HtmlWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class HtmlWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • appendIf

      public SimpleHtmlWriter appendIf(boolean flag, char value)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class HtmlWriter
      Parameters:
      flag - Boolean flag.
      value - The text to write.
      Returns:
      This object.
    • appendIf

      public SimpleHtmlWriter appendIf(boolean flag, String value)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class HtmlWriter
      Parameters:
      flag - Boolean flag.
      value - The text to write.
      Returns:
      This object.
    • appendln

      public SimpleHtmlWriter appendln(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text, followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class HtmlWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • appendln

      Description copied from class: SerializerWriter
      Writes the specified text followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class HtmlWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • appendUri

      Description copied from class: SerializerWriter
      Appends the specified object as a URI.

      Object is converted to a String using toString(), so this will work on URL or URI objects, or any other type that returns a URI via it's toString() method.

      The URI is resolved based on the Serializer.Builder.uriRelativity(UriRelativity) and Serializer.Builder.uriResolution(UriResolution) settings and the UriContext that's part of the session.

      Overrides:
      appendUri in class HtmlWriter
      Parameters:
      value - The URI to serialize.
      Returns:
      This object.
    • attr

      public SimpleHtmlWriter attr(String name, Object value)
      Description copied from class: XmlWriter
      Shortcut for attr(null, name, value, false);
      Overrides:
      attr in class HtmlWriter
      Parameters:
      name - The attribute name.
      value - The attribute value.
      Returns:
      This object.
    • attr

      public SimpleHtmlWriter attr(String name, Object value, boolean valNeedsEncoding)
      Description copied from class: XmlWriter
      Shortcut for attr(null, name, value, false);
      Overrides:
      attr in class HtmlWriter
      Parameters:
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, attribute name will be encoded.
      Returns:
      This object.
    • attr

      public SimpleHtmlWriter attr(String ns, String name, Object value)
      Description copied from class: XmlWriter
      Shortcut for attr(ns, name, value, false);
      Overrides:
      attr in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value.
      Returns:
      This object.
    • attr

      public SimpleHtmlWriter attr(String ns, String name, Object value, boolean valNeedsEncoding)
      Description copied from class: XmlWriter
      Writes an attribute to the output: ns:name='value'
      Overrides:
      attr in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, attribute name will be encoded.
      Returns:
      This object.
    • attrUri

      public SimpleHtmlWriter attrUri(String name, Object value)
      Description copied from class: XmlWriter
      Append an attribute with a URI value.
      Overrides:
      attrUri in class HtmlWriter
      Parameters:
      name - The attribute name.
      value - The attribute value. Can be any object whose toString() method returns a URI.
      Returns:
      This object.
    • ceTag

      Description copied from class: XmlWriter
      Closes an empty tag.

      Shortcut for append('/').append('->');

      Overrides:
      ceTag in class HtmlWriter
      Returns:
      This object.
    • cr

      public SimpleHtmlWriter cr(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cr in class HtmlWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cre

      public SimpleHtmlWriter cre(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return at the end of a line.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cre in class HtmlWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cTag

      Description copied from class: XmlWriter
      Closes a tag.

      Shortcut for append('->');

      Overrides:
      cTag in class HtmlWriter
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(int indent, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).eTag(null, name, false);
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(int indent, String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).eTag(ns, name, false);
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(int indent, String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Shortcut for i(indent).eTag(ns, name, needsEncoding);
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(String name)
      Description copied from class: XmlWriter
      Shortcut for eTag(null, name, false);
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      name - The element name.
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for eTag(ns, name, false);
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • eTag

      public SimpleHtmlWriter eTag(String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Writes an end tag to the output: </ns:name>
      Overrides:
      eTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • i

      public SimpleHtmlWriter i(int indent)
      Description copied from class: SerializerWriter
      Writes an indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      i in class HtmlWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • ie

      public SimpleHtmlWriter ie(int indent)
      Description copied from class: SerializerWriter
      Writes an end-of-line indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      ie in class HtmlWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • nl

      public SimpleHtmlWriter nl(int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled.
      Overrides:
      nl in class HtmlWriter
      Parameters:
      indent - The current indentation level.
      Returns:
      This object.
    • nlIf

      public SimpleHtmlWriter nlIf(boolean flag, int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled and the boolean flag is true.
      Overrides:
      nlIf in class HtmlWriter
      Parameters:
      flag - The boolean flag.
      indent - The current indentation level.
      Returns:
      This object.
    • oAttr

      public SimpleHtmlWriter oAttr(String ns, String name)
      Description copied from class: XmlWriter
      Writes an open-ended attribute to the output: ns:name=
      Overrides:
      oAttr in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(int indent, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).oTag(null, name, false);
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(int indent, String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).oTag(ns, name, false);
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(int indent, String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Shortcut for i(indent).oTag(ns, name, needsEncoding);
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(String name)
      Description copied from class: XmlWriter
      Shortcut for oTag(null, name, false);
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      name - The element name.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for oTag(ns, name, false);
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • oTag

      public SimpleHtmlWriter oTag(String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Writes an opening tag to the output: <ns:name
      Overrides:
      oTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • q

      public SimpleHtmlWriter q()
      Description copied from class: SerializerWriter
      Adds the quote character specified by the quoteChar setting to the output.
      Overrides:
      q in class HtmlWriter
      Returns:
      This object.
    • s

      public SimpleHtmlWriter s()
      Description copied from class: SerializerWriter
      Adds a whitespace character to the output if the useWhitespace setting is enabled.
      Overrides:
      s in class HtmlWriter
      Returns:
      This object.
    • sIf

      public SimpleHtmlWriter sIf(boolean flag)
      Description copied from class: SerializerWriter
      Writes a space if the boolean expression is true and useWhitespace is false.

      Intended for cases in XML where text should be separated by either a space or newline. This ensures the text is separated by a space if whitespace is disabled.

      Overrides:
      sIf in class HtmlWriter
      Parameters:
      flag - The boolean flag.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(int indent, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).sTag(null, name, false);
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(int indent, String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).sTag(ns, name, false);
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(int indent, String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Shortcut for i(indent).sTag(ns, name, needsEncoding);
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(String name)
      Description copied from class: XmlWriter
      Shortcut for sTag(null, name, false);
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      name - The element name.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for sTag(ns, name, false);
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • sTag

      public SimpleHtmlWriter sTag(String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Writes a start tag to the output: <ns:name>
      Overrides:
      sTag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(int indent, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).tag(null, name, false);
      Overrides:
      tag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(int indent, String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for i(indent).tag(ns, name, false);
      Overrides:
      tag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(int indent, String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Shortcut for i(indent).tag(ns, name, needsEncoding);
      Overrides:
      tag in class HtmlWriter
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(String name)
      Description copied from class: XmlWriter
      Shortcut for tag(null, name, false);
      Overrides:
      tag in class HtmlWriter
      Parameters:
      name - The element name.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(String ns, String name)
      Description copied from class: XmlWriter
      Shortcut for tag(ns, name, false);
      Overrides:
      tag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • tag

      public SimpleHtmlWriter tag(String ns, String name, boolean needsEncoding)
      Description copied from class: XmlWriter
      Writes a closed tag to the output: <ns:name/>
      Overrides:
      tag in class HtmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • text

      public SimpleHtmlWriter text(Object value)
      Description copied from class: XmlWriter
      Shortcut for calling text(o, false);
      Overrides:
      text in class HtmlWriter
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • text

      public SimpleHtmlWriter text(Object o, boolean preserveWhitespace)
      Description copied from class: XmlWriter
      Serializes and encodes the specified object as valid XML text.
      Overrides:
      text in class HtmlWriter
      Parameters:
      o - The object being serialized.
      preserveWhitespace - If true, then we're serializing XmlFormat.MIXED_PWS or XmlFormat.TEXT_PWS content.
      Returns:
      This object.
    • textUri

      Description copied from class: XmlWriter
      Same as XmlWriter.text(Object) but treats the value as a URL to resolved then serialized.
      Overrides:
      textUri in class HtmlWriter
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class XmlWriter
    • w

      public SimpleHtmlWriter w(char c)
      Description copied from class: SerializerWriter
      Writes the specified character to the writer.
      Overrides:
      w in class HtmlWriter
      Parameters:
      c - The character to write.
      Returns:
      This object.
    • w

      Description copied from class: SerializerWriter
      Writes the specified string to the writer.
      Overrides:
      w in class HtmlWriter
      Parameters:
      s - The string to write.
      Returns:
      This object.