Class HtmlSerializer.Builder<SELF extends HtmlSerializer.Builder<SELF>>

Direct Known Subclasses:
HtmlSchemaSerializer.Builder, HtmlSerializer.DefaultBuilder, HtmlStrippedDocSerializer.Builder
Enclosing class:
HtmlSerializer

public abstract static class HtmlSerializer.Builder<SELF extends HtmlSerializer.Builder<SELF>> extends XmlSerializer.Builder<SELF>
Builder class.
  • Constructor Details

    • Builder

      protected Builder()
      Constructor, default settings.
    • Builder

      protected Builder(HtmlSerializer.Builder<?> copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The builder to copy from.
      Cannot be null.
    • Builder

      protected Builder(HtmlSerializer copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The bean to copy from.
      Cannot be null.
  • Method Details

    • addBeanTypesHtml

      Add "_type" properties when needed.

      If true, then "_type" properties will be added to beans if their type cannot be inferred through reflection.

      When present, this value overrides the Serializer.Builder#addBeanTypes() setting and is provided to customize the behavior of specific serializers in a SerializerSet.

      Returns:
      This object.
    • addBeanTypesHtml

      public SELF addBeanTypesHtml(boolean value)
      Same as addBeanTypesHtml() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • addKeyValueTableHeaders

      HtmlSerializer configuration property:  Add key/value headers on bean/map tables.

      When enabled, key and value column headers are added to tables.

      Example:

      // Our bean class. public class MyBean { public String f1 = "foo"; public String f2 = "bar"; } // Serializer without headers. WriterSerializer serializer1 = HtmlSerializer.DEFAULT; // Serializer with headers. WriterSerializer serializer2 = HtmlSerializer .create() .addKeyValueTableHeaders() .build(); String withoutHeaders = serializer1.write(new MyBean()); String withHeaders = serializer2.write(new MyBean());

      The following shows the difference between the two generated outputs:

      withoutHeaders withHeaders
      f1foo
      f2bar
      keyvalue
      f1foo
      f2bar
      Returns:
      This object.
    • addKeyValueTableHeaders

      public SELF addKeyValueTableHeaders(boolean value)
      Same as addKeyValueTableHeaders() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • build

      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class XmlSerializer.Builder<SELF extends HtmlSerializer.Builder<SELF>>
      Returns:
      The built object.
    • copy

      public abstract SELF copy()
      Description copied from class: Context.Builder
      Copy creator.
      Specified by:
      copy in class XmlSerializer.Builder<SELF extends HtmlSerializer.Builder<SELF>>
      Returns:
      A new mutable copy of this builder.
    • disableDetectLabelParameters

      HtmlSerializer configuration property:  Dont look for link labels in URIs.

      Disables the feature where if the URL has a label parameter (e.g. "?label=foobar"), then use that as the anchor text of the link.

      The parameter name can be changed via the labelParameter(String) property.

      Example:

      // Our bean class with a property containing what looks like a URL. public class MyBean { public URI f1 = URI.create("http://www.apache.org?label=Apache%20Foundation"); } // Serializer with label detection. WriterSerializer serializer1 = HtmlSerializer .create() .addKeyValueTableHeaders() .build(); // Serializer without label detection. WriterSerializer serializer2 = HtmlSerializer .create() .addKeyValueTableHeaders() .disableDetectLabelParameters() .build(); String withLabels = serializer1.write(new MyBean()); String withoutLabels = serializer2.write(new MyBean());

      The following shows the difference between the two generated outputs.
      Note that they're both hyperlinks, but the anchor text differs:

      withLabels withoutLabels
      keyvalue
      f1Apache Foundation
      keyvalue
      f1http://www.apache.org?label=Apache%20Foundation
      Returns:
      This object.
    • disableDetectLabelParameters

      public SELF disableDetectLabelParameters(boolean value)
      Same as disableDetectLabelParameters() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • disableDetectLinksInStrings

      HtmlSerializer configuration property:  Don't look for URLs in Strings.

      Disables the feature where if a string looks like a URL (i.e. starts with "http://" or "https://", then treat it like a URL and make it into a hyperlink based on the rules specified by uriAnchorText(AnchorText).

      Example:

      // Our bean class with a property containing what looks like a URL. public class MyBean { public String f1 = "http://www.apache.org"; } // Serializer with link detection. WriterSerializer serializer1 = HtmlSerializer .create() .addKeyValueTableHeaders() .build(); // Serializer without link detection. WriterSerializer serializer2 = HtmlSerializer .create() .addKeyValueTableHeaders() .disableDetectLinksInStrings() .build(); String withLinks = serializer1.write(new MyBean()); String withoutLinks = serializer2.write(new MyBean());

      The following shows the difference between the two generated outputs:

      withLinks withoutLinks
      keyvalue
      f1http://www.apache.org
      keyvalue
      f1http://www.apache.org
      Returns:
      This object.
    • disableDetectLinksInStrings

      public SELF disableDetectLinksInStrings(boolean value)
      Same as disableDetectLinksInStrings() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • hashKey

      public HashKey hashKey()
      Description copied from class: Context.Builder
      Returns the hashkey of this builder.

      Used to return previously instantiated context beans that have matching hashkeys. The HashKey object is suitable for use as a hashmap key of a map of context beans. A context bean is considered equivalent if the HashKey.equals(Object) method is the same.

      Overrides:
      hashKey in class XmlSerializer.Builder<SELF extends HtmlSerializer.Builder<SELF>>
      Returns:
      The hashkey of this builder.
    • labelParameter

      public SELF labelParameter(String value)
      HtmlSerializer configuration property:  Link label parameter name.

      The parameter name to look for when resolving link labels}.

      Parameters:
      value - The new value for this property.
      Cannot be null.
      The default is "label".
      Returns:
      This object.
    • uriAnchorText

      public SELF uriAnchorText(AnchorText value)
      HtmlSerializer configuration property:  Anchor text source.

      When creating anchor tags (e.g. <a href='...' >text</a>) in HTML, this setting defines what to set the inner text to.

      The possible values are:

      • AnchorText
        • TO_STRING (default) - Set to whatever is returned by Object.toString() on the object.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("http://www.apache.org?foo=bar#myAnchor"); } // Serializer with TO_STRING anchor text. WriterSerializer serializer1 = HtmlSerializer.create().anchorText(TO_STRING).build(); // Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>http://www.apache.org?foo=bar#myAnchor</a> String html = serializer1.write(new MyBean());

        • PROPERTY_NAME - Set to the bean property name.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("http://www.apache.org?foo=bar#myAnchor"); } // Serializer with PROPERTY_NAME anchor text. WriterSerializer serializer1 = HtmlSerializer.create().anchorText(PROPERTY_NAME).build(); // Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>f1</a> String html = serializer1.write(new MyBean());

        • URI - Set to the URI value.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("http://www.apache.org?foo=bar#myAnchor"); } // Serializer with URI anchor text. WriterSerializer serializer1 = HtmlSerializer.create().anchorText(URI).build(); // Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>http://www.apache.org?foo=bar</a> String html = serializer1.write(new MyBean());

        • LAST_TOKEN - Set to the last token of the URI value.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("http://www.apache.org/foo/bar?baz=qux#myAnchor"); } // Serializer with LAST_TOKEN anchor text. WriterSerializer serializer1 = HtmlSerializer.create().anchorText(LAST_TOKEN).build(); // Produces: <a href='http://www.apache.org/foo/bar?baz=qux#myAnchor'>bar</a> String html = serializer1.write(new MyBean());

        • URI_ANCHOR - Set to the anchor of the URL.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("http://www.apache.org/foo/bar?baz=qux#myAnchor"); } // Serializer with URI_ANCHOR anchor text. WriterSerializer serializer1 = HtmlSerializer.create().anchorText(URI_ANCHOR).build(); // Produces: <a href='http://www.apache.org/foo/bar?baz=qux#myAnchor'>myAnchor</a> String html = serializer1.write(new MyBean());

        • CONTEXT_RELATIVE - Same as TO_STRING but assumes it's a context-relative path.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("bar/baz"); } // Serializer with CONTEXT_RELATIVE anchor text. WriterSerializer serializer1 = HtmlSerializer .create() .anchorText(CONTEXT_RELATIVE) .uriResolution(ROOT_RELATIVE) .uriRelativity(RESOURCE) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}") .build(); // Produces: <a href='/myContext/myServlet/bar/baz'>myServlet/bar/baz</a> String html = serializer1.write(new MyBean());

        • SERVLET_RELATIVE - Same as TO_STRING but assumes it's a servlet-relative path.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("bar/baz"); } // Serializer with SERVLET_RELATIVE anchor text. WriterSerializer serializer1 = HtmlSerializer .create() .anchorText(SERVLET_RELATIVE) .uriResolution(ROOT_RELATIVE) .uriRelativity(RESOURCE) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}") .build(); // Produces: <a href='/myContext/myServlet/bar/baz'>bar/baz</a> String html = serializer1.write(new MyBean());

        • PATH_RELATIVE - Same as TO_STRING but assumes it's a path-relative path.
          Example:

          // Our bean class with a URI property. public class MyBean { public URI f1 = URI.create("bar/baz"); } // Serializer with PATH_RELATIVE anchor text. WriterSerializer serializer1 = HtmlSerializer .create() .anchorText(PATH_RELATIVE) .uriResolution(ROOT_RELATIVE) .uriRelativity(PATH_INFO) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}") .build(); // Produces: <a href='/myContext/myServlet/foo/bar/baz'>bar/baz</a> String html = serializer1.write(new MyBean());

      Parameters:
      value - The new value for this property.
      Cannot be null.
      The default is AnchorText.TO_STRING.
      Returns:
      This object.