Liferay 6.2-ce-ga5

com.liferay.portal.kernel.util
Interface Localization

All Known Implementing Classes:
LocalizationImpl

public interface Localization

Stores and retrieves localized strings from XML, and provides utility methods for updating localizations from JSON, portlet requests, and maps. Used for adding localization to strings, most often for model properties.

Localized values are cached in this class rather than in the value object since value objects get flushed from cache fairly quickly. Though lookups performed on a key based on an XML file are slower than lookups done at the value object level in general, the value object will get flushed at a rate which works against the performance gain. The cache is a soft hash map which prevents memory leaks within the system while enabling the cache to live longer than in a weak hash map.


Method Summary
 Object deserialize(JSONObject jsonObject)
          Deserializes the JSON object into a map of locales and localized strings.
 String[] getAvailableLanguageIds(Document document)
           
 String[] getAvailableLanguageIds(String xml)
          Returns the available locales from the localizations XML.
 Locale getDefaultImportLocale(String className, long classPK, Locale contentDefaultLocale, Locale[] contentAvailableLocales)
          Returns a valid default locale for importing a localized entity.
 String getDefaultLanguageId(Document document)
           
 String getDefaultLanguageId(Document document, Locale defaultLocale)
           
 String getDefaultLanguageId(String xml)
          Returns the default locale from the localizations XML.
 String getDefaultLanguageId(String xml, Locale defaultLocale)
           
 String getLocalization(String xml, String requestedLanguageId)
          Returns the localized string from the localizations XML in the language.
 String getLocalization(String xml, String requestedLanguageId, boolean useDefault)
          Returns the localized string from the localizations XML in the language, optionally using the default language if the no localization exists for the requested language.
 Map<Locale,String> getLocalizationMap(javax.servlet.http.HttpServletRequest request, String parameter)
          Returns a map of locales and localized strings for the parameter in the request.
 Map<Locale,String> getLocalizationMap(PortletPreferences preferences, String parameter)
          Returns a map of locales and localized strings for the parameter in the preferences container.
 Map<Locale,String> getLocalizationMap(PortletRequest portletRequest, String parameter)
          Returns a map of locales and localized strings for the parameter in the portlet request.
 Map<Locale,String> getLocalizationMap(String xml)
          Returns a map of locales and localized strings from the localizations XML.
 Map<Locale,String> getLocalizationMap(String[] languageIds, String[] values)
          Returns a map of locales and localized strings for the given languageIds and values.
 Map<Locale,String> getLocalizationMap(String xml, boolean useDefault)
           
 Map<Locale,String> getLocalizationMap(String bundleName, ClassLoader classLoader, String key, boolean includeBetaLocales)
           
 String getLocalizationXmlFromPreferences(PortletPreferences preferences, PortletRequest portletRequest, String parameter)
          Returns the localizations XML for the parameter in the portlet request, attempting to get data from the preferences container when it is not available in the portlet request.
 String getLocalizationXmlFromPreferences(PortletPreferences preferences, PortletRequest portletRequest, String parameter, String defaultValue)
           
 Map<Locale,String> getLocalizedParameter(PortletRequest portletRequest, String parameter)
          Deprecated. As of 6.2.0, replaced by getLocalizationMap(PortletRequest, String)
 String getPreferencesKey(String key, String languageId)
          Returns the localized preferences key in the language.
 String getPreferencesValue(PortletPreferences preferences, String key, String languageId)
          Returns the localized preferences value for the key in the language.
 String getPreferencesValue(PortletPreferences preferences, String key, String languageId, boolean useDefault)
          Returns the localized preferences value for the key in the language, optionally using the default language if the no localization exists for the requested language.
 String[] getPreferencesValues(PortletPreferences preferences, String key, String languageId)
          Returns the localized preferences values for the key in the language.
 String[] getPreferencesValues(PortletPreferences preferences, String key, String languageId, boolean useDefault)
          Returns the localized preferences values for the key in the language, optionally using the default language if the no localization exists for the requested language.
 String removeLocalization(String xml, String key, String requestedLanguageId)
          Removes the localization for the language from the localizations XML.
 String removeLocalization(String xml, String key, String requestedLanguageId, boolean cdata)
          Removes the localization for the language from the localizations XML, optionally storing the localized strings as CDATA in the XML.
 String removeLocalization(String xml, String key, String requestedLanguageId, boolean cdata, boolean localized)
          Removes the localization for the language from the localizations XML, optionally storing the localized strings as CDATA in the XML.
 void setLocalizedPreferencesValues(PortletRequest portletRequest, PortletPreferences preferences, String parameter)
          Sets the localized preferences values for the parameter in the portlet request.
 void setPreferencesValue(PortletPreferences preferences, String key, String languageId, String value)
          Sets the localized preferences value for the key in the language.
 void setPreferencesValues(PortletPreferences preferences, String key, String languageId, String[] values)
          Sets the localized preferences values for the key in the language.
 String updateLocalization(Map<Locale,String> localizationMap, String xml, String key, String defaultLanguageId)
          Updates the localized string for all the available languages in the localizations XML for the map of locales and localized strings and changes the default language.
 String updateLocalization(String xml, String key, String value)
          Updates the localized string for the system default language in the localizations XML.
 String updateLocalization(String xml, String key, String value, String requestedLanguageId)
          Updates the localized string for the language in the localizations XML.
 String updateLocalization(String xml, String key, String value, String requestedLanguageId, String defaultLanguageId)
          Updates the localized string for the language in the localizations XML and changes the default language.
 String updateLocalization(String xml, String key, String value, String requestedLanguageId, String defaultLanguageId, boolean cdata)
          Updates the localized string for the language in the localizations XML and changes the default language, optionally storing the localized strings as CDATA in the XML.
 String updateLocalization(String xml, String key, String value, String requestedLanguageId, String defaultLanguageId, boolean cdata, boolean localized)
          Updates the localized string for the language in the localizations XML and changes the default language, optionally storing the localized strings as CDATA in the XML.
 

