Package org.ametys.runtime.i18n
Class I18nizableText
java.lang.Object
org.ametys.runtime.i18n.I18nizableText
- All Implemented Interfaces:
I18nizable
,I18nizableTextParameter
This class wraps a text that may be internationalized.
-
Constructor Summary
ConstructorDescriptionI18nizableText
(String label) Create a simple international textI18nizableText
(String catalogue, String key) Create an i18nized textI18nizableText
(String catalogueLocation, String catalogueFilename, String key) Create an i18nized text.I18nizableText
(String catalogueLocation, String catalogueFilename, String key, List<String> parameters) Create an i18nized text with ordered parameters.I18nizableText
(String catalogueLocation, String catalogueFilename, String key, Map<String, I18nizableTextParameter> parameters) Create an i18nized text with named parameters.I18nizableText
(String catalogue, String key, List<String> parameters) Create an i18nized text with ordered parameters.I18nizableText
(String catalogue, String key, Map<String, I18nizableTextParameter> parameters) Create an i18nized text with named parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Get the files name of catalogueGet the catalogue of the i18nized text.static I18nizableText
getI18nizableTextValue
(Configuration config, String defaultCatalogue, String value) Get an i18n text configuration (can be a key or a "direct" string).getKey()
Get the key of the i18nized text.getLabel()
Get the label if a text is not i18nized.Get the file location URI of the i18nized text.Get the parameters of the key of the i18nized text.Get the parameters of the key of the i18nized text.int
hashCode()
static String
i18nizableTextToString
(I18nizableText i18nizableText) Gets a string representation of a i18n textboolean
isI18n()
Determine whether the text is i18nized or a simple cross languages text.static boolean
isI18n
(Configuration config) Check if configuration is an i18nizable textstatic I18nizableText
parseI18nizableText
(Configuration config, String defaultCatalogue) Parse a mandatory i18n text configuration, throwing an exception if empty.static I18nizableText
parseI18nizableText
(Configuration config, String defaultCatalogue, String defaultValue) Parse an optional i18n text configuration, with a default value.static I18nizableText
parseI18nizableText
(Configuration config, String catalogueLocation, String catalogueFilename, String defaultValue) Parse a i18n text configuration.static I18nizableText
parseI18nizableText
(Configuration config, String defaultCatalogue, I18nizableText defaultValue) Parse an optional i18n text configuration, with a default i18n text value.static I18nizableText
Returns the i18n text from its string representationvoid
toSAX
(ContentHandler handler) Represents thisI18nizable
as SAX events.void
toSAXAsParam
(ContentHandler handler) Represents thisI18nizableTextParameter
as SAX events for anI18nizableText
parameter.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.ametys.runtime.i18n.I18nizable
toSAX
-
Constructor Details
-
I18nizableText
Create a simple international text- Parameters:
label
- The text. Cannot be null.
-
I18nizableText
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
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
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
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
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
Get the catalogue of the i18nized text.- Returns:
- The catalogue where the key is defined
-
getLocation
Get the file location URI of the i18nized text.- Returns:
- The catalogue location where the key is defined
-
getBundleName
Get the files name of catalogue- Returns:
- bundle name
-
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
Get the label if a text is not i18nized.- Returns:
- The label
-
toSAX
Description copied from interface:I18nizable
Represents thisI18nizable
as SAX events.- Specified by:
toSAX
in interfaceI18nizable
- Parameters:
handler
- the SAX content handler- Throws:
SAXException
- if an error occurs
-
toSAXAsParam
Description copied from interface:I18nizableTextParameter
Represents thisI18nizableTextParameter
as SAX events for anI18nizableText
parameter.- Specified by:
toSAXAsParam
in interfaceI18nizableTextParameter
- Parameters:
handler
- the SAX content handler- Throws:
SAXException
- if an error occurs
-
toString
-
hashCode
-
equals
-
isI18n
Check if configuration is an i18nizable text- Parameters:
config
- the config to check- Returns:
- true if the config is an I18n
-
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) Parse a i18n text configuration.- Parameters:
config
- the configuration to use.catalogueLocation
- The i18n catalogue location URIcatalogueFilename
- The i18n catalogue bundle namedefaultValue
- 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 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 defaultCatalogue, I18nizableText defaultValue) Parse an optional i18n text configuration, with a default i18n text value.- Parameters:
config
- the configuration to use.defaultCatalogue
- the i18n catalogue 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
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
-