Class MultilingualStringHelper
java.lang.Object
org.ametys.plugins.repository.metadata.MultilingualStringHelper
Helper methods for
MultilingualString
metadata-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MultilingualString
Get theMultilingualString
object from its JSON representationstatic MultilingualString
fromString
(String string) Retrieves theMultilingualString
from its string representationstatic MultilingualString
Get theMultilingualString
object from the givenNode
static Locale
getClosestNonEmptyLocale
(MultilingualString multilingualString, Locale locale) Returns the closest non-empty locale for aMultilingualString
in a given locale.static String
getValue
(ModelAwareDataHolder dataHolder, String dataName, Locale locale) Returns the closest non-empty value for aMultilingualString
element in a given locale.static String
getValue
(ModelLessDataHolder dataHolder, String dataName, Locale locale) Returns the closest non-empty value for aMultilingualString
element in a given locale.static String
getValue
(CompositeMetadata parentMetadata, String metadataName, Locale locale) Deprecated.static String
getValue
(MultilingualString multilingualString, Locale locale) Returns the closest non-empty value for aMultilingualString
in a given locale.localeLookupList
(Locale locale) Return the list of closest locales to searchstatic boolean
Check if a given string matches the Multilingual string patternstatic void
sax
(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, Locale locale) Deprecated.static void
sax
(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, AttributesImpl attributes, Locale locale) Saxes the given multilingual stringtoJson
(MultilingualString multilingualString) Get the JSON representation of aMultilingualString
static String
toString
(MultilingualString multilingualString) Retrieves a string representation of aMultilingualString
-
Field Details
-
DEFAULT_LOCALE
The default locale
-
-
Method Details
-
getValue
@Deprecated public static String getValue(CompositeMetadata parentMetadata, String metadataName, Locale locale) throws AmetysRepositoryException Deprecated.Returns the closest non-empty value for aMultilingualString
metadata in a given locale. If no close locale is found, return the value forLocale.ENGLISH
if exists.
Otherwise, the value of first stored locale will be returned.- Parameters:
parentMetadata
- The metadata holdermetadataName
- The metadata namelocale
- The requested locale- Returns:
- the closest non-empty localized value or
null
if not found. - Throws:
AmetysRepositoryException
- if an errors occurs.
-
getValue
public static String getValue(ModelLessDataHolder dataHolder, String dataName, Locale locale) throws AmetysRepositoryException Returns the closest non-empty value for aMultilingualString
element in a given locale. If no close locale is found, return the value forLocale.ENGLISH
if exists.
Otherwise, the value of first stored locale will be returned.- Parameters:
dataHolder
- data holderdataName
- The data namelocale
- The requested locale- Returns:
- the closest non-empty localized value or
null
if not found. - Throws:
AmetysRepositoryException
- if an errors occurs.
-
getValue
public static String getValue(ModelAwareDataHolder dataHolder, String dataName, Locale locale) throws AmetysRepositoryException Returns the closest non-empty value for aMultilingualString
element in a given locale. If no close locale is found, return the value forLocale.ENGLISH
if exists.
Otherwise, the value of first stored locale will be returned.- Parameters:
dataHolder
- The data holderdataName
- The data namelocale
- The requested locale- Returns:
- the closest non-empty localized value or
null
if not found. - Throws:
AmetysRepositoryException
- if an errors occurs.
-
getValue
public static String getValue(MultilingualString multilingualString, Locale locale) throws AmetysRepositoryException Returns the closest non-empty value for aMultilingualString
in a given locale. If no close locale is found, return the value forLocale.ENGLISH
if exists.
Otherwise, the value of first stored locale will be returned.- Parameters:
multilingualString
- The multilingual stringlocale
- The requested locale. Can be null.- Returns:
- the closest non-empty localized value or
null
if not found. - Throws:
AmetysRepositoryException
- if an errors occurs.
-
getClosestNonEmptyLocale
public static Locale getClosestNonEmptyLocale(MultilingualString multilingualString, Locale locale) throws AmetysRepositoryException Returns the closest non-empty locale for aMultilingualString
in a given locale. If no close locale is found, return theLocale.ENGLISH
if a values exists.
Otherwise, the first stored locale will be returned.- Parameters:
multilingualString
- The multilingual stringlocale
- The requested locale. Can be null.- Returns:
- the closest non-empty locale or
null
if not found. - Throws:
AmetysRepositoryException
- if an errors occurs.
-
localeLookupList
Return the list of closest locales to search- Parameters:
locale
- the locale to start from. If null, returns the default locale- Returns:
- the unmodifiable list of Locale objects, 0 being locale, not null
-
sax
@Deprecated public static void sax(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, Locale locale) throws SAXException Deprecated.Saxes the given multilingual string- Parameters:
contentHandler
- the content handler where to SAX into.tagName
- the name of the tag to sax the multilingual stringmultilingualString
- the multilingual string to saxlocale
- the requested locale. Can be null.- Throws:
SAXException
- if an errors occurs during the value saxing
-
sax
public static void sax(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, AttributesImpl attributes, Locale locale) throws SAXException Saxes the given multilingual string- Parameters:
contentHandler
- the content handler where to SAX into.tagName
- the name of the tag to sax the multilingual stringmultilingualString
- the multilingual string to saxattributes
- the attributes to sax the multilingual stringlocale
- the requested locale. Can be null.- Throws:
SAXException
- if an errors occurs during the value saxing
-
fromXML
Get theMultilingualString
object from the givenNode
- Parameters:
element
- the DOM element containing the multilingual string data- Returns:
- the
MultilingualString
object
-
toJson
public static Map<String,Object> toJson(MultilingualString multilingualString) throws AmetysRepositoryException Get the JSON representation of aMultilingualString
- Parameters:
multilingualString
- The multilingual string. Cannot be null.- Returns:
- A map with the locales and values.
- Throws:
AmetysRepositoryException
- if an error occurs
-
fromJSON
Get theMultilingualString
object from its JSON representation- Parameters:
json
- the JSON representation of the multilingual string- Returns:
- the
MultilingualString
object
-
toString
Retrieves a string representation of aMultilingualString
- Parameters:
multilingualString
- the multilingual string- Returns:
- thestring representation of the multilingual string
-
fromString
Retrieves theMultilingualString
from its string representation- Parameters:
string
- the string representation of the multilingual string- Returns:
- the multilingual string from its string representation, or
null
if the given string value is null or empty - Throws:
IllegalArgumentException
- if the given string value can't be cast to a multilingual string
-
matchesMultilingualStringPattern
Check if a given string matches the Multilingual string pattern- Parameters:
string
- the string representation of the multilingual string to check- Returns:
true
if the string have a correct pattern,false
otherwise
-
getValue(ModelAwareDataHolder, String, Locale)
orgetValue(ModelLessDataHolder, String, Locale)
instead