Method Detail

deserialize

Object deserialize(JSONObject jsonObject)
Deserializes the JSON object into a map of locales and localized strings.

Parameters:
jsonObject - the JSON object
Returns:
the locales and localized strings

getAvailableLanguageIds

String[] getAvailableLanguageIds(Document document)

getAvailableLanguageIds

String[] getAvailableLanguageIds(String xml)
Returns the available locales from the localizations XML.

Parameters:
xml - the localizations XML
Returns:
the language IDs of the available locales

getDefaultImportLocale

Locale getDefaultImportLocale(String className,
                              long classPK,
                              Locale contentDefaultLocale,
                              Locale[] contentAvailableLocales)
Returns a valid default locale for importing a localized entity.

Parameters:
className - the class name of the entity
classPK - the primary keys of the entity
contentDefaultLocale - the default Locale of the entity
contentAvailableLocales - the available locales of the entity
Returns:
the valid locale

getDefaultLanguageId

String getDefaultLanguageId(Document document)

getDefaultLanguageId

String getDefaultLanguageId(Document document,
                            Locale defaultLocale)

getDefaultLanguageId

String getDefaultLanguageId(String xml)
Returns the default locale from the localizations XML.

Parameters:
xml - the localizations XML
Returns:
the language ID of the default locale, or the system default locale if the default locale cannot be retrieved from the XML

getDefaultLanguageId

String getDefaultLanguageId(String xml,
                            Locale defaultLocale)

getLocalization

String getLocalization(String xml,
                       String requestedLanguageId)
Returns the localized string from the localizations XML in the language. Uses the default language if no localization exists for the requested language.

Parameters:
xml - the localizations XML
requestedLanguageId - the ID of the language
Returns:
the localized string

getLocalization

String getLocalization(String xml,
                       String requestedLanguageId,
                       boolean useDefault)
Returns the localized string from the localizations XML in the language, optionally using the default language if the no localization exists for the requested language.

Parameters:
xml - the localizations XML
requestedLanguageId - the ID of the language
useDefault - whether to use the default language if no localization exists for the requested language
Returns:
the localized string. If useDefault is false and no localization exists for the requested language, an empty string will be returned.

getLocalizationMap

Map<Locale,String> getLocalizationMap(javax.servlet.http.HttpServletRequest request,
                                      String parameter)
Returns a map of locales and localized strings for the parameter in the request.

Parameters:
request - the request
parameter - the prefix of the parameters containing the localized strings. Each localization will be loaded from a parameter with this prefix, followed by an underscore, and the language ID.
Returns:
the locales and localized strings

