Class MultilingualStringHelper
java.lang.Object
org.ametys.plugins.repository.metadata.MultilingualStringHelper
Helper methods for
MultilingualString metadata-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MultilingualStringGet theMultilingualStringobject from its JSON representationstatic MultilingualStringfromString(String string) Retrieves theMultilingualStringfrom its string representationstatic MultilingualStringGet theMultilingualStringobject from the givenNodestatic LocalegetClosestNonEmptyLocale(MultilingualString multilingualString, Locale locale) Returns the closest non-empty locale for aMultilingualStringin a given locale.static StringgetValue(ModelAwareDataHolder dataHolder, String dataName, Locale locale) Returns the closest non-empty value for aMultilingualStringelement in a given locale.static StringgetValue(ModelLessDataHolder dataHolder, String dataName, Locale locale) Returns the closest non-empty value for aMultilingualStringelement in a given locale.static StringgetValue(CompositeMetadata parentMetadata, String metadataName, Locale locale) Deprecated.static StringgetValue(MultilingualString multilingualString, Locale locale) Returns the closest non-empty value for aMultilingualStringin a given locale.localeLookupList(Locale locale) Return the list of closest locales to searchstatic booleanCheck if a given string matches the Multilingual string patternstatic voidsax(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, Locale locale) Deprecated.static voidsax(ContentHandler contentHandler, String tagName, MultilingualString multilingualString, AttributesImpl attributes, Locale locale) Saxes the given multilingual stringtoJson(MultilingualString multilingualString) Get the JSON representation of aMultilingualStringstatic StringtoString(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 aMultilingualStringmetadata in a given locale. If no close locale is found, return the value forLocale.ENGLISHif 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
nullif 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 aMultilingualStringelement in a given locale. If no close locale is found, return the value forLocale.ENGLISHif 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
nullif 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 aMultilingualStringelement in a given locale. If no close locale is found, return the value forLocale.ENGLISHif 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
nullif 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 aMultilingualStringin a given locale. If no close locale is found, return the value forLocale.ENGLISHif 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
nullif 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 aMultilingualStringin a given locale. If no close locale is found, return theLocale.ENGLISHif 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
nullif 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 theMultilingualStringobject from the givenNode- Parameters:
element- the DOM element containing the multilingual string data- Returns:
- the
MultilingualStringobject
-
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 theMultilingualStringobject from its JSON representation- Parameters:
json- the JSON representation of the multilingual string- Returns:
- the
MultilingualStringobject
-
toString
Retrieves a string representation of aMultilingualString- Parameters:
multilingualString- the multilingual string- Returns:
- thestring representation of the multilingual string
-
fromString
Retrieves theMultilingualStringfrom its string representation- Parameters:
string- the string representation of the multilingual string- Returns:
- the multilingual string from its string representation, or
nullif 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:
trueif the string have a correct pattern,falseotherwise
-
getValue(ModelAwareDataHolder, String, Locale)orgetValue(ModelLessDataHolder, String, Locale)instead