Package org.ametys.runtime.i18n
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 Summary
Constructors Constructor Description I18nizableText(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
String
getBundleName()
Get the files name of catalogString
getCatalogue()
Get 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).String
getKey()
Get the key of the i18nized text.String
getLabel()
Get the label if a text is not i18nized.String
getLocation()
Get the file location URI of the i18nized text.Map<String,I18nizableTextParameter>
getParameterMap()
Get the parameters of the key of the i18nized text.List<String>
getParameters()
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 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 defaultCatalog, I18nizableText defaultValue)
Parse an optional i18n text configuration, with a default i18n text value.static I18nizableText
stringToI18nizableText(String str)
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.String
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 Detail
-
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 Detail
-
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
public String getBundleName()
Get the files name of catalog- Returns:
- bundle name
-
getParameters
public List<String> 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
public Map<String,I18nizableTextParameter> getParameterMap()
Get the parameters of the key of the i18nized text.- Returns:
- The list of parameters' values or null if there is no parameters
-
toSAX
public void toSAX(ContentHandler handler) throws SAXException
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
public void toSAXAsParam(ContentHandler handler) throws SAXException
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
-
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 URIcatalogueFilename
- The i18n catalog bundle namedefaultValue
- 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
public static I18nizableText stringToI18nizableText(String str)
Returns the i18n text from its string representation- Parameters:
str
- The string representation of the i18n text- Returns:
- The i18n text
-
-