Liferay 6.0.5

com.liferay.portal.util
Class LocalizationImpl

java.lang.Object
  extended by com.liferay.portal.util.LocalizationImpl
All Implemented Interfaces:
Localization

public class LocalizationImpl
extends Object
implements Localization


Constructor Summary
LocalizationImpl()
           
 
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)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizationImpl

public LocalizationImpl()
Method Detail

deserialize

public Object deserialize(JSONObject jsonObject)
Description copied from interface: Localization
Deserializes the JSON object into a map of locales and localized strings.

Specified by:
deserialize in interface Localization
Parameters:
jsonObject - the JSON object to deserialize
Returns:
the locales and localized strings

getAvailableLocales

public String[] getAvailableLocales(String xml)
Description copied from interface: Localization
Gets the available locales from the localizations XML

Specified by:
getAvailableLocales in interface Localization
Parameters:
xml - the localizations XML to get the available locales from
Returns:
the language ids of the available locales

getDefaultLocale

public String getDefaultLocale(String xml)
Description copied from interface: Localization
Gets the default locale from the localizations XML.

Specified by:
getDefaultLocale in interface Localization
Parameters:
xml - the localizations XML to get the default locale from
Returns:
the language id of the default locale, or the system default locale if the default locale cannot be retrieved from the XML

getLocalization

public String getLocalization(String xml,
                              String requestedLanguageId)
Description copied from interface: Localization
Gets the localized string from the localizations XML. Uses the default language if no localization exists for the requested language.

Specified by:
getLocalization in interface Localization
Parameters:
xml - the localizations XML to get the localized string from
requestedLanguageId - the id of the language to get the localization for
Returns:
the localized string

getLocalization

public String getLocalization(String xml,
                              String requestedLanguageId,
                              boolean useDefault)
Description copied from interface: Localization
Gets the localized string from the localizations XML, optionally using the default language if the no localization exists for the requested language.

Specified by:
getLocalization in interface Localization
Parameters:
xml - the localizations XML to get the localized string from
requestedLanguageId - the id of the language to get the localization for
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

public Map<Locale,String> getLocalizationMap(PortletRequest portletRequest,
                                             String parameter)
Description copied from interface: Localization
Gets a map of locales and localized strings for the parameter in the portlet request.

Specified by:
getLocalizationMap in interface Localization
Parameters:
portletRequest - the portlet request to get the locales and localized strings from
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

public Map<Locale,String> getLocalizationMap(String xml)
Description copied from interface: Localization
Gets a map of locales and localized strings from the localizations XML.

Specified by:
getLocalizationMap in interface Localization
Parameters:
xml - the localizations XML to get the locales and localized strings from
Returns:
the locales and localized strings

getLocalizationXmlFromPreferences

public String getLocalizationXmlFromPreferences(PortletPreferences preferences,
                                                PortletRequest portletRequest,
                                                String parameter)
Description copied from interface: Localization
Gets an xml of locales and localized strings for the parameter in the portlet request.

Specified by:
getLocalizationXmlFromPreferences in interface Localization
Parameters:
preferences - the preferences container to get the localized value from
portletRequest - the portlet request to get the locales and localized strings from
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

getLocalizedParameter

public Map<Locale,String> getLocalizedParameter(PortletRequest portletRequest,
                                                String parameter)
Specified by:
getLocalizedParameter in interface Localization

getPreferencesValue

public String getPreferencesValue(PortletPreferences preferences,
                                  String key,
                                  String languageId)
Description copied from interface: Localization
Gets the localized preferences value for the key. Uses the default language if no localization exists for the requested language.

Specified by:
getPreferencesValue in interface Localization
Parameters:
preferences - the preferences container to get the localized value from
key - the preferences key to get the localized value for
languageId - the id of the language to get the localization for
Returns:
the localized preferences value

getPreferencesValue

public String getPreferencesValue(PortletPreferences preferences,
                                  String key,
                                  String languageId,
                                  boolean useDefault)
Description copied from interface: Localization
Gets the localized preferences value for the key, optionally using the default language if the no localization exists for the requested language.

Specified by:
getPreferencesValue in interface Localization
Parameters:
preferences - the preferences container to get the localized value from
key - the preferences key to get the localized value for
languageId - the id of the language to get the localization for
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

public String[] getPreferencesValues(PortletPreferences preferences,
                                     String key,
                                     String languageId)
Description copied from interface: Localization
Gets the localized preferences values for the key. Uses the default language if no localization exists for the requested language.

Specified by:
getPreferencesValues in interface Localization
Parameters:
preferences - the preferences container to get the localized values from
key - the preferences key to get localized values for
languageId - the id of the language to get the localizations for
Returns:
the localized preferences values

