Class HtmlSerializerSession

All Implemented Interfaces:
BeanSession, ConverterSession, RecordWritable
Direct Known Subclasses:
HtmlSchemaSerializerSession, HtmlStrippedDocSerializerSession

Session object that lives for the duration of a single use of HtmlSerializer.
Notes:
  • This class is not thread safe and is typically discarded after one use.
See Also:
  • Constructor Details

  • Method Details

    • create

      Creates a new builder for this object.
      Parameters:
      ctx - The context creating this session.
      Cannot be null.
      Returns:
      A new builder.
    • getAnchorText

      Returns the anchor text to use for the specified URL object.
      Parameters:
      pMeta - The property metadata of the bean property of the object. Can be null if the object isn't from a bean property; the PROPERTY_NAME anchor-text mode then falls back to the URL string itself.
      o - The URL object.
      Returns:
      The anchor text to use for the specified URL object.
    • isHtmlMode

      public boolean isHtmlMode()
      Description copied from class: XmlSerializerSession
      Returns true if we're serializing HTML.

      The difference in behavior is how empty non-void elements are handled. The XML serializer will produce a collapsed tag, whereas the HTML serializer will produce a start and end tag.

      Overrides:
      isHtmlMode in class XmlSerializerSession
      Returns:
      true if we're generating HTML.
    • isUri

      public boolean isUri(ClassMeta<?> cm, BeanPropertyMeta pMeta, Object o)
      Returns true if the specified object is a URL.
      Parameters:
      cm - The ClassMeta of the object being serialized.
      pMeta - The property metadata of the bean property of the object. Can be null if the object isn't from a bean property; bean-property-level URI detection is then skipped, relying solely on cm.
      o - The object.
      Returns:
      true if the specified object is a URL.
    • doWrite

      protected void doWrite(SerializerPipe out, Object o) throws IOException, SerializeException
      Description copied from class: SerializerSession
      Serializes a POJO to the specified pipe.

      This method should NOT close the context object.

      The default implementation of this method simply calls Serializer.doWrite(SerializerSession,SerializerPipe,Object).

      Overrides:
      doWrite in class XmlSerializerSession
      Parameters:
      out - Where to send the output from the serializer.
      o - The object to serialize.
      Throws:
      IOException - Thrown by underlying stream.
      SerializeException - Problem occurred trying to serialize object.
    • getHtmlBeanPropertyMeta

      Returns the language-specific metadata on the specified bean property.
      Parameters:
      bpm - The bean property to return the metadata on.
      Returns:
      The metadata.
    • getHtmlClassMeta

      Returns the language-specific metadata on the specified class.
      Parameters:
      cm - The class to return the metadata on.
      Returns:
      The metadata.
    • getHtmlWriter

      protected final HtmlWriter<?> getHtmlWriter(SerializerPipe out)
      Converts the specified output target object to an HtmlWriter.
      Parameters:
      out - The output target object.
      Must not be null.
      Returns:
      The output target object wrapped in an HtmlWriter.
    • getLabelParameter

      protected final String getLabelParameter()
      Link label parameter name.
      Returns:
      The parameter name to look for when resolving link labels.
      See Also:
    • getUriAnchorText

      protected final AnchorText getUriAnchorText()
      Anchor text source.
      Returns:
      When creating anchor tags (e.g. <a href='...' >text</a>) in HTML, this setting defines what to set the inner text to.
      See Also:
    • isAddBeanTypes

      public final boolean isAddBeanTypes()
      Description copied from class: SerializerSession
      Add "_type" properties when needed.
      Overrides:
      isAddBeanTypes in class XmlSerializerSession
      Returns:
      true if "_type" properties added to beans if their type cannot be inferred through reflection.
      See Also:
    • isAddKeyValueTableHeaders

      protected final boolean isAddKeyValueTableHeaders()
      Add key/value headers on bean/map tables.
      Returns:
      true if key and value column headers are added to tables.
      See Also:
    • isDetectLabelParameters

      protected final boolean isDetectLabelParameters()
      Look for link labels in URIs.
      Returns:
      true if we should ook for URL label parameters (e.g. "?label=foobar").
      See Also:
    • isDetectLinksInStrings

      protected final boolean isDetectLinksInStrings()
      Look for URLs in Strings.
      Returns:
      true if we should automatically convert strings to URLs if they look like a URL.
      See Also:
    • writeAnything

      protected XmlSerializerSession.ContentResult writeAnything(XmlWriter<?> out, Object o, ClassMeta<?> eType, String name, BeanPropertyMeta pMeta, int xIndent, boolean isRoot, boolean nlIfElement) throws SerializeException
      Serialize the specified object to the specified writer.
      Parameters:
      out - The writer.
      o - The object to serialize.
      eType - The expected type of the object if this is a bean property.
      name - The attribute name of this object if this object was a field in a JSON object (i.e. key of a Map.Entry or property name of a bean).
      pMeta - The bean property being serialized, or null if we're not serializing a bean property.
      xIndent - The current indentation value.
      isRoot - true if this is the root element of the document.
      nlIfElement - true if we should add a newline to the output before serializing only if the object is an element and not text.
      Returns:
      The type of content encountered. Either simple (no whitespace) or normal (elements with whitespace).
      Throws:
      SerializeException - Generic serialization error occurred.
    • writeAnything

      protected XmlSerializerSession.ContentResult writeAnything(XmlWriter<?> out, Object o, ClassMeta<?> eType, String keyName, String elementName, Namespace elementNamespace, boolean addNamespaceUris, XmlFormat format, boolean isMixed, boolean preserveWhitespace, BeanPropertyMeta pMeta) throws SerializeException
      Description copied from class: XmlSerializerSession
      Workhorse method.
      Overrides:
      writeAnything in class XmlSerializerSession
      Parameters:
      out - The writer to send the output to.
      Must not be null.
      o - The object to serialize.
      Can be null (written as the XML null representation, e.g. type='null').
      eType - The expected type if this is a bean property value being serialized.
      Can be null (treated as the generic Object type).
      keyName - The property name or map key name.
      Can be null (the element is written without a separate property/key name).
      elementName - The root element name.
      Can be null (falls back to the bean dictionary name, then keyName, then the JSON type name).
      elementNamespace - The namespace of the element.
      Can be null (resolved from the serialized type's, then the actual type's, then the session's default namespace).
      addNamespaceUris - Flag indicating that namespace URIs need to be added.
      format - The format to serialize the output to.
      Must not be null.
      isMixed - We're serializing mixed content, so don't use whitespace.
      preserveWhitespace - true if we're serializing XmlFormat.MIXED_PWS or XmlFormat.TEXT_PWS.
      pMeta - The bean property metadata if this is a bean property being serialized.
      Can be null (no bean-property-level URI/child-name/namespace metadata is applied).
      Returns:
      The same writer passed in so that calls to the writer can be chained.
      Throws:
      SerializeException - General serialization error occurred.