Class DefaultLocalizedPopulator

  • All Implemented Interfaces:
    LocalizedPopulator

    public class DefaultLocalizedPopulator
    extends java.lang.Object
    implements LocalizedPopulator
    Default implementation for the LocalizedPopulator interface.
    • Constructor Detail

      • DefaultLocalizedPopulator

        public DefaultLocalizedPopulator()
    • 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: 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 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.
      • setLanguageFacade

        public void setLanguageFacade​(LanguageFacade languageFacade)
      • setCommonI18NService

        public void setCommonI18NService​(CommonI18NService commonI18NService)
      • setCmsUserService

        public void setCmsUserService​(CMSUserService cmsUserService)