Class Text

java.lang.Object
com.polarion.core.util.types.Text
All Implemented Interfaces:
Serializable

public class Text extends Object implements Serializable
A primitive text type to be used in the model objects.
Author:
dobisekm
See Also:
  • Field Details

    • TYPE_PLAIN

      @NotNull public static final String TYPE_PLAIN
      A plain (possibly multi-line) text.
      See Also:
    • TYPE_HTML

      @NotNull public static final String TYPE_HTML
      An html text.
      See Also:
    • KNOWN_TYPES

      @NotNull public static final Set<String> KNOWN_TYPES
      All known types (contains the values of all the type constants defined in this class).
  • Constructor Details

    • Text

      public Text(@NotNull String type, @Nullable String content)
      The shortcut for calling new Text(type, content, false).
    • Text

      public Text(@NotNull String type, @Nullable String content, boolean lossy)
      Creates a Text with the given type, content, and lossy flag.
      Parameters:
      type - The Text type. Must be one of KNOWN_TYPES.
      content - The Text content in a format that is valid for the given type.
      lossy - Whether the provided content has been through a lossy data conversion. (see isContentLossy())
  • Method Details

    • plain

      public static Text plain(@Nullable String content)
      The convenience factory method for the creation of a plain Text instance.

      Returns:
      new Text(TYPE_PLAIN, content);
    • html

      public static Text html(@Nullable String content)
      The convenience factory method for the creation of an html Text instance.

      Returns:
      new Text(TYPE_HTML, content);
    • getType

      @NotNull public String getType()
      Returns:
      This Text's type. (One of the type constants defined in this class.)
    • getContent

      @NotNull public String getContent()
      Returns:
      The string content of this text in a format specific for the text's type.
    • isContentLossy

      public boolean isContentLossy()
      Returns true, if a lossy format conversion was done on this Text. (see convertTo... methods).

      Making modifications based on lossy text is not recommended.

    • isPlain

      public boolean isPlain()
      Shortcut for TYPE_PLAIN.equals(type);
    • isHtml

      public boolean isHtml()
      Shortcut for TYPE_HTML.equals(type);
    • convertToPlainText

      @NotNull public Text convertToPlainText()
      Converts this Text to plain text. If it's already plain text, then this is returned. Otherwise the content is converted to plain text (any html tags are removed), and a new Text instance is created.

      Note: This function is lossy, so the HTML tag information is lost forever. Recommendation: Never transform between HTML and plain text multiple times.

      Returns:
      New Text instance with type TYPE_PLAIN
      See Also:
    • convertToHTML

      @NotNull public Text convertToHTML()
      Converts this Text to HTML text. If it's already HTML text, then this is returned. Otherwise the content is converted to HTML by escaping characters, that have special meaning or that are ignored in HTML.

      Note: This function is lossy, so there is no guarantee that converting Note: This function is lossy, so there is no guarantee that converting the HTML back to plain text will generate the original text.

      Returns:
      New Text instance with type "text/html"
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getTransformedContent

      public String getTransformedContent()
      Internal, do not use.
      Since:
      3.4.1
    • setTransformedContent

      public void setTransformedContent(String transformedContent)
      Internal, do not use.
      Since:
      3.4.1
    • getTransformedContent2

      public String getTransformedContent2()
      Internal, do not use.
      Since:
      3.5.0
    • setTransformedContent2

      public void setTransformedContent2(String transformedContent2)
      Internal, do not use.
      Since:
      3.5.0