本文整理匯總了Java中javax.validation.MessageInterpolator類的典型用法代碼示例。如果您正苦於以下問題:Java MessageInterpolator類的具體用法?Java MessageInterpolator怎麽用?Java MessageInterpolator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageInterpolator類屬於javax.validation包,在下文中一共展示了MessageInterpolator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createConstraintViolation
import javax.validation.MessageInterpolator; //導入依賴的package包/類
private <T, V, A extends Annotation> ConstraintViolation<T> createConstraintViolation(
final GwtValidationContext<T> context, final G object, final V value,
final ConstraintDescriptorImpl<A> constraintDescriptor, final MessageAndPath messageAndPath) {
final MessageInterpolator messageInterpolator = context.getMessageInterpolator();
final de.knightsoftnet.validators.client.impl.MessageInterpolatorContextImpl messageContext =
new MessageInterpolatorContextImpl(constraintDescriptor, value);
final String message =
messageInterpolator.interpolate(messageAndPath.getMessage(), messageContext);
return ConstraintViolationImpl.<T>builder() //
.setConstraintDescriptor(constraintDescriptor) //
.setInvalidValue(value) //
.setLeafBean(object) //
.setMessage(message) //
.setMessageTemplate(messageAndPath.getMessage()) //
.setPropertyPath(messageAndPath.getPath()) //
.setRootBean(context.getRootBean()) //
.setRootBeanClass(context.getRootBeanClass()) //
.setElementType(constraintDescriptor.getElementType()) //
.build();
}
示例2: afterPropertiesSet
import javax.validation.MessageInterpolator; //導入依賴的package包/類
@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());
}
示例3: parsePolicyEnable
import javax.validation.MessageInterpolator; //導入依賴的package包/類
public static JsonNode parsePolicyEnable(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
PolicyEnbale policyEnable = new_mapper.readValue(jsonString, PolicyEnbale.class);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<PolicyEnbale>> set = validator.validate(policyEnable);
if (set.size() > 0 ){
for (ConstraintViolation<PolicyEnbale> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = policyEnable.transformInput();
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例4: parseScalingHistory
import javax.validation.MessageInterpolator; //導入依賴的package包/類
public static JsonNode parseScalingHistory(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
JavaType javaType = getCollectionType(ArrayList.class, ArrayList.class, HistoryData.class);
new_mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<HistoryData> scalinghistory = (List<HistoryData>)new_mapper.readValue(jsonString, javaType);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<List<HistoryData>>> set = validator.validate(scalinghistory);
if (set.size() > 0 ){
for (ConstraintViolation<List<HistoryData>> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = transformHistory(scalinghistory);
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例5: testInterpolateStringContext
import javax.validation.MessageInterpolator; //導入依賴的package包/類
/**
* JAVADOC Method Level Comments
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testInterpolateStringContext() {
Context context = mock(Context.class);
ConstraintDescriptor cd = mock(ConstraintDescriptor.class);
Map<String, Object> atts = new HashMap<String, Object>();
when(cd.getAttributes()).thenReturn(atts);
when(context.getConstraintDescriptor()).thenReturn(cd);
Foo foo = new Foo();
when(context.getValidatedValue()).thenReturn(foo);
MessageInterpolator delegate = mock(MessageInterpolator.class);
when(delegate.interpolate("message", context)).thenReturn("MEssAGE");
BeanMessageInterpolator interpolator = new BeanMessageInterpolator(delegate);
interpolator.interpolate("message", context);
assertEquals(foo, atts.get("0"));
}
示例6: resolve
import javax.validation.MessageInterpolator; //導入依賴的package包/類
protected String resolve ( final String key, final Context context, final Locale locale )
{
for ( final Resolver resolver : this.tracker.getTracked ().values () )
{
final String result = resolver.resolve ( key, context, locale );
if ( result != null )
{
return result;
}
}
final MessageInterpolator fallback = this.fallback;
if ( fallback == null )
{
return null;
}
return fallback.interpolate ( String.format ( "{%s}", key ), context, locale );
}
示例7: afterPropertiesSet
import javax.validation.MessageInterpolator; //導入依賴的package包/類
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());
}
示例8: setup
import javax.validation.MessageInterpolator; //導入依賴的package包/類
@Before
public void setup() {
ResourceBundle bundle = new SafeResourceBundle(ResourceBundle.getBundle("messages"));
ValidatorFactory validatorFactory = javax.validation.Validation.buildDefaultValidatorFactory();
javax.validation.Validator bvalidator = validatorFactory.getValidator();
MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();
Proxifier proxifier = new JavassistProxifier();
Messages messages = new Messages();
validator = new DefaultValidator(result, new DefaultValidationViewsFactory(result, proxifier, new DefaultReflectionProvider()),
outjector, proxifier, bundle, bvalidator, interpolator, Locale.ENGLISH, messages);
when(result.use(LogicResult.class)).thenReturn(logicResult);
when(result.use(PageResult.class)).thenReturn(pageResult);
when(logicResult.forwardTo(MyComponent.class)).thenReturn(instance);
when(pageResult.of(MyComponent.class)).thenReturn(instance);
}
示例9: getContext
import javax.validation.MessageInterpolator; //導入依賴的package包/類
@Override
public GeneralValidator getContext(final Class<?> type) {
final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
final Configuration<?> config = Validation.byDefaultProvider().configure()
.messageInterpolator(messageInterpolator);
final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
.getDefaultValidatedExecutableTypes();
return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
defaultValidatedExecutableTypes);
}
示例10: parsePolicy
import javax.validation.MessageInterpolator; //導入依賴的package包/類
public static JsonNode parsePolicy(String jsonString, Map<String, String> service_info, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
logger.info("received policy : " + jsonString); //debug
new_mapper.readValue(jsonString, Policy.class); //for syntax error check
String transfered_json = TransferedPolicy.packServiceInfo(jsonString, service_info);
logger.info("transfered policy after update with service_information : " + transfered_json); //debug
TransferedPolicy policy = new_mapper.readValue(transfered_json, TransferedPolicy.class);
logger.info("we get policy as " + (Obj2Map(policy)).toString());//debug
//additional data manipulation and check again
policy = policy.setMaxInstCount();
HibernateValidatorConfiguration config = BeanValidation.getPolicyRange();
ValidatorFactory vf = config.buildValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<TransferedPolicy>> set = validator.validate(policy);
if (set.size() > 0 ){
for (ConstraintViolation<TransferedPolicy> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
String new_json = policy.transformInput();
logger.info("policy before trigger back : " + new_json); //debug
new_json = TransferedPolicy.unpackServiceInfo(new_json, service_info);
result.put("valid", true);
logger.info("send out policy: " + new_json); //debug
result.put("new_json", new_json);
return result;
}
示例11: parsePolicyOutput
import javax.validation.MessageInterpolator; //導入依賴的package包/類
public static JsonNode parsePolicyOutput(String jsonString, Map<String, String> supplyment, Map<String, String> service_info, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
logger.info("received json: " + jsonString);
String transfered_json = TransferedPolicy.packServiceInfo(jsonString, service_info);
logger.info("transfered policy after update with service_information : " + transfered_json); //debug
TransferedPolicy policy = new_mapper.readValue(transfered_json, TransferedPolicy.class);
logger.info("we get policy as " + (Obj2Map(policy)).toString());//debug
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<TransferedPolicy>> set = validator.validate(policy);
if (set.size() > 0 ){
for (ConstraintViolation<TransferedPolicy> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
policy = policy.transformSchedules();
String new_json = policy.transformOutput(supplyment, service_info);
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例12: parseMetrics
import javax.validation.MessageInterpolator; //導入依賴的package包/類
public static JsonNode parseMetrics(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
//JavaType javaType = getCollectionType(ArrayList.class, HistoryData.class);
//new_mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
logger.info("Received metrics: " + jsonString);
Metrics metrics = new_mapper.readValue(jsonString, Metrics.class);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<Metrics>> set = validator.validate(metrics);
if (set.size() > 0 ){
for (ConstraintViolation<Metrics> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = metrics.transformOutput();
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例13: testInterpolateStringContextLocale
import javax.validation.MessageInterpolator; //導入依賴的package包/類
/**
* JAVADOC Method Level Comments
*/
@SuppressWarnings("unchecked")
@Test
public void testInterpolateStringContextLocale() {
Context context = mock(Context.class);
@SuppressWarnings("rawtypes")
ConstraintDescriptor cd = mock(ConstraintDescriptor.class);
Map<String, Object> atts = new HashMap<String, Object>();
String[] properties = { "name", "value" };
atts.put("properties", properties);
when(cd.getAttributes()).thenReturn(atts);
when(context.getConstraintDescriptor()).thenReturn(cd);
Foo foo = new Foo();
foo.setName("Name");
foo.setValue(200);
when(context.getValidatedValue()).thenReturn(foo);
MessageInterpolator delegate = mock(MessageInterpolator.class);
when(delegate.interpolate("message", context, Locale.getDefault())).thenReturn("MEssAGE");
BeanMessageInterpolator interpolator = new BeanMessageInterpolator(delegate);
interpolator.interpolate("message", context, Locale.getDefault());
assertEquals("Name", atts.get("0"));
assertEquals("200", atts.get("1"));
}
示例14: messageInterpolator
import javax.validation.MessageInterpolator; //導入依賴的package包/類
@Provides
@Singleton
protected MessageInterpolator messageInterpolator(RiseValidationMessageInterpolator interpolator) {
return interpolator;
// return new ResourceBundleMessageInterpolator(
// resolver::getResourceBundle);
}
示例15: GwtValidationContext
import javax.validation.MessageInterpolator; //導入依賴的package包/類
private GwtValidationContext(final Class<T> rootBeanClass, final T rootBean,
final BeanDescriptor beanDescriptor, final MessageInterpolator messageInterpolator,
final TraversableResolver traversableResolver, final AbstractGwtValidator validator,
final Set<Object> validatedObjects) {
this.rootBeanClass = rootBeanClass;
this.rootBean = rootBean;
this.beanDescriptor = beanDescriptor;
this.messageInterpolator = messageInterpolator;
this.traversableResolver = traversableResolver;
this.validator = validator;
this.validatedObjects = new HashSet<>(validatedObjects);
}