use of jakarta.validation.MessageInterpolator in project graphql-java-extended-validation by graphql-java.
the class ELDiscover method main.
public static void main(String[] args) throws Exception {
elDirect();
Map<String, Object> attributes = new HashMap<>();
ConstraintAnnotationDescriptor.Builder<NotNull> constraintBuilder = new ConstraintAnnotationDescriptor.Builder<>(NotNull.class, attributes);
ConstraintDescriptorImpl<NotNull> constraintDescriptor = new ConstraintDescriptorImpl<>(ConstraintHelper.forAllBuiltinConstraints(), null, constraintBuilder.build(), ConstraintLocationKind.FIELD, ConstraintType.GENERIC);
User user = new User();
user.setAge(18);
ResourceBundleMessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator();
PathImpl rootPath = PathImpl.createRootPath();
ExpressionLanguageFeatureLevel level = ExpressionLanguageFeatureLevel.BEAN_METHODS;
MessageInterpolator.Context context = new MessageInterpolatorContext(constraintDescriptor, user, null, rootPath, Collections.emptyMap(), Collections.emptyMap(), level, true);
print("${validatedValue.age}", messageInterpolator, context);
print("${validatedValue}", messageInterpolator, context);
print("[1,2,3,4].stream().sum()", messageInterpolator, context);
print("${4.0>= 3}", messageInterpolator, context);
print("${! empty validatedValue}", messageInterpolator, context);
print("#{cube=(x->x*x*x);cube(2)}", messageInterpolator, context);
}
use of jakarta.validation.MessageInterpolator in project mojarra by eclipse-ee4j.
the class BeanValidator method getBeanValidator.
// ----------------------------------------------------- Private helper methods for bean validation
// MOJARRA IMPLEMENTATION NOTE: identical code exists in Mojarra's com.sun.faces.util.BeanValidation
private static jakarta.validation.Validator getBeanValidator(FacesContext context) {
ValidatorFactory validatorFactory = getValidatorFactory(context);
ValidatorContext validatorContext = validatorFactory.usingContext();
MessageInterpolator facesMessageInterpolator = new FacesAwareMessageInterpolator(context, validatorFactory.getMessageInterpolator());
validatorContext.messageInterpolator(facesMessageInterpolator);
return validatorContext.getValidator();
}
use of jakarta.validation.MessageInterpolator in project today-framework by TAKETODAY.
the class CustomValidatorBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
if (this.validatorFactory == null) {
this.validatorFactory = Validation.buildDefaultValidatorFactory();
}
ValidatorContext validatorContext = this.validatorFactory.usingContext();
MessageInterpolator targetInterpolator = this.messageInterpolator;
if (targetInterpolator == null) {
targetInterpolator = this.validatorFactory.getMessageInterpolator();
}
validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
if (this.traversableResolver != null) {
validatorContext.traversableResolver(this.traversableResolver);
}
setTargetValidator(validatorContext.getValidator());
}
use of jakarta.validation.MessageInterpolator in project today-framework by TAKETODAY.
the class MessageInterpolatorFactoryTests method getObjectShouldReturnMessageSourceMessageInterpolatorDelegateWithResourceBundleMessageInterpolator.
@Test
void getObjectShouldReturnMessageSourceMessageInterpolatorDelegateWithResourceBundleMessageInterpolator() {
MessageSource messageSource = mock(MessageSource.class);
MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory(messageSource);
MessageInterpolator interpolator = interpolatorFactory.get();
assertThat(interpolator).isInstanceOf(MessageSourceMessageInterpolator.class);
assertThat(interpolator).hasFieldOrPropertyWithValue("messageSource", messageSource);
assertThat(ReflectionTestUtils.getField(interpolator, "messageInterpolator")).isInstanceOf(ResourceBundleMessageInterpolator.class);
}
use of jakarta.validation.MessageInterpolator in project hibernate-validator by hibernate.
the class EscapedInterpolationVariableTest method setUp.
@BeforeTest
public void setUp() {
MessageInterpolator interpolator = new ResourceBundleMessageInterpolator(new ResourceBundleLocator() {
@Override
public ResourceBundle getResourceBundle(Locale locale) {
return new ResourceBundle() {
@Override
protected Object handleGetObject(String key) {
if ("key-1".equals(key)) {
return "\\{escapedParameterKey\\}";
} else if ("key-2".equals(key)) {
// since {} are unbalanced the original key (key-2) should be returned from the interpolation
return "{escapedParameterKey\\}";
} else if ("key-3".equals(key)) {
// since {} are unbalanced the original key (key-3) should be returned from the interpolation
return "\\{escapedParameterKey}";
} else if ("key-4".equals(key)) {
return "foo";
} else {
fail("Unexpected key: " + key);
}
return null;
}
@Override
public Enumeration<String> getKeys() {
throw new UnsupportedOperationException();
}
};
}
}, false);
HibernateValidatorConfiguration config = ValidatorUtil.getConfiguration();
ValidatorFactory factory = config.messageInterpolator(interpolator).buildValidatorFactory();
validator = factory.getValidator();
}
Aggregations