Class MessageUtilImpl

java.lang.Object
com.atlassian.jira.message.MessageUtilImpl
All Implemented Interfaces:
MessageUtil, BaseUrl, I18nHelper

public class MessageUtilImpl extends Object implements MessageUtil
Default implementation of the message utility.
Since:
7.0
  • Method Details

    • getUrl

      @Nonnull public HelpUrl getUrl(String key)
      Description copied from interface: MessageUtil
      Returns a HelpUrl associated with the passed key. The MessageUtil.getDefaultUrl() URL is returned if the key has no associated URL.
      Specified by:
      getUrl in interface MessageUtil
      Parameters:
      key - the key to search for.
      Returns:
      the HelpUrl
      See Also:
    • getDefaultUrl

      @Nonnull public HelpUrl getDefaultUrl()
      Description copied from interface: MessageUtil
      Returns a HelpUrl that can be used for generic JIRA help. It commonly points at the JIRA help index/landing page.
      Specified by:
      getDefaultUrl in interface MessageUtil
      Returns:
      the default HelpUrl for this instance.
      See Also:
    • getUrlKeys

      @Nonnull public Set<String> getUrlKeys()
      Description copied from interface: MessageUtil
      Return all the keys that have an associated HelpUrl.
      Specified by:
      getUrlKeys in interface MessageUtil
      Returns:
      all the keys that have an associated HelpUrl.
      See Also:
    • getExternalLink

      public String getExternalLink(String key)
      Description copied from interface: MessageUtil
      Get the external link for the specified key.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      Returns:
      the external link or the specified key if the link was not found.
      See Also:
    • getExternalLink

      public String getExternalLink(String key, String value1)
      Description copied from interface: MessageUtil
      Get the external link for the specified key with the specified parameter formatted into the link.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      value1 - specified parameter.
      Returns:
      the external link with the parameter formatted into the link or the specified key if the link was not found.
      See Also:
    • getExternalLink

      public String getExternalLink(String key, String value1, String value2)
      Description copied from interface: MessageUtil
      Get the external link for the specified key with the specified parameters formatted into the link.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      value1 - first specified parameter.
      value2 - second specified parameter.
      Returns:
      the external link with the parameters formatted into the link or the specified key if the link was not found.
      See Also:
    • getExternalLink

      public String getExternalLink(String key, String value1, String value2, String value3)
      Description copied from interface: MessageUtil
      Get the external link for the specified key with the specified parameters formatted into the link.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      value1 - first specified parameter.
      value2 - second specified parameter.
      value3 - third specified parameter.
      Returns:
      the external link with the parameters formatted into the link or the specified key if the link was not found.
      See Also:
    • getExternalLink

      public String getExternalLink(String key, String value1, String value2, String value3, String value4)
      Description copied from interface: MessageUtil
      Get the external link for the specified key with the specified parameters formatted into the link.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      value1 - first specified parameter.
      value2 - second specified parameter.
      value3 - third specified parameter.
      value4 - third specified parameter.
      Returns:
      the external link with the parameters formatted into the link or the specified key if the link was not found.
      See Also:
    • getExternalLink

      public String getExternalLink(String key, Object parameters)
      Description copied from interface: MessageUtil
      Get the external link for the specified key with the specified parameters formatted into the link.
      Specified by:
      getExternalLink in interface MessageUtil
      Parameters:
      key - of the external link.
      parameters - specified parameters, typically a List of parameters.
      Returns:
      the external link with the parameters formatted into the link or the specified key if the link was not found.
      See Also:
    • getAnchorTagWithInternalLink

      public String getAnchorTagWithInternalLink(String keyOfLink)
      Description copied from interface: MessageUtil
      Get a String representation of an anchor tag with an internal link and link text. The internal link would be the JIRA base url with the path of the specified key appended.

      Example for default implementation:

           #Config internal-help-paths.properties:
           app_access_local.path=/secure/admin/ApplicationAccess.jspa
           app_access_local.title=application.access.configuration.title
      
           #Config JiraWebActionSupport.properties:
           application.access.configuration.title=Application Access
      
           #Usage:
           messageUtil.getAnchorTagWithInternalLink("app_access_local");
      
           #Result:
           Application access
       
      Specified by:
      getAnchorTagWithInternalLink in interface MessageUtil
      Parameters:
      keyOfLink - the key for the internal link to be appended with the base URL.
      Returns:
      a String representation of an anchor tag with an internal link and link text.
      See Also:
    • getLocale

      public Locale getLocale()
      Specified by:
      getLocale in interface I18nHelper
      Returns:
      the Locale that is associated with this I18nHelper
    • getDefaultResourceBundle

      public ResourceBundle getDefaultResourceBundle()
      Description copied from interface: I18nHelper
      Returns the default ResourceBundle within JIRA, which does not include translations provided by plugins. For use cases where non-English translations are required, call I18nHelper.getResourceBundle() instead.
      Specified by:
      getDefaultResourceBundle in interface I18nHelper
      Returns:
      a non-null bundle
      See Also:
    • getUnescapedText

      public String getUnescapedText(String key)
      Description copied from interface: I18nHelper
      Called to return the un-formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getUnescapedText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      Returns:
      the un-formatted, translated, text or the key itself if no i18n message can be found
    • getUntransformedRawText

      public String getUntransformedRawText(String key)
      Description copied from interface: I18nHelper
      Specified by:
      getUntransformedRawText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      Returns:
      the un-formatted text or the key itself if no i18n message can be found
    • isKeyDefined

      public boolean isKeyDefined(String key)
      Description copied from interface: I18nHelper

      For the given key, checks whether such a key is defined in the locale context represented by this helper instance. Note that the actual translation may be in the 'fallback' default locale rather than the current locale.

      The contract of this is method is correlated with I18nHelper.getUntransformedRawText(String), whereby if this method returns false, I18nHelper.getUntransformedRawText(String) will return the key provided as an argument, and if this method returns true, I18nHelper.getUntransformedRawText(String) will generally return the translation, which in some very unlikely cases may be equal to the key.

      Specified by:
      isKeyDefined in interface I18nHelper
      Parameters:
      key - translation key
      Returns:
      true, if any translation for such key exists, false otherwise
    • getText

      public String getText(String key)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1, String value2)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1, String value2, String value3)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1, String value2, String value3, String value4)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3, Object value4)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      value6 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      value6 - a value to be substituted into the message
      value7 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1, String value2, String value3, String value4, String value5, String value6, String value7)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      value6 - a value to be substituted into the message
      value7 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      value6 - a value to be substituted into the message
      value7 - a value to be substituted into the message
      value8 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, String value1, String value2, String value3, String value4, String value5, String value6, String value7, String value8, String value9)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found
      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      value1 - a value to be substituted into the message
      value2 - a value to be substituted into the message
      value3 - a value to be substituted into the message
      value4 - a value to be substituted into the message
      value5 - a value to be substituted into the message
      value6 - a value to be substituted into the message
      value7 - a value to be substituted into the message
      value8 - a value to be substituted into the message
      value9 - a value to be substituted into the message
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getText

      public String getText(String key, Object parameters)
      Description copied from interface: I18nHelper
      Called to return the formatted text of the specified i18n key or the key itself if no message can be found.

      The object passed in can be an array, a List} or a single parameter object. It will be then used as substitution parameters within the message.

      Specified by:
      getText in interface I18nHelper
      Parameters:
      key - the key of the i18n message
      parameters - This can be an Array, a List and Array or a single object parameter
      Returns:
      the formatted text or the key itself if no i18n message can be found
    • getKeysForPrefix

      public Set<String> getKeysForPrefix(String prefix)
      Description copied from interface: I18nHelper
      Given a prefix for an i18n key, this method will return all keys that start with the prefix specified.
      Specified by:
      getKeysForPrefix in interface I18nHelper
      Parameters:
      prefix - The prefix for i18n keys. May not be null
      Returns:
      An immutable set of translation keys that start with the prefix specified.
    • getResourceBundle

      public ResourceBundle getResourceBundle()
      Description copied from interface: I18nHelper
      Returns the consolidated ResourceBundle for this I18nHelper, which includes translations provided by plugins.
      Specified by:
      getResourceBundle in interface I18nHelper
      Returns:
      a non-null bundle
      See Also:
    • getBaseUrl

      @Nonnull public String getBaseUrl()
      Specified by:
      getBaseUrl in interface BaseUrl
      Returns:
      The base URL for this instance, also known as the context path. If running in the context of a web request, this will return a url relative to the server root (ie "/jira/"). If running via email, it will return an absolute URL (eg. "http://example.com/jira"). In both cases URL does not contain trailing "/" character.
    • getCanonicalBaseUrl

      @Nonnull public String getCanonicalBaseUrl()
      Specified by:
      getCanonicalBaseUrl in interface BaseUrl
      Returns:
      The canonical base URL for this instance. It will return an absolute URL (eg. "http://example.com/jira"). This URL does not contain trailing "/" character.
    • getBaseUri

      public URI getBaseUri()
      Specified by:
      getBaseUri in interface BaseUrl
      Returns:
      The absolute base URI for this instance. It will contain trailing "/" character (eg. "http://example.com/jira/") as opposed to BaseUrl.getCanonicalBaseUrl()
    • resolveAddress

      @Nonnull public URI resolveAddress(@Nonnull String relative)
      Description copied from interface: BaseUrl
      Resolve the given relative path against the base URI.
      Specified by:
      resolveAddress in interface BaseUrl
      Parameters:
      relative - the path to be resolved
      Returns:
      absolute URI
    • runWithStaticBaseUrl

      @Nullable public <I, O> O runWithStaticBaseUrl(@Nullable I input, @Nonnull com.google.common.base.Function<I,O> runnable)
      Description copied from interface: BaseUrl
      Run the passed function in an environment where JIRA's configured baseURL is always used. This basically makes the passed function ignore any smart baseURL that can be generated from the request associated with the calling thread.
      Specified by:
      runWithStaticBaseUrl in interface BaseUrl
      Parameters:
      input - input to pass to the function.
      runnable - the function to execute.
      Returns:
      the result of the function.