java.lang.Object
de.hybris.platform.configurablebundleservices.constraints.TypeValidatorHelper
Direct Known Subclasses:
BasicBundleRuleValidator, BasicBundleTemplateValidator

public class TypeValidatorHelper extends Object
A helper class for validators providing some common functionality of error message constructing.
  • Field Details

    • MESSAGE_PARAMETER_PATTERN

      protected static final Pattern MESSAGE_PARAMETER_PATTERN
      Pattern to check whether validation message is a string resource id.
  • Constructor Details

    • TypeValidatorHelper

      public TypeValidatorHelper()
  • Method Details

    • buildErrorMessage

      protected void buildErrorMessage(String fieldName, @Nonnull javax.validation.ConstraintValidatorContext context, Object... args)
      Creates custom error message.

      Message template is taken from validation context. In general it is the one specified in C.message field. Strings {string.resource.id} treated as string key of localized string resource. Current add locale is used to resolve value.
      To have such string as it is, double the surrounding curly brackets: {{not.a.resource{0}}} will be show as {not.a.resource<value_of_first_arg>}

      The resulting string is then passed to MessageFormat.format(String, Object...) along with args only if any args provided.

      Please pay attention to syntax inconsistency between parametrized and non-parametrized lines: It''s a parametrized line with arg ''{0}'' but It'a a non-parametrized line

      Parameters:
      fieldName - name of field where the error occurred
      context - validation context
      args - optional message arguments
      Throws:
      IllegalStateException - if the instance has not been initialized by Spring (see BasicBundleRuleValidator.initialize(Annotation) as an example of initialization)
      See Also:
    • getCurrentLocale

      protected Locale getCurrentLocale()
    • getLocalizedString

      protected String getLocalizedString(String key, Locale locale)
    • getI18nService

      protected I18NService getI18nService()
    • getResourceBundleProvider

      protected ResourceBundleProvider getResourceBundleProvider()