Class TextResource


  • public abstract class TextResource
    extends Object

    A class representing a textual resource.

    This class can be used in scenarios where either a plain text or a text from the application's resources can be provided. Different factory methods for these use cases are provided. Instances can be queried for the data they contain. They also have a resolve() method which - given an ApplicationContext reference - returns the textual value of this resource.

    Since:
    1.4
    • Field Detail

      • UNDEFINED

        public static final TextResource UNDEFINED
        Constant for an undefined text resource. This instance returns null for all access methods.
    • Method Detail

      • getPlainText

        public String getPlainText()
        Returns the plain text for this resource. This method is defined if a plain text is available (i.e. the text does not have to be fetched from application resources). Otherwise, it returns null.
        Returns:
        the plain text for this resource or null
      • getResourceID

        public Object getResourceID()
        Returns the resource ID for this object. This method is defined if this resource represents an entry from the application's resources. Otherwise, result is null
        Returns:
        the resource ID or null
      • resolveText

        public String resolveText​(ApplicationContext applicationContext)
        Resolves this resource and returns its text value. If necessary, does a resource lookup using the given application context. The final text represented by this object is returned. For an undefined resource result is null.
        Parameters:
        applicationContext - the application context
        Returns:
        the text represented by this resource
      • hashCode

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

        public String toString()
        Returns a string representation of this object. The string contains the data that is defined: the plain text or the resource ID. (For the undefined resource, neither is available.)
        Overrides:
        toString in class Object
        Returns:
        a string for this object
      • fromText

        public static TextResource fromText​(String text)
        Creates a new instance of TextResource that represents the given plain text. No resource lookup is necessary; the text is directly provided. If the text is null, however, an undefined resource is returned.
        Parameters:
        text - the plain text
        Returns:
        a TextResource representing this plain text
      • fromResourceID

        public static TextResource fromResourceID​(Object resID)
        Creates a new instance of TextResource that represents an application resource with the given ID. The actual text is obtained via a resource lookup in the resolve() method. If the resource ID is null, however, an undefined resource is returned.
        Parameters:
        resID - the resource ID
        Returns:
        a TextResource representing this resource ID