Package org.ametys.runtime.i18n
Class I18nizableText
- java.lang.Object
-
- org.ametys.runtime.i18n.I18nizableText
-
public final class I18nizableText extends Object
This class wraps a text that may be internationalized.
-
-
Field Summary
Fields Modifier and Type Field Description private String_catalogueprivate String_catalogueBundleNameprivate String_catalogueLocationprivate String_directLabelprivate boolean_i18nprivate String_keyprivate Map<String,I18nizableText>_parameterMapprivate List<String>_parameters
-
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,I18nizableText> 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,I18nizableText> parameters)Create an i18nized text with named parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void_toSAXAsParam(ContentHandler handler)booleanequals(Object obj)StringgetBundleName()Get the files name of catalogStringgetCatalogue()Get the catalogue of the i18nized text.static I18nizableTextgetI18nizableTextValue(Configuration config, String defaultCatalogue, String value)Get an i18n text configuration (can be a key or a "direct" string).private static I18nizableTextgetI18nizableTextValue(Configuration config, String catalogueLocation, String catalogueFilename, String value)Get an i18n text configuration (can be a key or a "direct" string).StringgetKey()Get the key of the i18nized text.StringgetLabel()Get the label if a text is not i18nized.StringgetLocation()Get the file location URI of the i18nized text.Map<String,I18nizableText>getParameterMap()Get the parameters of the key of the i18nized text.List<String>getParameters()Get the parameters of the key of the i18nized text.inthashCode()static Stringi18nizableTextToString(I18nizableText i18nizableText)Gets a string representation of a i18n textbooleanisI18n()Determine whether the text is i18nized or a simple cross languages text.private static booleanisI18n(Configuration config)static I18nizableTextparseI18nizableText(Configuration config, String defaultCatalogue)Parse a mandatory i18n text configuration, throwing an exception if empty.static I18nizableTextparseI18nizableText(Configuration config, String defaultCatalogue, String defaultValue)Parse an optional i18n text configuration, with a default value.static I18nizableTextparseI18nizableText(Configuration config, String catalogueLocation, String catalogueFilename, String defaultValue)Parse a i18n text configuration.static I18nizableTextparseI18nizableText(Configuration config, String defaultCatalog, I18nizableText defaultValue)Parse an optional i18n text configuration, with a default i18n text value.static I18nizableTextstringToI18nizableText(String str)Returns the i18n text from its string representationvoidtoSAX(ContentHandler handler)SAX a textvoidtoSAX(ContentHandler handler, String tagName)SAX a textStringtoString()
-
-
-
Field Detail
-
_i18n
private final boolean _i18n
-
_directLabel
private String _directLabel
-
_catalogue
private String _catalogue
-
_parameters
private List<String> _parameters
-
_parameterMap
private Map<String,I18nizableText> _parameterMap
-
_catalogueLocation
private String _catalogueLocation
-
_catalogueBundleName
private String _catalogueBundleName
-
-
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,I18nizableText> 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,I18nizableText> 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,I18nizableText> 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
SAX a text- Parameters:
handler- The sax content handler- Throws:
SAXException- if an error occurs
-
toSAX
public void toSAX(ContentHandler handler, String tagName) throws SAXException
SAX a text- Parameters:
handler- The sax content handlertagName- The tag name- Throws:
SAXException- if an error occurs
-
_toSAXAsParam
private void _toSAXAsParam(ContentHandler handler) throws SAXException
- Throws:
SAXException
-
isI18n
private static boolean isI18n(Configuration config)
-
getI18nizableTextValue
private static I18nizableText getI18nizableTextValue(Configuration config, String catalogueLocation, String catalogueFilename, String value)
Get an i18n text configuration (can be a key or a "direct" string).- Parameters:
config- The configuration to parse.catalogueLocation- The i18n catalogue location URIcatalogueFilename- The i18n catalogue bundle namevalue- The i18n text, can be a key or a "direct" string.- Returns:
- The i18nizable text
-
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
-
-