getLocalizationMap

Map<Locale,String> getLocalizationMap(PortletPreferences preferences,
                                      String parameter)
Returns a map of locales and localized strings for the parameter in the preferences container.

Parameters:
preferences - the preferences container
parameter - the prefix of the parameters containing the localized strings. Each localization will be loaded from a parameter with this prefix, followed by an underscore, and the language ID.
Returns:
the locales and localized strings

getLocalizationMap

Map<Locale,String> getLocalizationMap(PortletRequest portletRequest,
                                      String parameter)
Returns a map of locales and localized strings for the parameter in the portlet request.

Parameters:
portletRequest - the portlet request
parameter - the prefix of the parameters containing the localized strings. Each localization will be loaded from a parameter with this prefix, followed by an underscore, and the language ID.
Returns:
the locales and localized strings

getLocalizationMap

Map<Locale,String> getLocalizationMap(String xml)
Returns a map of locales and localized strings from the localizations XML.

Parameters:
xml - the localizations XML
Returns:
the locales and localized strings

getLocalizationMap

Map<Locale,String> getLocalizationMap(String xml,
                                      boolean useDefault)

getLocalizationMap

Map<Locale,String> getLocalizationMap(String bundleName,
                                      ClassLoader classLoader,
                                      String key,
                                      boolean includeBetaLocales)

getLocalizationMap

Map<Locale,String> getLocalizationMap(String[] languageIds,
                                      String[] values)
Returns a map of locales and localized strings for the given languageIds and values.

Parameters:
languageIds - the languageIds of the localized Strings
values - the localized strings for the different languageId
Returns:
the map of locales and values for the given parameters

getLocalizationXmlFromPreferences

String getLocalizationXmlFromPreferences(PortletPreferences preferences,
                                         PortletRequest portletRequest,
                                         String parameter)
Returns the localizations XML for the parameter in the portlet request, attempting to get data from the preferences container when it is not available in the portlet request.

Parameters:
preferences - the preferences container
portletRequest - the portlet request
parameter - the prefix of the parameters containing the localized strings. Each localization will be loaded from a parameter with this prefix, followed by an underscore, and the language ID.
Returns:
the locales and localized strings

getLocalizationXmlFromPreferences

String getLocalizationXmlFromPreferences(PortletPreferences preferences,
                                         PortletRequest portletRequest,
                                         String parameter,
                                         String defaultValue)

getLocalizedParameter

Map<Locale,String> getLocalizedParameter(PortletRequest portletRequest,
                                         String parameter)
Deprecated. As of 6.2.0, replaced by getLocalizationMap(PortletRequest, String)


getPreferencesKey

String getPreferencesKey(String key,
                         String languageId)
Returns the localized preferences key in the language. Generally this is just the preferences key, followed by an underscore, and the language ID.

Parameters:
key - the preferences key
languageId - the ID of the language
Returns:
the localized preferences key

getPreferencesValue

String getPreferencesValue(PortletPreferences preferences,
                           String key,
                           String languageId)
Returns the localized preferences value for the key in the language. Uses the default language if no localization exists for the requested language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
Returns:
the localized preferences value

getPreferencesValue

String getPreferencesValue(PortletPreferences preferences,
                           String key,
                           String languageId,
                           boolean useDefault)
Returns the localized preferences value for the key in the language, optionally using the default language if the no localization exists for the requested language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
useDefault - whether to use the default language if no localization exists for the requested language
Returns:
the localized preferences value. If useDefault is false and no localization exists for the requested language, an empty string will be returned.

getPreferencesValues

String[] getPreferencesValues(PortletPreferences preferences,
                              String key,
                              String languageId)
Returns the localized preferences values for the key in the language. Uses the default language if no localization exists for the requested language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
Returns:
the localized preferences values

getPreferencesValues

String[] getPreferencesValues(PortletPreferences preferences,
                              String key,
                              String languageId,
                              boolean useDefault)
Returns the localized preferences values for the key in the language, optionally using the default language if the no localization exists for the requested language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
useDefault - whether to use the default language if no localization exists for the requested language
Returns:
the localized preferences values. If useDefault is false and no localization exists for the requested language, an empty array will be returned.

removeLocalization

String removeLocalization(String xml,
                          String key,
                          String requestedLanguageId)
