Class MultilingualStringHelper
- java.lang.Object
-
- org.ametys.plugins.repository.metadata.MultilingualStringHelper
-
public final class MultilingualStringHelper extends Object
Helper methods forMultilingualStringmetadata
-
-
Field Summary
Fields Modifier and Type Field Description private static String__ENTRIES_SEPARATORThe separator between the entries for the string representation of a multilingual stringprivate static String__LOCALE_AND_VALUE_SEPARATORThe separator between the locale and the value for the string representation of a multilingual stringstatic LocaleDEFAULT_LOCALEThe default locale
-
Constructor Summary
Constructors Modifier Constructor Description privateMultilingualStringHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MultilingualStringfromJSON(Map<String,? extends Object> json)Get theMultilingualStringobject from its JSON representationstatic MultilingualStringfromString(String string)Retrieves theMultilingualStringfrom its string representationstatic MultilingualStringfromXML(Element element)Get 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.static List<Locale>localeLookupList(Locale locale)Return the list of closest locales to searchstatic 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 stringstatic Map<String,Object>toJson(MultilingualString multilingualString)Get the JSON representation of aMultilingualStringstatic StringtoString(MultilingualString multilingualString)Retrieves a string representation of aMultilingualString
-
-
-
Field Detail
-
DEFAULT_LOCALE
public static final Locale DEFAULT_LOCALE
The default locale
-
__LOCALE_AND_VALUE_SEPARATOR
private static final String __LOCALE_AND_VALUE_SEPARATOR
The separator between the locale and the value for the string representation of a multilingual string- See Also:
- Constant Field Values
-
__ENTRIES_SEPARATOR
private static final String __ENTRIES_SEPARATOR
The separator between the entries for the string representation of a multilingual string- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MultilingualStringHelper
private MultilingualStringHelper()
-
-
Method Detail
-
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
public static List<Locale> localeLookupList(Locale locale)
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
public static MultilingualString fromXML(Element element) throws TransformerException
Get theMultilingualStringobject from the givenNode- Parameters:
element- the DOM element containing the multilingual string data- Returns:
- the
MultilingualStringobject - Throws:
TransformerException- if an error occurs while parsing the DOM node
-
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
public static MultilingualString fromJSON(Map<String,? extends Object> json)
Get theMultilingualStringobject from its JSON representation- Parameters:
json- the JSON representation of the multilingual string- Returns:
- the
MultilingualStringobject
-
toString
public static String toString(MultilingualString multilingualString)
Retrieves a string representation of aMultilingualString- Parameters:
multilingualString- the multilingual string- Returns:
- thestring representation of the multilingual string
-
fromString
public static MultilingualString fromString(String string) throws IllegalArgumentException
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
-
-