Class MultilingualStringHelper
- java.lang.Object
- 
- org.ametys.plugins.repository.metadata.MultilingualStringHelper
 
- 
 public final class MultilingualStringHelper extends Object Helper methods forMultilingualStringmetadata
- 
- 
Field SummaryFields Modifier and Type Field Description static LocaleDEFAULT_LOCALEThe default locale
 - 
Method SummaryAll 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 booleanmatchesMultilingualStringPattern(String string)Check 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 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_LOCALEpublic static final Locale DEFAULT_LOCALE The default locale
 
- 
 - 
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 holder
- metadataName- The metadata name
- locale- The requested locale
- Returns:
- the closest non-empty localized value or nullif not found.
- Throws:
- AmetysRepositoryException- if an errors occurs.
 
 - 
getValuepublic 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 holder
- dataName- The data name
- locale- The requested locale
- Returns:
- the closest non-empty localized value or nullif not found.
- Throws:
- AmetysRepositoryException- if an errors occurs.
 
 - 
getValuepublic 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 holder
- dataName- The data name
- locale- The requested locale
- Returns:
- the closest non-empty localized value or nullif not found.
- Throws:
- AmetysRepositoryException- if an errors occurs.
 
 - 
getValuepublic 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 string
- locale- The requested locale. Can be null.
- Returns:
- the closest non-empty localized value or nullif not found.
- Throws:
- AmetysRepositoryException- if an errors occurs.
 
 - 
getClosestNonEmptyLocalepublic 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 string
- locale- The requested locale. Can be null.
- Returns:
- the closest non-empty locale or nullif not found.
- Throws:
- AmetysRepositoryException- if an errors occurs.
 
 - 
localeLookupListpublic 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 string
- multilingualString- the multilingual string to sax
- locale- the requested locale. Can be null.
- Throws:
- SAXException- if an errors occurs during the value saxing
 
 - 
saxpublic 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 string
- multilingualString- the multilingual string to sax
- attributes- the attributes to sax the multilingual string
- locale- the requested locale. Can be null.
- Throws:
- SAXException- if an errors occurs during the value saxing
 
 - 
fromXMLpublic static MultilingualString fromXML(Element element) Get theMultilingualStringobject from the givenNode- Parameters:
- element- the DOM element containing the multilingual string data
- Returns:
- the MultilingualStringobject
 
 - 
toJsonpublic 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
 
 - 
fromJSONpublic 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
 
 - 
toStringpublic static String toString(MultilingualString multilingualString) Retrieves a string representation of aMultilingualString- Parameters:
- multilingualString- the multilingual string
- Returns:
- thestring representation of the multilingual string
 
 - 
fromStringpublic 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
 
 - 
matchesMultilingualStringPatternpublic static boolean matchesMultilingualStringPattern(String string) 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
 
 
- 
 
-