public LocaleAwareMessageInterpolator(Locale defaultLocale) { super(new PlatformResourceBundleLocator("ValidationMessages")); this.defaultLocale = defaultLocale; }
protected ResourceBundleMessageInEnglishInterpolator() { super(new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES )); }
protected ResourceBundleMessageInEnglishInterpolator() { super(new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES )); }
Validation .byProvider(HibernateValidator.class) .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator("com.mycompany.Messages"))) .buildValidatorFactory() .getValidator();`
Validator validator = Validation.byDefaultProvider() .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "MyMessages" ) ) ) .buildValidatorFactory() .getValidator();
Validator validator = Validation.byProvider(HibernateValidator.class) .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "LabelNames" ))) .buildValidatorFactory() .getValidator();
Validator validator = Validation.byDefaultProvider() .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "MyMessages" ) ) ) .buildValidatorFactory() .getValidator();
Validator validator = Validation.byProvider(HibernateValidator.class) .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "my_bundle" ))) .buildValidatorFactory() .getValidator();
Validator validator = Validation.byDefaultProvider() .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "messages" ) ) ) .buildValidatorFactory() .getValidator();
@Override public ResourceBundle getResourceBundle(Locale locale) { List<ResourceBundle> sourceBundles = new ArrayList<ResourceBundle>(); for ( String bundleName : bundleNames ) { ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator( bundleName, classLoader ); ResourceBundle resourceBundle = resourceBundleLocator.getResourceBundle( locale ); if ( resourceBundle != null ) { sourceBundles.add( resourceBundle ); } } ResourceBundle bundleFromDelegate = super.getResourceBundle( locale ); if ( bundleFromDelegate != null ) { sourceBundles.add( bundleFromDelegate ); } return sourceBundles.isEmpty() ? null : new AggregateBundle( sourceBundles ); }
@Override public ResourceBundle getResourceBundle(Locale locale) { List<ResourceBundle> sourceBundles = new ArrayList<ResourceBundle>(); for ( String bundleName : bundleNames ) { ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator( bundleName, classLoader ); ResourceBundle resourceBundle = resourceBundleLocator.getResourceBundle( locale ); if ( resourceBundle != null ) { sourceBundles.add( resourceBundle ); } } ResourceBundle bundleFromDelegate = super.getResourceBundle( locale ); if ( bundleFromDelegate != null ) { sourceBundles.add( bundleFromDelegate ); } return sourceBundles.isEmpty() ? null : new AggregateBundle( sourceBundles ); }
this.userResourceBundleLocator = new PlatformResourceBundleLocator( USER_VALIDATION_MESSAGES ); this.contributorResourceBundleLocator = new PlatformResourceBundleLocator( CONTRIBUTOR_VALIDATION_MESSAGES, null, this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES );
@Bean public LocalValidatorFactoryBean validator() { PlatformResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator(ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, null, true); LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean(); factoryBean.setMessageInterpolator(new ResourceBundleMessageInterpolator(resourceBundleLocator)); return factoryBean; }
this.userResourceBundleLocator = new PlatformResourceBundleLocator( USER_VALIDATION_MESSAGES ); this.contributorResourceBundleLocator = new PlatformResourceBundleLocator( CONTRIBUTOR_VALIDATION_MESSAGES, null, this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES );
private Validator tryCreateValidator(final String bundle, final Locale locale, ValidatorKey key) { HibernateValidatorConfiguration configure = Validation.byProvider(HibernateValidator.class).configure(); configure.messageInterpolator(new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator(bundle)) { @Override public String interpolate(String message, Context context) { return super.interpolate(message, context, locale); } }); ValidatorFactory vf = configure.buildValidatorFactory(); Validator validator = vf.getValidator(); GeneralHelper.syncTryPut(validatorMap, key, validator); return validatorMap.get(key); } }
/** * Creates a new validator instance. * * @return New instance. */ @Produces public Validator createValidator() { final PlatformResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, null, true); return Validation.byDefaultProvider().configure() .messageInterpolator(new ResourceBundleMessageInterpolator( resourceBundleLocator)) .buildValidatorFactory().getValidator(); }
private ConfigurationImpl() { this.validationBootstrapParameters = new ValidationBootstrapParameters(); this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES ); this.defaultTraversableResolver = TraversableResolvers.getDefault(); this.defaultConstraintValidatorFactory = new ConstraintValidatorFactoryImpl(); this.defaultParameterNameProvider = new DefaultParameterNameProvider(); this.defaultClockProvider = DefaultClockProvider.INSTANCE; }
PlatformResourceBundleLocator userResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, externalClassLoader ); PlatformResourceBundleLocator contributorResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES, externalClassLoader,
PlatformResourceBundleLocator userResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, externalClassLoader ); PlatformResourceBundleLocator contributorResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES, externalClassLoader,
private ConfigurationImpl() { this.validationBootstrapParameters = new ValidationBootstrapParameters(); TypeResolutionHelper typeResolutionHelper = new TypeResolutionHelper(); if ( isJavaFxInClasspath() ) { validatedValueHandlers.add( createJavaFXUnwrapperClass( typeResolutionHelper ) ); } if ( Version.getJavaRelease() >= 8 ) { validatedValueHandlers.add( new OptionalValueUnwrapper( typeResolutionHelper ) ); } this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES ); this.defaultTraversableResolver = new DefaultTraversableResolver(); this.defaultConstraintValidatorFactory = new ConstraintValidatorFactoryImpl(); this.defaultParameterNameProvider = new DefaultParameterNameProvider(); this.serviceLoaderBasedConstraintMappingContributor = new ServiceLoaderBasedConstraintMappingContributor( typeResolutionHelper ); }