public LocaleAwareMessageInterpolator(Locale defaultLocale) { super(new PlatformResourceBundleLocator("ValidationMessages")); this.defaultLocale = defaultLocale; }
@Override public ResourceBundle newBundle( String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { // only *.properties files can be aggregated. Other formats are delegated to the default implementation if ( !"java.properties".equals( format ) ) { return super.newBundle( baseName, locale, format, loader, reload ); } String resourceName = toBundleName( baseName, locale ) + ".properties"; Properties properties = load( resourceName, loader ); return properties.size() == 0 ? null : new AggregateResourceBundle( properties ); }
@Override public ResourceBundle getResourceBundle(Locale locale) { ResourceBundle cachedResourceBundle = bundleCache.get( locale ); if ( cachedResourceBundle == null ) { final ResourceBundle bundle = super.getResourceBundle( locale ); if ( bundle != null ) { cachedResourceBundle = bundleCache.putIfAbsent( locale, bundle ); if ( cachedResourceBundle == null ) { return bundle; } } } return cachedResourceBundle; } }
@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 ); }
rb = loadBundle( classLoader, locale, bundleName + " not found by user-provided classloader" ClassLoader classLoader = run( GetClassLoader.fromContext() ); if ( classLoader != null ) { rb = loadBundle( classLoader, locale, bundleName + " not found by thread context classloader" ClassLoader classLoader = run( GetClassLoader.fromClass( PlatformResourceBundleLocator.class ) ); rb = loadBundle( classLoader, locale, bundleName + " not found by validator classloader"
@Override public Enumeration<String> getKeys() { return new IteratorEnumeration<String>( contents.keySet().iterator() ); }
protected ResourceBundleMessageInEnglishInterpolator() { super(new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES )); }
@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 newBundle( String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { // only *.properties files can be aggregated. Other formats are delegated to the default implementation if ( !"java.properties".equals( format ) ) { return super.newBundle( baseName, locale, format, loader, reload ); } String resourceName = toBundleName( baseName, locale ) + ".properties"; Properties properties = load( resourceName, loader ); return properties.size() == 0 ? null : new AggregateResourceBundle( properties ); }
@Override public ResourceBundle getResourceBundle(Locale locale) { ResourceBundle cachedResourceBundle = bundleCache.get( locale ); if ( cachedResourceBundle == null ) { final ResourceBundle bundle = super.getResourceBundle( locale ); if ( bundle != null ) { cachedResourceBundle = bundleCache.putIfAbsent( locale, bundle ); if ( cachedResourceBundle == null ) { return bundle; } } } return cachedResourceBundle; } }
@Override public Enumeration<String> getKeys() { return new IteratorEnumeration<String>( contents.keySet().iterator() ); }
protected ResourceBundleMessageInEnglishInterpolator() { super(new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES )); }
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();
Validation .byProvider(HibernateValidator.class) .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator("com.mycompany.Messages"))) .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.byDefaultProvider() .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator( "messages" ) ) ) .buildValidatorFactory() .getValidator();
@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; }
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; }