use of org.hibernate.validator.HibernateValidatorConfiguration in project JessMA by ldcsaa.
the class HibernateBeanValidator method tryCreateValidator.
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);
}
use of org.hibernate.validator.HibernateValidatorConfiguration in project cuba by cuba-platform.
the class BeanValidationImpl method getValidatorWithDefaultFactory.
protected Validator getValidatorWithDefaultFactory(Locale locale) {
ValidatorFactory validatorFactoryFromCache = validatorFactoriesCache.get(locale);
if (validatorFactoryFromCache != null) {
return validatorFactoryFromCache.getValidator();
}
HibernateValidatorConfiguration configuration = getValidatorFactoryConfiguration(locale);
ValidatorFactory factory = configuration.buildValidatorFactory();
validatorFactoriesCache.put(locale, factory);
return factory.getValidator();
}
use of org.hibernate.validator.HibernateValidatorConfiguration in project wildfly by wildfly.
the class SafeHtmlValidationTestCase method testSafeHTML.
/**
* Ensure that including a cross-site script attack triggers the @SafeHtml validation rule
*/
@Test
public void testSafeHTML() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
assertNotNull(configuration);
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Employee emp = new Employee();
// create employee
emp.setFirstName("Joe");
emp.setLastName("Cocker");
emp.setEmail("none@jboss.org");
emp.setWebsite("<script> Cross-site scripting http://en.wikipedia.org/wiki/Joe_Cocker <script/>.");
Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
}
use of org.hibernate.validator.HibernateValidatorConfiguration in project wildfly by wildfly.
the class MessageInterpolationValidationTestCase method testCustomMessageInterpolation.
@Test
public void testCustomMessageInterpolation() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
assertNotNull(configuration);
final MessageInterpolator messageInterpolator = new CustomMessageInterpolator();
configuration.messageInterpolator(messageInterpolator);
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
// create employee
Employee emp = new Employee();
emp.setEmail("MADHUMITA");
Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
assertEquals(CustomMessageInterpolator.MESSAGE, constraintViolations.iterator().next().getMessage());
}
use of org.hibernate.validator.HibernateValidatorConfiguration in project jo-client-platform by jo-source.
the class HibernateBeanValidatorFactory method create.
@Override
public Validator create() {
final ValidationProviderResolver validationProviderResolver = new ValidationProviderResolver() {
@Override
public List<ValidationProvider<?>> getValidationProviders() {
final List<ValidationProvider<?>> result = new LinkedList<ValidationProvider<?>>();
result.add(new HibernateValidator());
return result;
}
};
final ProviderSpecificBootstrap<HibernateValidatorConfiguration> bootstrap = Validation.byProvider(HibernateValidator.class);
bootstrap.providerResolver(validationProviderResolver);
final HibernateValidatorConfiguration validatorConfiguration = bootstrap.configure();
return validatorConfiguration.buildValidatorFactory().getValidator();
}
Aggregations