Class DefaultLocalizedPopulator

java.lang.Object
de.hybris.platform.cmsfacades.common.populator.impl.DefaultLocalizedPopulator
All Implemented Interfaces:
LocalizedPopulator

public class DefaultLocalizedPopulator extends Object implements LocalizedPopulator
Default implementation for the LocalizedPopulator interface.
  • Constructor Details

    • DefaultLocalizedPopulator

      public DefaultLocalizedPopulator()
  • Method Details

    • populate

      public <T> void populate(BiConsumer<Locale,T> consumer, Function<Locale,T> function)
      Description copied from interface: LocalizedPopulator
      Bi-directional method to populate the localized attributes. It can be used to populate Model classes by reading the content from the getter function, and also populate localized Maps 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 function getter to get the localized value that may be coming from different sources (see examples bellow). The result of the getter function will then be used on the BiConsumer setter function. Examples of its usage: Populate a Map<String, String> from a localized model final Map<String, String> map = new HashMap<>(); getLocalizedPopulator().populate( (locale, value) -> map.put(getLocalizedPopulator().getLanguage(locale), value), (locale) -> source.getSomeLocalizedField(locale) ); * Populate an ItemModel from a localized Map<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:
      populate in interface LocalizedPopulator
      Parameters:
      consumer - A BiConsumer function that will accept the Locale and the Value extracted from the getter function.
      function - A Function that will be applied to get the localized value for a given Locale.
    • getAllLanguages

      protected 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)