Removes the localization for the language from the localizations XML. Stores the localized strings as characters in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
requestedLanguageId - the ID of the language
Returns:
the localizations XML with the language removed

removeLocalization

String removeLocalization(String xml,
                          String key,
                          String requestedLanguageId,
                          boolean cdata)
Removes the localization for the language from the localizations XML, optionally storing the localized strings as CDATA in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
requestedLanguageId - the ID of the language
cdata - whether to store localized strings as CDATA in the XML
Returns:
the localizations XML with the language removed

removeLocalization

String removeLocalization(String xml,
                          String key,
                          String requestedLanguageId,
                          boolean cdata,
                          boolean localized)
Removes the localization for the language from the localizations XML, optionally storing the localized strings as CDATA in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
requestedLanguageId - the ID of the language
cdata - whether to store localized strings as CDATA in the XML
localized - whether there is a localized field
Returns:
the localizations XML with the language removed

setLocalizedPreferencesValues

void setLocalizedPreferencesValues(PortletRequest portletRequest,
                                   PortletPreferences preferences,
                                   String parameter)
                                   throws Exception
Sets the localized preferences values for the parameter in the portlet request.

Parameters:
portletRequest - the portlet request
preferences - the preferences container
parameter - the prefix of the parameters containing the localized strings. Each localization will be loaded from a parameter with this prefix, followed by an underscore, and the language ID.
Throws:
Exception - if an exception occurred

setPreferencesValue

void setPreferencesValue(PortletPreferences preferences,
                         String key,
                         String languageId,
                         String value)
                         throws Exception
Sets the localized preferences value for the key in the language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
value - the localized value
Throws:
Exception - if an exception occurred

setPreferencesValues

void setPreferencesValues(PortletPreferences preferences,
                          String key,
                          String languageId,
                          String[] values)
                          throws Exception
Sets the localized preferences values for the key in the language.

Parameters:
preferences - the preferences container
key - the preferences key
languageId - the ID of the language
values - the localized values
Throws:
Exception - if an exception occurred

updateLocalization

String updateLocalization(Map<Locale,String> localizationMap,
                          String xml,
                          String key,
                          String defaultLanguageId)
Updates the localized string for all the available languages in the localizations XML for the map of locales and localized strings and changes the default language. Stores the localized strings as characters in the XML.

Parameters:
localizationMap - the locales and localized strings
xml - the localizations XML
key - the name of the localized string, such as "Title"
defaultLanguageId - the ID of the default language
Returns:
the updated localizations XML

updateLocalization

String updateLocalization(String xml,
                          String key,
                          String value)
Updates the localized string for the system default language in the localizations XML. Stores the localized strings as characters in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
value - the localized string
Returns:
the updated localizations XML

updateLocalization

String updateLocalization(String xml,
                          String key,
                          String value,
                          String requestedLanguageId)
Updates the localized string for the language in the localizations XML. Stores the localized strings as characters in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the ID of the language
Returns:
the updated localizations XML

updateLocalization

String updateLocalization(String xml,
                          String key,
                          String value,
                          String requestedLanguageId,
                          String defaultLanguageId)
Updates the localized string for the language in the localizations XML and changes the default language. Stores the localized strings as characters in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the ID of the language
defaultLanguageId - the ID of the default language
Returns:
the updated localizations XML

updateLocalization

String updateLocalization(String xml,
                          String key,
                          String value,
                          String requestedLanguageId,
                          String defaultLanguageId,
                          boolean cdata)
Updates the localized string for the language in the localizations XML and changes the default language, optionally storing the localized strings as CDATA in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the ID of the language
defaultLanguageId - the ID of the default language
cdata - whether to store localized strings as CDATA in the XML
Returns:
the updated localizations XML

updateLocalization

String updateLocalization(String xml,
                          String key,
                          String value,
                          String requestedLanguageId,
                          String defaultLanguageId,
                          boolean cdata,
                          boolean localized)
Updates the localized string for the language in the localizations XML and changes the default language, optionally storing the localized strings as CDATA in the XML.

Parameters:
xml - the localizations XML
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the ID of the language
defaultLanguageId - the ID of the default language
cdata - whether to store localized strings as CDATA in the XML
localized - whether there is a localized field
Returns:
the updated localizations XML

Liferay 6.2-ce-ga5