当前位置: 首页>>代码示例>>Java>>正文


Java MessageInterpolator类代码示例

本文整理汇总了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();
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:21,代码来源:AbstractGwtSpecificValidator.java

示例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());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CustomValidatorBean.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:25,代码来源:BeanValidation.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:27,代码来源:BeanValidation.java

示例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"));
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:27,代码来源:BeanMessageInterpolatorTest.java

示例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 );
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:20,代码来源:OsgiMessageInterpolator.java

示例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());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:18,代码来源:CustomValidatorBean.java

示例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);
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:19,代码来源:DefaultValidatorTest.java

示例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);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:15,代码来源:ValidatorContextResolver.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:35,代码来源:BeanValidation.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:30,代码来源:BeanValidation.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:30,代码来源:BeanValidation.java

示例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"));
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:34,代码来源:BeanMessageInterpolatorTest.java

示例14: messageInterpolator

import javax.validation.MessageInterpolator; //导入依赖的package包/类
@Provides
@Singleton
protected MessageInterpolator messageInterpolator(RiseValidationMessageInterpolator interpolator) {
    return interpolator;
    // return new ResourceBundleMessageInterpolator(
    // resolver::getResourceBundle);
}
 
开发者ID:ruediste,项目名称:rise,代码行数:8,代码来源:CoreRestartableModule.java

示例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);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:13,代码来源:GwtValidationContext.java


注:本文中的javax.validation.MessageInterpolator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。