Class I18nizableText

java.lang.Object
org.ametys.runtime.i18n.I18nizableText
All Implemented Interfaces:
I18nizable, I18nizableTextParameter

public final class I18nizableText extends Object implements I18nizable, I18nizableTextParameter
This class wraps a text that may be internationalized.
  • Constructor Details

    • I18nizableText

      public I18nizableText(String label)
      Create a simple international text
      Parameters:
      label - The text. Cannot be null.
    • I18nizableText

      public I18nizableText(String catalogue, String key)
      Create an i18nized text
      Parameters:
      catalogue - the catalogue where the key is defined. Can be null. Can be overloaded by the catalogue in the key.
      key - the key of the text. Cannot be null. May include the catalogue using the character ':' as separator. CATALOG:KEY.
    • I18nizableText

      public I18nizableText(String catalogue, String key, List<String> parameters)
      Create an i18nized text with ordered parameters.
      Parameters:
      catalogue - the catalogue where the key is defined. Can be null. Can be overloaded by the catalogue in the key.
      key - the key of the text. Cannot be null. May include the catalogue using the character ':' as separator. CATALOG:KEY.
      parameters - the parameters of the key if any. Can be null.
    • I18nizableText

      public I18nizableText(String catalogue, String key, Map<String,I18nizableTextParameter> parameters)
      Create an i18nized text with named parameters.
      Parameters:
      catalogue - the catalogue where the key is defined. Can be null. Can be overloaded by the catalogue in the key.
      key - the key of the text. Cannot be null. May include the catalogue using the character ':' as separator. CATALOG:KEY.
      parameters - the named parameters of the message, as a Map of name -> value. Value can itself be an i18n key but must not have parameters.
    • I18nizableText

      public I18nizableText(String catalogueLocation, String catalogueFilename, String key)
      Create an i18nized text. Use this constructor only when the catalogue is an external catalogue, not managed by Ametys application
      Parameters:
      catalogueLocation - the file location URI of the catalogue where the key is defined.
      catalogueFilename - the catalogue bundle name such as 'messages'
      key - the key of the text. Cannot be null.
    • I18nizableText

      public I18nizableText(String catalogueLocation, String catalogueFilename, String key, List<String> parameters)
      Create an i18nized text with ordered parameters. Use this constructor only when the catalogue is an external catalogue, not managed by Ametys application
      Parameters:
      catalogueLocation - the file location URI of the catalogue where the key is defined.
      catalogueFilename - the catalogue bundle name such as 'messages'
      key - the key of the text. Cannot be null.
      parameters - the parameters of the key if any. Can be null.
    • I18nizableText

      public I18nizableText(String catalogueLocation, String catalogueFilename, String key, Map<String,I18nizableTextParameter> parameters)
      Create an i18nized text with named parameters.
      Parameters:
      catalogueLocation - the file location URI of the catalogue where the key is defined.
      catalogueFilename - the catalogue bundle name such as 'messages'
      key - the key of the text. Cannot be null.
      parameters - the named parameters of the message, as a Map of name -> value. Value can itself be an i18n key but must not have parameters.
  • Method Details

    • isI18n

      public boolean isI18n()
      Determine whether the text is i18nized or a simple cross languages text.
      Returns:
      true if the text is i18nized and so defined by a catalogue, a key and optionaly parameters.
      false if the text is a simple label
    • getCatalogue

      public String getCatalogue()
      Get the catalogue of the i18nized text.
      Returns:
      The catalogue where the key is defined
    • getLocation

      public String getLocation()
      Get the file location URI of the i18nized text.
      Returns:
      The catalog location where the key is defined
    • getBundleName

      Get the files name of catalog
      Returns:
      bundle name
    • getKey

      public String getKey()
      Get the key of the i18nized text.
      Returns:
      The key in the catalogue
    • getParameters

      Get the parameters of the key of the i18nized text.
      Returns:
      The list of parameters' values or null if there is no parameters
    • getParameterMap

      Get the parameters of the key of the i18nized text.
      Returns:
      The list of parameters' values or null if there is no parameters
    • getLabel

      public String getLabel()
      Get the label if a text is not i18nized.
      Returns:
      The label
    • toSAX

      public void toSAX(ContentHandler handler) throws SAXException
      Description copied from interface: I18nizable
      Represents this I18nizable as SAX events.
      Specified by:
      toSAX in interface I18nizable
      Parameters:
      handler - the SAX content handler
      Throws:
      SAXException - if an error occurs
    • toSAXAsParam

      public void toSAXAsParam(ContentHandler handler) throws SAXException
      Description copied from interface: I18nizableTextParameter
      Represents this I18nizableTextParameter as SAX events for an I18nizableText parameter.
      Specified by:
      toSAXAsParam in interface I18nizableTextParameter
      Parameters:
      handler - the SAX content handler
      Throws:
      SAXException - if an error occurs
    • toString

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

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

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

      public static I18nizableText getI18nizableTextValue(Configuration config, String defaultCatalogue, String value)
      Get an i18n text configuration (can be a key or a "direct" string).
      Parameters:
      config - The configuration to parse.
      defaultCatalogue - The i18n catalogue to use when not specified.
      value - The i18n text, can be a key or a "direct" string.
      Returns:
      The i18nizable text or null if the config is null
    • parseI18nizableText

      public static I18nizableText parseI18nizableText(Configuration config, String catalogueLocation, String catalogueFilename, String defaultValue) throws ConfigurationException
      Parse a i18n text configuration.
      Parameters:
      config - the configuration to use.
      catalogueLocation - The i18n catalog location URI
      catalogueFilename - The i18n catalog bundle name
      defaultValue - The default value key in configuration
      Returns:
      the i18n text or null if the config is null
      Throws:
      ConfigurationException - if the configuration is not valid.
    • parseI18nizableText

      public static I18nizableText parseI18nizableText(Configuration config, String defaultCatalogue, String defaultValue)
      Parse an optional i18n text configuration, with a default value.
      Parameters:
      config - the configuration to use.
      defaultCatalogue - the i18n catalogue to use when not specified.
      defaultValue - the default value key in configuration.
      Returns:
      the i18n text or null if the config is null
    • parseI18nizableText

      public static I18nizableText parseI18nizableText(Configuration config, String defaultCatalog, I18nizableText defaultValue)
      Parse an optional i18n text configuration, with a default i18n text value.
      Parameters:
      config - the configuration to use.
      defaultCatalog - the i18n catalog to use when not specified.
      defaultValue - the default i18n text value.
      Returns:
      the i18n text or null if the config is null
    • parseI18nizableText

      public static I18nizableText parseI18nizableText(Configuration config, String defaultCatalogue) throws ConfigurationException
      Parse a mandatory i18n text configuration, throwing an exception if empty.
      Parameters:
      config - the configuration to use.
      defaultCatalogue - the i18n catalogue to use when not specified.
      Returns:
      the i18n text or null if the config is null
      Throws:
      ConfigurationException - if the configuration is not valid.
    • i18nizableTextToString

      public static String i18nizableTextToString(I18nizableText i18nizableText)
      Gets a string representation of a i18n text
      Parameters:
      i18nizableText - The i18 text
      Returns:
      The string representation of the i18n text
    • stringToI18nizableText

      Returns the i18n text from its string representation
      Parameters:
      str - The string representation of the i18n text
      Returns:
      The i18n text