Class HtmlWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
Direct Known Subclasses:
SimpleHtmlWriter

public class HtmlWriter extends XmlWriter
Specialized writer for serializing HTML.
See Also:
  • Constructor Details

    • HtmlWriter

      public HtmlWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver)
      Constructor.
      Parameters:
      out - The writer being wrapped.
      useWhitespace - If true, tabs will be used in output.
      maxIndent - The maximum indentation level.
      trimStrings - If true, strings should be trimmed before they're serialized.
      quoteChar - The quote character to use (i.e. '\'' or '"')
      uriResolver - The URI resolver for resolving URIs to absolute or root-relative form.
  • Method Details

    • text

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oTag

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

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

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

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

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

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

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

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

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

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

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

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

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • eTag

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

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

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

      public HtmlWriter 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 XmlWriter
      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.
    • attr

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

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

      public HtmlWriter 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 XmlWriter
      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.
    • attr

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

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cre

      public HtmlWriter 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 XmlWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • appendln

      public HtmlWriter 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 XmlWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • appendln

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • append

      public HtmlWriter 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 XmlWriter
      Parameters:
      indent - The number of tabs to indent.
      c - The character to write.
      Returns:
      This object.
    • s

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

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

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

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

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

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

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