|
Liferay 6.0.5 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.
Caching of the localized values is done 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 is 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[] |
getAvailableLocales(String xml)
Gets the available locales from the localizations XML |
String |
getDefaultLocale(String xml)
Gets the default locale from the localizations XML. |
String |
getLocalization(String xml,
String requestedLanguageId)
Gets the localized string from the localizations XML. |
String |
getLocalization(String xml,
String requestedLanguageId,
boolean useDefault)
Gets the localized string from the localizations XML, optionally using the default language if the no localization exists for the requested language. |
Map<Locale,String> |
getLocalizationMap(PortletRequest portletRequest,
String parameter)
Gets a map of locales and localized strings for the parameter in the portlet request. |
Map<Locale,String> |
getLocalizationMap(String xml)
Gets a map of locales and localized strings from the localizations XML. |
String |
getLocalizationXmlFromPreferences(PortletPreferences preferences,
PortletRequest portletRequest,
String parameter)
Gets an xml of locales and localized strings for the parameter in the portlet request. |
Map<Locale,String> |
getLocalizedParameter(PortletRequest portletRequest,
String parameter)
Deprecated. use getLocalizationMap(PortletRequest, String)
instead. |
String |
getPreferencesValue(PortletPreferences preferences,
String key,
String languageId)
Gets the localized preferences value for the key. |
String |
getPreferencesValue(PortletPreferences preferences,
String key,
String languageId,
boolean useDefault)
Gets the localized preferences value for the key, optionally using the default language if the no localization exists for the requested language. |
String[] |
getPreferencesValues(PortletPreferences preferences,
String key,
String languageId)
Gets the localized preferences values for the key. |
String[] |
getPreferencesValues(PortletPreferences preferences,
String key,
String languageId,
boolean useDefault)
Gets the localized preferences values for the key, 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. |
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. |
void |
setPreferencesValues(PortletPreferences preferences,
String key,
String languageId,
String[] values)
Sets the localized preferences values for the key. |
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. |
Method Detail |
---|
Object deserialize(JSONObject jsonObject)
jsonObject
- the JSON object to deserialize
String[] getAvailableLocales(String xml)
xml
- the localizations XML to get the available locales from
String getDefaultLocale(String xml)
xml
- the localizations XML to get the default locale from
String getLocalization(String xml, String requestedLanguageId)
xml
- the localizations XML to get the localized string fromrequestedLanguageId
- the id of the language to get the
localization for
String getLocalization(String xml, String requestedLanguageId, boolean useDefault)
xml
- the localizations XML to get the localized string fromrequestedLanguageId
- the id of the language to get the
localization foruseDefault
- whether to use the default language if no localization
exists for the requested language
useDefault
is
false
and no localization exists for the requested
language, an empty string will be returned.Map<Locale,String> getLocalizationMap(PortletRequest portletRequest, String parameter)
portletRequest
- the portlet request to get the locales and
localized strings fromparameter
- 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.
Map<Locale,String> getLocalizationMap(String xml)
xml
- the localizations XML to get the locales and localized
strings from
String getLocalizationXmlFromPreferences(PortletPreferences preferences, PortletRequest portletRequest, String parameter)
preferences
- the preferences container to get the localized value
fromportletRequest
- the portlet request to get the locales and
localized strings fromparameter
- 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.
Map<Locale,String> getLocalizedParameter(PortletRequest portletRequest, String parameter)
getLocalizationMap(PortletRequest, String)
instead.
String getPreferencesValue(PortletPreferences preferences, String key, String languageId)
preferences
- the preferences container to get the localized value
fromkey
- the preferences key to get the localized value forlanguageId
- the id of the language to get the localization for
String getPreferencesValue(PortletPreferences preferences, String key, String languageId, boolean useDefault)
preferences
- the preferences container to get the localized value
fromkey
- the preferences key to get the localized value forlanguageId
- the id of the language to get the localization foruseDefault
- whether to use the default language if no localization
exists for the requested language
useDefault
is
false
and no localization exists for the requested
language, an empty string will be returned.String[] getPreferencesValues(PortletPreferences preferences, String key, String languageId)
preferences
- the preferences container to get the localized values
fromkey
- the preferences key to get localized values forlanguageId
- the id of the language to get the localizations for
String[] getPreferencesValues(PortletPreferences preferences, String key, String languageId, boolean useDefault)
preferences
- the preferences container to get the localized values
fromkey
- the preferences key to get localized values forlanguageId
- the id of the language to get the localizations foruseDefault
- whether to use the default language if no localization
exists for the requested language
useDefault
is
false
and no localization exists for the requested
language, an empty array will be returned.String removeLocalization(String xml, String key, String requestedLanguageId)
xml
- the localizations XML to remove the localization for the
language fromkey
- the name of the localized string, such as "Title"requestedLanguageId
- the id of the language to remove from the
localizations XML
String removeLocalization(String xml, String key, String requestedLanguageId, boolean cdata)
xml
- the localizations XML to remove the localization for the
language fromkey
- the name of the localized string, such as "Title"requestedLanguageId
- the id of the language to remove from the
localizations XMLcdata
- whether to store localized strings as CDATA in the XML
void setLocalizedPreferencesValues(PortletRequest portletRequest, PortletPreferences preferences, String parameter) throws Exception
portletRequest
- the portlet request to get the localized values
frompreferences
- the preferences container to set the localized values
inparameter
- 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.
Exception
- if an exception occurredvoid setPreferencesValue(PortletPreferences preferences, String key, String languageId, String value) throws Exception
preferences
- the preferences container to store the localized
value inkey
- the preferences key to set the localized value forlanguageId
- the id of the language to set the localization forvalue
- the localized value
Exception
- if an exception occurredvoid setPreferencesValues(PortletPreferences preferences, String key, String languageId, String[] values) throws Exception
preferences
- the preferences container to store the localized
values inkey
- the preferences key to set the localized values forlanguageId
- the id of the language to set the localizations forvalues
- the localized values
Exception
- if an exception occurredString updateLocalization(String xml, String key, String value)
xml
- the localizations XML to update the localized string inkey
- the name of the localized string, such as "Title"value
- the localized string
String updateLocalization(String xml, String key, String value, String requestedLanguageId)
xml
- the localizations XML to update the localized string inkey
- the name of the localized string, such as "Title"value
- the localized stringrequestedLanguageId
- the id of the language to update the
localization for
String updateLocalization(String xml, String key, String value, String requestedLanguageId, String defaultLanguageId)
xml
- the localizations XML to update the localized string inkey
- the name of the localized string, such as "Title"value
- the localized stringrequestedLanguageId
- the id of the language to update the
localization fordefaultLanguageId
- the id of the default language
String updateLocalization(String xml, String key, String value, String requestedLanguageId, String defaultLanguageId, boolean cdata)
xml
- the localizations XML to update the localized string inkey
- the name of the localized string, such as "Title"value
- the localized stringrequestedLanguageId
- the id of the language to update the
localization fordefaultLanguageId
- the id of the default languagecdata
- whether to store localized strings as CDATA in the XML
|
Liferay 6.0.5 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |