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

      Copy constructor.
      Parameters:
      w - Writer being copied.
    • 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

    • append

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

      public HtmlWriter append(char[] value)
      Description copied from class: SerializerWriter
      Appends the specified characters to this writer.
      Overrides:
      append in class XmlWriter
      Parameters:
      value - The characters to append to this writer.
      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.
    • 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(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.
    • appendIf

      public HtmlWriter 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 XmlWriter
      Parameters:
      flag - Boolean flag.
      value - The text to write.
      Returns:
      This object.
    • appendIf

      public HtmlWriter 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 XmlWriter
      Parameters:
      flag - Boolean flag.
      value - The text to write.
      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.
    • appendUri

      public HtmlWriter appendUri(Object value)
      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 XmlWriter
      Parameters:
      value - The URI to serialize.
      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 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.
    • 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.
    • attrUri

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

      public HtmlWriter ceTag()
      Description copied from class: XmlWriter
      Closes an empty tag.

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

      Overrides:
      ceTag in class XmlWriter
      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.
    • cTag

      public HtmlWriter cTag()
      Description copied from class: XmlWriter
      Closes a tag.

      Shortcut for append('->');

      Overrides:
      cTag in class XmlWriter
      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(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 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.
    • 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(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.
    • 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.
    • ie

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

      public HtmlWriter 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 XmlWriter
      Parameters:
      flag - The boolean flag.
      indent - The current indentation level.
      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.
    • 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.
    • 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 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(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(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 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.
    • 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.
    • 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.
    • sIf

      public HtmlWriter 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 XmlWriter
      Parameters:
      flag - The boolean flag.
      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(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 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.
    • 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(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.
    • 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)
      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.
    • 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(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(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 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.
    • text

      public HtmlWriter text(Object value)
      Description copied from class: XmlWriter
      Shortcut for calling text(o, false);
      Overrides:
      text in class XmlWriter
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • 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.
    • textUri

      public HtmlWriter textUri(Object value)
      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 XmlWriter
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • w

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

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