Class DefaultLocalizedPopulator
- java.lang.Object
-
- de.hybris.platform.cmsfacades.common.populator.impl.DefaultLocalizedPopulator
-
- All Implemented Interfaces:
LocalizedPopulator
public class DefaultLocalizedPopulator extends java.lang.Object implements LocalizedPopulator
Default implementation for theLocalizedPopulatorinterface.
-
-
Constructor Summary
Constructors Constructor Description DefaultLocalizedPopulator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.stream.Stream<LanguageData>getAllLanguages()Gets all the languages supported.protected CMSUserServicegetCmsUserService()protected CommonI18NServicegetCommonI18NService()protected LanguageFacadegetLanguageFacade()<T> voidpopulate(java.util.function.BiConsumer<java.util.Locale,T> consumer, java.util.function.Function<java.util.Locale,T> function)Bi-directional method to populate the localized attributes.voidsetCmsUserService(CMSUserService cmsUserService)voidsetCommonI18NService(CommonI18NService commonI18NService)voidsetLanguageFacade(LanguageFacade languageFacade)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.hybris.platform.cmsfacades.common.populator.LocalizedPopulator
getLanguage, populateAsMapOfLanguages, populateAsMapOfLocales
-
-
-
-
Method Detail
-
populate
public <T> void populate(java.util.function.BiConsumer<java.util.Locale,T> consumer, java.util.function.Function<java.util.Locale,T> function)Description copied from interface:LocalizedPopulatorBi-directional method to populate the localized attributes. It can be used to populate Model classes by reading the content from thegetterfunction, and also populate localizedMaps by reading content from a localized data model. This method will iterate over all locales (Locale) available at the execution time. For each locale, it will execute the functiongetterto get the localized value that may be coming from different sources (see examples bellow). The result of thegetterfunction will then be used on theBiConsumersetterfunction. Examples of its usage: Populate aMap<String, String>from a localized modelfinal Map<String, String> map = new HashMap<>(); getLocalizedPopulator().populate( (locale, value) -> map.put(getLocalizedPopulator().getLanguage(locale), value), (locale) -> source.getSomeLocalizedField(locale) );* Populate anItemModelfrom a localizedMap<String, String>// source.getTitle() returns Map<String, String> Optional.ofNullable(source.getTitle()) .ifPresent(title -> getLocalizedPopulator() .populate((locale, value) -> target.setTitle(value, locale), (locale) -> title.get(getLocalizedPopulator().getLanguage(locale))));- Specified by:
populatein interfaceLocalizedPopulator- Parameters:
consumer- ABiConsumerfunction that will accept the Locale and the Value extracted from thegetterfunction.function- AFunctionthat will be applied to get the localized value for a givenLocale.
-
getAllLanguages
protected java.util.stream.Stream<LanguageData> getAllLanguages()
Gets all the languages supported.- Returns:
- - a Map containing all the required locales where the keys maps the
Locale.getLanguage()to a boolean value, indicating if the language is the default language.
-
getLanguageFacade
protected LanguageFacade getLanguageFacade()
-
setLanguageFacade
public void setLanguageFacade(LanguageFacade languageFacade)
-
getCommonI18NService
protected CommonI18NService getCommonI18NService()
-
setCommonI18NService
public void setCommonI18NService(CommonI18NService commonI18NService)
-
getCmsUserService
protected CMSUserService getCmsUserService()
-
setCmsUserService
public void setCmsUserService(CMSUserService cmsUserService)
-
-