getPreferencesValues

public String[] getPreferencesValues(PortletPreferences preferences,
                                     String key,
                                     String languageId,
                                     boolean useDefault)
Description copied from interface: Localization
Gets the localized preferences values for the key, optionally using the default language if the no localization exists for the requested language.

Specified by:
getPreferencesValues in interface Localization
Parameters:
preferences - the preferences container to get the localized values from
key - the preferences key to get localized values for
languageId - the id of the language to get the localizations for
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

public String removeLocalization(String xml,
                                 String key,
                                 String requestedLanguageId)
Description copied from interface: Localization
Removes the localization for the language from the localizations XML. Stores the localized strings as characters in the XML.

Specified by:
removeLocalization in interface Localization
Parameters:
xml - the localizations XML to remove the localization for the language from
key - the name of the localized string, such as "Title"
requestedLanguageId - the id of the language to remove from the localizations XML
Returns:
the localizations XML with the language removed

removeLocalization

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

Specified by:
removeLocalization in interface Localization
Parameters:
xml - the localizations XML to remove the localization for the language from
key - the name of the localized string, such as "Title"
requestedLanguageId - the id of the language to remove from the localizations XML
cdata - whether to store localized strings as CDATA in the XML
Returns:
the localizations XML with the language removed

setLocalizedPreferencesValues

public void setLocalizedPreferencesValues(PortletRequest portletRequest,
                                          PortletPreferences preferences,
                                          String parameter)
                                   throws Exception
Description copied from interface: Localization
Sets the localized preferences values for the parameter in the portlet request.

Specified by:
setLocalizedPreferencesValues in interface Localization
Parameters:
portletRequest - the portlet request to get the localized values from
preferences - the preferences container to set the localized values in
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

public void setPreferencesValue(PortletPreferences preferences,
                                String key,
                                String languageId,
                                String value)
                         throws Exception
Description copied from interface: Localization
Sets the localized preferences value for the key.

Specified by:
setPreferencesValue in interface Localization
Parameters:
preferences - the preferences container to store the localized value in
key - the preferences key to set the localized value for
languageId - the id of the language to set the localization for
value - the localized value
Throws:
Exception - if an exception occurred

setPreferencesValues

public void setPreferencesValues(PortletPreferences preferences,
                                 String key,
                                 String languageId,
                                 String[] values)
                          throws Exception
Description copied from interface: Localization
Sets the localized preferences values for the key.

Specified by:
setPreferencesValues in interface Localization
Parameters:
preferences - the preferences container to store the localized values in
key - the preferences key to set the localized values for
languageId - the id of the language to set the localizations for
values - the localized values
Throws:
Exception - if an exception occurred

updateLocalization

public String updateLocalization(String xml,
                                 String key,
                                 String value)
Description copied from interface: Localization
Updates the localized string for the system default language in the localizations XML. Stores the localized strings as characters in the XML.

Specified by:
updateLocalization in interface Localization
Parameters:
xml - the localizations XML to update the localized string in
key - the name of the localized string, such as "Title"
value - the localized string
Returns:
the updated localizations XML

updateLocalization

public String updateLocalization(String xml,
                                 String key,
                                 String value,
                                 String requestedLanguageId)
Description copied from interface: Localization
Updates the localized string for the language in the localizations XML. Stores the localized strings as characters in the XML.

Specified by:
updateLocalization in interface Localization
Parameters:
xml - the localizations XML to update the localized string in
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the id of the language to update the localization for
Returns:
the updated localizations XML

updateLocalization

public String updateLocalization(String xml,
                                 String key,
                                 String value,
                                 String requestedLanguageId,
                                 String defaultLanguageId)
Description copied from interface: Localization
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.

Specified by:
updateLocalization in interface Localization
Parameters:
xml - the localizations XML to update the localized string in
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the id of the language to update the localization for
defaultLanguageId - the id of the default language
Returns:
the updated localizations XML

updateLocalization

public String updateLocalization(String xml,
                                 String key,
                                 String value,
                                 String requestedLanguageId,
                                 String defaultLanguageId,
                                 boolean cdata)
Description copied from interface: Localization
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.

Specified by:
updateLocalization in interface Localization
Parameters:
xml - the localizations XML to update the localized string in
key - the name of the localized string, such as "Title"
value - the localized string
requestedLanguageId - the id of the language to update the localization for
defaultLanguageId - the id of the default language
cdata - whether to store localized strings as CDATA in the XML
Returns:
the updated localizations XML

Liferay 6.0.5