Class Text

  • All Implemented Interfaces:
    java.io.Serializable

    public class Text
    extends java.lang.Object
    implements java.io.Serializable
    A primitive text type to be used in the model objects.
    Author:
    dobisekm
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Set<java.lang.String> KNOWN_TYPES
      All known types (contains the values of all the type constants defined in this class).
      static java.lang.String TYPE_HTML
      An html text.
      static java.lang.String TYPE_PLAIN
      A plain (possibly multi-line) text.
    • Constructor Summary

      Constructors 
      Constructor Description
      Text​(java.lang.String type, java.lang.String content)
      The shortcut for calling new Text(type, content, false).
      Text​(java.lang.String type, java.lang.String content, boolean lossy)
      Creates a Text with the given type, content, and lossy flag.
    • Field Detail

      • TYPE_PLAIN

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

        @NotNull
        public static final java.lang.String TYPE_HTML
        An html text.
        See Also:
        Constant Field Values
      • KNOWN_TYPES

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

      • Text

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

        public Text​(@NotNull
                    java.lang.String type,
                    @Nullable
                    java.lang.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 Detail

      • plain

        public static Text plain​(@Nullable
                                 java.lang.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
                                java.lang.String content)
        The convenience factory method for the creation of an html Text instance.

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

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

        @NotNull
        public java.lang.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(), HTMLHelper.convertHTMLToPlain(String)
      • 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:
        convertToPlainText(), HTMLHelper.convertPlainToHTML(String)
      • toString

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

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

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

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