Class LocaleDO

All Implemented Interfaces:
IBaseDO<Locale>

public class LocaleDO extends AbstractSimpleEntityDO<Locale>
  • Constructor Details

    • LocaleDO

      public LocaleDO()
  • Method Details

    • save

      public Locale save(Locale locale, DataMap map) throws ApplicationException
      Description copied from interface: IBaseDO
      map data to entity if any, validate and save
      Specified by:
      save in interface IBaseDO<Locale>
      Overrides:
      save in class AbstractEntityBaseDO<Locale>
      Parameters:
      locale - mandatory
      map - optional
      Returns:
      mapped entity
      Throws:
      ApplicationException
    • getJavaLocale

      public Locale getJavaLocale(Locale locale)
    • getUIActive

      public List<Locale> getUIActive()
      Gets all locales marked as isActive and isUILocale and not as isSystem (default and undefined locale).
      Returns:
      list of Locale entities
    • getDefault

      public Locale getDefault()
      Returns:
      Locale.DEFAULT
      Throws:
      mc.core.system.configuration.ConfigurationException - (RuntimeException) if locale default does not exist.
    • getUiDefault

      public Locale getUiDefault()
    • getUndefined

      public Locale getUndefined()
      Returns:
      Locale.UNDEFINED
      Throws:
      mc.core.system.configuration.ConfigurationException - (RuntimeException) if locale undefined does not exist.
    • getFromKey

      Description copied from interface: IBaseDO
      get entity by key through entity specific property matching
      Specified by:
      getFromKey in interface IBaseDO<Locale>
      Overrides:
      getFromKey in class AbstractBaseDO<Locale>
      Parameters:
      key - mandatory, can be the java locale code, the id (long or String) or internalDescription
      Returns:
      entity if found and unique
      Throws:
      EntityNotFoundException - if no locale can be found for this key
      NotUniqueResultException - if more than one locale are found for id or internalDescription (does not apply to java locale string due to fallback strategy when no exact match is possible)
    • fromJavaLocale

      public Locale fromJavaLocale(String javaLocaleString)
      Returns a active Locale according to the following rules:
      if a locale whose java locale string is an exact match to the given string is found in db this is returned.
      as fallback a locale whose language part is a match with the langauge part of the given string is returned if country and/or extension do not differ explicitly, e.g. a different country is set in both.
      If no matching locale can be found returns the default locale. Example:
      • in DB: fr, fr_CH
        fr -> fr
        fr_CH -> fr_CH
        fr_FR -> fr (fallback)
      • in DB: fr_FR, fr_CH
        fr_FR -> fr_FR
        fr_CH -> fr_CH
        fr -> fr_FR (fallback, first found) + warning
      • in DB: fr
        fr -> fr
        fr_CH -> fr (fallback)
      • in DB: fr_CH

        fr -> fr_CH (fallback)
        fr_CH -> fr_CH
        fr_FR -> Default-Locale in fromJavaLocale, EntityNotFoundEx in getFromKey
      Parameters:
      javaLocaleString - Language, country and variant separated by underscore. For example en_GB.
    • fromJavaLocale

      public Locale fromJavaLocale(Locale javaLocale) throws EntityNotFoundException, NotUniqueResultException
      Searches mediacockpit locales by example. Does not perform any fallbacks or fuzzy searching.
      Parameters:
      javaLocale - Java Locale object.
      Returns:
      mediacockpit representation of an equal locale.
      Throws:
      EntityNotFoundException
      NotUniqueResultException
    • validator

      public mc.core.domain.i18n.dobj.LocaleDO.LocaleValidator validator(Locale locale, DataMap map) throws ApplicationException
      Description copied from class: AbstractBaseDO
      for persistent entity copy constructor be used, the copy of entity be mapped and validated
      WARNING: in error case param map be changed! non valid fields be deleted from it
      all error be collect as ValidationResults in ValidationException and throw only by validate() call
      Examples to use:
      1. validator( navigationHrc, dataMap).thatValidField( NavigationHrc.Field.navigationHrcType).validate(); 2. validator( navigation, dataMap).thatValidField( Navigation.Field.navigationType, Navigation.Field.navigationHrc) .thatNotNullIf( HrcEntity.Field.parent, n -> n.getNavigationType().getParentNavigationType() != null).validate(); 3. validator( entity, dataMap).thatValidField( Country.Field.iso2Code, "message.validate.Country.iso2Code.missing").thatUnique( Country.Field.iso2Code).validate();
      Overrides:
      validator in class AbstractBaseDO<Locale>
      Parameters:
      locale - mandatory
      map - optional
      Returns:
      the validator
      Throws:
      ApplicationException - the application exception