Package com.hybris.cockpitng.i18n.impl
Class DefaultCockpitLocaleService
- java.lang.Object
-
- com.hybris.cockpitng.i18n.impl.DefaultCockpitLocaleService
-
- All Implemented Interfaces:
Resettable,CockpitLocaleService
public class DefaultCockpitLocaleService extends java.lang.Object implements CockpitLocaleService, Resettable
Default implementation ofCockpitLocaleService. Session locale are based on ZK Locale handling. Data Locale are stored per principal in cockpit-configuration : 'available-locales'.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPERTY_COCKPITNG_LEGACY_WIDGET_CONFIGURATION_PERSISTENCE_ENABLEDstatic java.lang.StringPROPERTY_COCKPITNG_LOCALIZATION_LOCALES
-
Constructor Summary
Constructors Constructor Description DefaultCockpitLocaleService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ConfigContextbuildContext(java.lang.String principal, boolean addGroupDimension)<T> TexecuteWithLocale(AbstractExecutionBody<T> executionBody, java.util.Locale locale)Using this method you can execute code in a context of a different locale than the current oneprotected java.util.List<CockpitLocale>getAllCockpitLocales(java.lang.String principal)Override, if your system has additional language management.java.util.List<java.util.Locale>getAllLocales()Returns a list of all available locales.protected java.util.List<CockpitLocale>getAvailableCockpitLocales(java.lang.String principal)java.util.List<java.util.Locale>getAvailableDataLocales(java.lang.String principal)Returns a collection of available data locales (both enabled and disabled) for specified principal.protected CockpitConfigurationServicegetCockpitConfigurationService()protected CockpitLocalesFactorygetCockpitLocalesFactory()protected CockpitPropertiesgetCockpitProperties()java.util.LocalegetCurrentLocale()Returns the currently active locale.java.util.LocalegetDefaultDataLocale(java.lang.String principal)Returns the default data locale for specified principal.java.util.List<java.util.Locale>getEnabledDataLocales(java.lang.String principal)Returns a collection of enabled locales for specified principal.protected org.zkoss.zk.ui.SessiongetZKSession()Deprecated, for removal: This API element is subject to removal in a future version.since 6.7 please uslookupZkSession()booleanisDataLocaleEnabled(java.util.Locale locale, java.lang.String principal)Checks if the given data locale is an active data locale for the given user.protected booleanisLocalePersistenceOnToggleEnabled()protected java.util.Optional<org.zkoss.zk.ui.Session>lookupZkSession()voidreset()Resets the something the implementation provides.protected voidsaveLocales(java.util.Collection<CockpitLocale> cockpitLocale, java.lang.String principal)voidsetAuthorityGroupService(AuthorityGroupService authorityGroupService)voidsetCockpitConfigurationService(CockpitConfigurationService cockpitConfigurationService)voidsetCockpitLocalesFactory(CockpitLocalesFactory cockpitLocalesFactory)voidsetCockpitProperties(CockpitProperties cockpitProperties)voidsetCurrentLocale(java.util.Locale locale)Changes the current locale to the given one.voidsetWidgetConfigurationContextDecoratorList(java.util.List<WidgetConfigurationContextDecorator> configContextDecoratorList)voidtoggleDataLocale(java.util.Locale locale, java.lang.String principal)Toggles the specified data locale.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.hybris.cockpitng.i18n.CockpitLocaleService
getAllUILocales
-
-
-
-
Field Detail
-
PROPERTY_COCKPITNG_LOCALIZATION_LOCALES
public static final java.lang.String PROPERTY_COCKPITNG_LOCALIZATION_LOCALES
- See Also:
- Constant Field Values
-
PROPERTY_COCKPITNG_LEGACY_WIDGET_CONFIGURATION_PERSISTENCE_ENABLED
public static final java.lang.String PROPERTY_COCKPITNG_LEGACY_WIDGET_CONFIGURATION_PERSISTENCE_ENABLED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentLocale
public java.util.Locale getCurrentLocale()
Description copied from interface:CockpitLocaleServiceReturns the currently active locale. You normally do not need to call this. All localized widget labels are automatically rendered using the current locale.- Specified by:
getCurrentLocalein interfaceCockpitLocaleService- Returns:
- currently active locale
-
setCurrentLocale
public void setCurrentLocale(java.util.Locale locale)
Description copied from interface:CockpitLocaleServiceChanges the current locale to the given one. After calling this you need to refresh the cockpit application (unless this is called before the application was rendered, e.g. shortly after login). You can useExecutions.sendRedirect(String)withnullas a parameter to re-render the application.- Specified by:
setCurrentLocalein interfaceCockpitLocaleService- Parameters:
locale- the locale to be set as the current one
-
executeWithLocale
public <T> T executeWithLocale(AbstractExecutionBody<T> executionBody, java.util.Locale locale)
Description copied from interface:CockpitLocaleServiceUsing this method you can execute code in a context of a different locale than the current one- Specified by:
executeWithLocalein interfaceCockpitLocaleService- Parameters:
executionBody- the execution bodylocale- the locale- Returns:
- the result of the execution body call or null if execution is without result
-
getZKSession
@Deprecated(since="6.7", forRemoval=true) protected org.zkoss.zk.ui.Session getZKSession()Deprecated, for removal: This API element is subject to removal in a future version.since 6.7 please uslookupZkSession()
-
lookupZkSession
protected java.util.Optional<org.zkoss.zk.ui.Session> lookupZkSession()
-
getAllLocales
public java.util.List<java.util.Locale> getAllLocales()
Description copied from interface:CockpitLocaleServiceReturns a list of all available locales.- Specified by:
getAllLocalesin interfaceCockpitLocaleService- Returns:
- a list of all available locales
-
getAvailableDataLocales
public java.util.List<java.util.Locale> getAvailableDataLocales(java.lang.String principal)
Description copied from interface:CockpitLocaleServiceReturns a collection of available data locales (both enabled and disabled) for specified principal. An exception of typeAvailableLocaleExceptionis thrown when an attempt to load the cockpit locales failed.- Specified by:
getAvailableDataLocalesin interfaceCockpitLocaleService- Parameters:
principal- needed to filter available cockpit locales- Returns:
- collection of available locales
-
toggleDataLocale
public void toggleDataLocale(java.util.Locale locale, java.lang.String principal)Description copied from interface:CockpitLocaleServiceToggles the specified data locale. Does nothing if the locale does not exist. Toggling data locale would enable or disable it for localized editors.- Specified by:
toggleDataLocalein interfaceCockpitLocaleService- Parameters:
locale- to toggleprincipal- needed to filter available cockpit locales
-
isLocalePersistenceOnToggleEnabled
protected boolean isLocalePersistenceOnToggleEnabled()
-
getEnabledDataLocales
public java.util.List<java.util.Locale> getEnabledDataLocales(java.lang.String principal)
Description copied from interface:CockpitLocaleServiceReturns a collection of enabled locales for specified principal. Only enabled locales are used to render localized attributes. By disabling locale you can reduce the visible localized data. An exception of typeAvailableLocaleExceptionis thrown when an attempt to load the cockpit locales failed.- Specified by:
getEnabledDataLocalesin interfaceCockpitLocaleService- Parameters:
principal- needed to filter available cockpit locales- Returns:
- collection of enabled locales
-
getDefaultDataLocale
public java.util.Locale getDefaultDataLocale(java.lang.String principal)
Description copied from interface:CockpitLocaleServiceReturns the default data locale for specified principal. A collapsed localized editor would only show the data using the default data locale. An exception of typeAvailableLocaleExceptionis thrown when an attempt to load the cockpit locales failed.- Specified by:
getDefaultDataLocalein interfaceCockpitLocaleService- Parameters:
principal- needed to filter available cockpit locales- Returns:
Locale
-
isDataLocaleEnabled
public boolean isDataLocaleEnabled(java.util.Locale locale, java.lang.String principal)Description copied from interface:CockpitLocaleServiceChecks if the given data locale is an active data locale for the given user.- Specified by:
isDataLocaleEnabledin interfaceCockpitLocaleService- Parameters:
locale- to checkprincipal- needed to filter available cockpit locales- Returns:
- true if data locale is enabled.
-
saveLocales
protected void saveLocales(java.util.Collection<CockpitLocale> cockpitLocale, java.lang.String principal)
-
buildContext
protected ConfigContext buildContext(java.lang.String principal, boolean addGroupDimension)
-
getAvailableCockpitLocales
protected java.util.List<CockpitLocale> getAvailableCockpitLocales(java.lang.String principal)
-
getAllCockpitLocales
protected java.util.List<CockpitLocale> getAllCockpitLocales(java.lang.String principal)
Override, if your system has additional language management.- Parameters:
principal- user that can be used to restrict the list of available languages. Can be null.
-
getCockpitProperties
protected CockpitProperties getCockpitProperties()
-
setCockpitProperties
public void setCockpitProperties(CockpitProperties cockpitProperties)
-
getCockpitConfigurationService
protected CockpitConfigurationService getCockpitConfigurationService()
-
setCockpitConfigurationService
public void setCockpitConfigurationService(CockpitConfigurationService cockpitConfigurationService)
-
getCockpitLocalesFactory
protected CockpitLocalesFactory getCockpitLocalesFactory()
-
setCockpitLocalesFactory
public void setCockpitLocalesFactory(CockpitLocalesFactory cockpitLocalesFactory)
-
reset
public void reset()
Description copied from interface:ResettableResets the something the implementation provides.- Specified by:
resetin interfaceResettable
-
setWidgetConfigurationContextDecoratorList
public void setWidgetConfigurationContextDecoratorList(java.util.List<WidgetConfigurationContextDecorator> configContextDecoratorList)
-
setAuthorityGroupService
public void setAuthorityGroupService(AuthorityGroupService authorityGroupService)
-
-