Java 类org.springframework.context.support.DefaultMessageSourceResolvable 实例源码

项目:lams    文件:SpringValidatorAdapter.java   
/**
 * Return FieldError arguments for a validation error on the given field.
 * Invoked for each violated constraint.
 * <p>The default implementation returns a first argument indicating the field name
 * (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
 * Afterwards, it adds all actual constraint annotation attributes (i.e. excluding
 * "message", "groups" and "payload") in alphabetical order of their attribute names.
 * <p>Can be overridden to e.g. add further attributes from the constraint descriptor.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @param descriptor the JSR-303 constraint descriptor
 * @return the Object array that represents the FieldError arguments
 * @see org.springframework.validation.FieldError#getArguments
 * @see org.springframework.context.support.DefaultMessageSourceResolvable
 * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
 */
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
    List<Object> arguments = new LinkedList<Object>();
    String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
    arguments.add(new DefaultMessageSourceResolvable(codes, field));
    // Using a TreeMap for alphabetical ordering of attribute names
    Map<String, Object> attributesToExpose = new TreeMap<String, Object>();
    for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
        String attributeName = entry.getKey();
        Object attributeValue = entry.getValue();
        if (!internalAnnotationAttributes.contains(attributeName)) {
            attributesToExpose.put(attributeName, attributeValue);
        }
    }
    arguments.addAll(attributesToExpose.values());
    return arguments.toArray(new Object[arguments.size()]);
}
项目:spring4-understanding    文件:SpringValidatorAdapter.java   
/**
 * Return FieldError arguments for a validation error on the given field.
 * Invoked for each violated constraint.
 * <p>The default implementation returns a first argument indicating the field name
 * (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
 * Afterwards, it adds all actual constraint annotation attributes (i.e. excluding
 * "message", "groups" and "payload") in alphabetical order of their attribute names.
 * <p>Can be overridden to e.g. add further attributes from the constraint descriptor.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @param descriptor the JSR-303 constraint descriptor
 * @return the Object array that represents the FieldError arguments
 * @see org.springframework.validation.FieldError#getArguments
 * @see org.springframework.context.support.DefaultMessageSourceResolvable
 * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
 */
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
    List<Object> arguments = new LinkedList<Object>();
    String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
    arguments.add(new DefaultMessageSourceResolvable(codes, field));
    // Using a TreeMap for alphabetical ordering of attribute names
    Map<String, Object> attributesToExpose = new TreeMap<String, Object>();
    for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
        String attributeName = entry.getKey();
        Object attributeValue = entry.getValue();
        if (!internalAnnotationAttributes.contains(attributeName)) {
            attributesToExpose.put(attributeName, attributeValue);
        }
    }
    arguments.addAll(attributesToExpose.values());
    return arguments.toArray(new Object[arguments.size()]);
}
项目:spring4-understanding    文件:MessageTagTests.java   
@Test
public void messageTagWithMessageSourceResolvable() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer message = new StringBuffer();
    MessageTag tag = new MessageTag() {
        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setMessage(new DefaultMessageSourceResolvable("test"));
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
    assertEquals("Correct message", "test message", message.toString());
}
项目:spring4-understanding    文件:MessageTagTests.java   
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
    assertEquals("test message", rc.getMessage("test"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null));
    assertEquals("test message", rc.getMessage("test", "default"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
    assertEquals("test arg1 message arg2",
            rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
    assertEquals("test arg1 message arg2",
            rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
    assertEquals("default", rc.getMessage("testa", "default"));
    assertEquals("default", rc.getMessage("testa", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
    assertEquals("test message", rc.getMessage(resolvable));
}
项目:spring4-understanding    文件:ThemeTagTests.java   
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
    assertEquals("theme test message", rc.getThemeMessage("themetest"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
    assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
    assertEquals("theme test message arg1",
            rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
    assertEquals("theme test message arg1",
            rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
    assertEquals("default", rc.getThemeMessage("themetesta", "default"));
    assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
    assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
项目:my-spring-cache-redis    文件:SpringValidatorAdapter.java   
/**
 * Return FieldError arguments for a validation error on the given field.
 * Invoked for each violated constraint.
 * <p>The default implementation returns a first argument indicating the field name
 * (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
 * Afterwards, it adds all actual constraint annotation attributes (i.e. excluding
 * "message", "groups" and "payload") in alphabetical order of their attribute names.
 * <p>Can be overridden to e.g. add further attributes from the constraint descriptor.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @param descriptor the JSR-303 constraint descriptor
 * @return the Object array that represents the FieldError arguments
 * @see org.springframework.validation.FieldError#getArguments
 * @see org.springframework.context.support.DefaultMessageSourceResolvable
 * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
 */
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
    List<Object> arguments = new LinkedList<Object>();
    String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
    arguments.add(new DefaultMessageSourceResolvable(codes, field));
    // Using a TreeMap for alphabetical ordering of attribute names
    Map<String, Object> attributesToExpose = new TreeMap<String, Object>();
    for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
        String attributeName = entry.getKey();
        Object attributeValue = entry.getValue();
        if (!internalAnnotationAttributes.contains(attributeName)) {
            attributesToExpose.put(attributeName, attributeValue);
        }
    }
    arguments.addAll(attributesToExpose.values());
    return arguments.toArray(new Object[arguments.size()]);
}
项目:eMonocot    文件:GroupController.java   
/**
 *
 * @param group
 *            Set the group to create
 * @param page Set the page number
 * @param size Set the page size
 * @param result
 *            Set the binding result
 * @param model
 *            Set the model
 * @param session Set the session
 * @return the name of the view
 */
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid Group group,
        BindingResult result,
        Model model,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "group/create";
    }
    getService().save(group);
    String[] codes = new String[] {"group.created" };
    Object[] args = new Object[] {group.getIdentifier()};
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group";
}
项目:eMonocot    文件:GroupController.java   
/**
 * @param identifier
 *            Set the identifier of the group
 * @param ace Set the ace
 * @param session Set the session
 * @return the view name
 */
@RequestMapping(value = "/{identifier}", params = { "aces", "!delete" }, method = RequestMethod.POST, produces = "text/html")
public String addAce(@PathVariable String identifier,
        @ModelAttribute("ace") AceDto ace,
        RedirectAttributes redirectAttributes) {
    SecuredObject object = conversionService.convert(ace,
            SecuredObject.class);
    getService().addPermission(object, identifier, ace.getPermission(),
            ace.getClazz());
    String[] codes = new String[] {"ace.added.to.group" };
    Object[] args = new Object[] {
            conversionService.convert(ace.getPermission(), String.class),
            ace.getClazz().getSimpleName(), ace.getObject() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group/" + identifier + "?form";
}
项目:eMonocot    文件:GroupController.java   
/**
 * @param identifier
 *            Set the identifier of the group
 * @param object
 *            Set the identifier of the secured object
 * @param clazz Set the class of the secured object
 * @param session Set the session
 * @param permission Set the permission
 * @return the view name
 */
@RequestMapping(value = "/{identifier}", params = { "aces",
"delete" }, method = RequestMethod.GET, produces = "text/html")
public String removeAce(@PathVariable String identifier,
        @RequestParam String object,
        @RequestParam Class clazz,
        @RequestParam @PermissionFormat Permission permission,
        RedirectAttributes redirectAttributes) {
    AceDto ace = new AceDto();
    ace.setClazz(clazz);
    ace.setObject(object);
    ace.setPrincipal(identifier);
    SecuredObject securedObject = conversionService.convert(ace,
            SecuredObject.class);
    getService().deletePermission(securedObject, identifier, permission, clazz);
    String[] codes = new String[] {"ace.removed.from.group" };
    Object[] args = new Object[] {
            conversionService.convert(permission, String.class),
            clazz.getSimpleName(), ace.getObject() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group/" + identifier + "?form";
}
项目:eMonocot    文件:OrganisationController.java   
/**
 * @param session
 *            Set the session
 * @param organisation
 *            Set the source
 * @param result
 *            Set the binding results
 * @return a model and view
 */
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String post(@Valid Organisation organisation,
        BindingResult result, RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "organisation/create";
    }

    getService().saveOrUpdate(organisation);
    String[] codes = new String[] { "organisation.was.created" };
    Object[] args = new Object[] { organisation.getTitle() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/organisation";
}
项目:eMonocot    文件:ResourceController.java   
/**
 * @param identifier
 *            Set the sourceId
 * @param model
 *            Set the model
 * @param session
 *            Set the session
 * @param resource
 *            Set the job
 * @param result
 *            Set the binding results
 * @return a model and view
 */
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(Model model,
     @Validated({Default.class, ReadResource.class}) Resource resource,
     BindingResult result,
     RedirectAttributes redirectAttributes) {

 if (result.hasErrors()) {
     populateForm(model, resource, new ResourceParameterDto());
     return "resource/create";
 }

 logger.error("Creating Resource " + resource + " with organisation " + resource.getOrganisation());
 getService().saveOrUpdate(resource);
 String[] codes = new String[] { "resource.was.created" };
 Object[] args = new Object[] { resource.getTitle() };
 DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
 redirectAttributes.addFlashAttribute("info", message);

 return "redirect:/resource";
}
项目:kaif    文件:AbstractRestExceptionHandler.java   
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
    HttpHeaders headers,
    HttpStatus status,
    WebRequest request) {

  //TODO detail i18n and missing parameter name
  final String detail = ex.getBindingResult()
      .getAllErrors()
      .stream()
      .map(DefaultMessageSourceResolvable::getDefaultMessage)
      .collect(joining(", "));
  final E errorResponse = createErrorResponse(status,
      i18n(request, "rest-error.MethodArgumentNotValidException", detail));
  logException(ex, errorResponse, request);
  return new ResponseEntity<>(errorResponse, status);
}
项目:class-guard    文件:SpringValidatorAdapter.java   
/**
 * Return FieldError arguments for a validation error on the given field.
 * Invoked for each violated constraint.
 * <p>The default implementation returns a first argument indicating the field name
 * (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
 * Afterwards, it adds all actual constraint annotation attributes (i.e. excluding
 * "message", "groups" and "payload") in alphabetical order of their attribute names.
 * <p>Can be overridden to e.g. add further attributes from the constraint descriptor.
 * @param objectName the name of the target object
 * @param field the field that caused the binding error
 * @param descriptor the JSR-303 constraint descriptor
 * @return the Object array that represents the FieldError arguments
 * @see org.springframework.validation.FieldError#getArguments
 * @see org.springframework.context.support.DefaultMessageSourceResolvable
 * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
 */
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
    List<Object> arguments = new LinkedList<Object>();
    String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
    arguments.add(new DefaultMessageSourceResolvable(codes, field));
    // Using a TreeMap for alphabetical ordering of attribute names
    Map<String, Object> attributesToExpose = new TreeMap<String, Object>();
    for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
        String attributeName = entry.getKey();
        Object attributeValue = entry.getValue();
        if (!internalAnnotationAttributes.contains(attributeName)) {
            attributesToExpose.put(attributeName, attributeValue);
        }
    }
    arguments.addAll(attributesToExpose.values());
    return arguments.toArray(new Object[arguments.size()]);
}
项目:class-guard    文件:MessageTagTests.java   
@SuppressWarnings("serial")
public void testMessageTagWithMessageSourceResolvable2() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer message = new StringBuffer();
    MessageTag tag = new MessageTag() {
        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    pc.setAttribute("myattr", new DefaultMessageSourceResolvable("test"));
    tag.setMessage("${myattr}");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertEquals("Correct message", "test message", message.toString());
}
项目:class-guard    文件:MessageTagTests.java   
public void testRequestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
    assertEquals("test message", rc.getMessage("test"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null));
    assertEquals("test message", rc.getMessage("test", "default"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
    assertEquals("test arg1 message arg2",
            rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
    assertEquals("test arg1 message arg2",
            rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
    assertEquals("default", rc.getMessage("testa", "default"));
    assertEquals("default", rc.getMessage("testa", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
    assertEquals("test message", rc.getMessage(resolvable));
}
项目:class-guard    文件:ThemeTagTests.java   
public void testRequestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
    assertEquals("theme test message", rc.getThemeMessage("themetest"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
    assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
    assertEquals("theme test message arg1",
            rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
    assertEquals("theme test message arg1",
            rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
    assertEquals("default", rc.getThemeMessage("themetesta", "default"));
    assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
    assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
项目:springapp    文件:DeindexMessageSource.java   
private MessageSourceResolvable parse2(String code, Object[] args, String defaultMessage) {

        List<MessageSourceResolvable> params = new ArrayList<>();

        Matcher m = pattern.matcher(code);
        boolean result = m.find();
        if (!result) {
            return new DefaultMessageSourceResolvable(new String[] { code }, getArgs(params, args), defaultMessage);
        }

        StringBuffer sb = new StringBuffer();
        do {
            String s = m.group(1);
            params.add(create(sb.toString(), s));
            m.appendReplacement(sb, "[]");
            result = m.find();
        } while (result);
        m.appendTail(sb);

        return new DefaultMessageSourceResolvable(new String[] { code, sb.toString() }, getArgs(params, args),
                defaultMessage);
    }
项目:spring-rich-client    文件:PropertyColumn.java   
/**
 * Returns the header to be used as column title. If no explicit header was set, the headerKeys are used
 * to fetch a message from the available resources.
 */
public String getHeader()
{
    if (this.header == null)
    {
        if (this.headerKeys == null)
        {
            this.headerKeys = new String[2];
            this.headerKeys[0] = getPropertyName() + ".header";
            this.headerKeys[1] = getPropertyName();
        }
        this.header = RcpSupport.getMessage(new DefaultMessageSourceResolvable(this.headerKeys, null,
                this.headerKeys[this.headerKeys.length - 1]));
    }
    // JTableHeader has a reusable defaultHeaderRenderer on which the default height must be correct.
    // when painting, the columns headers are processed in order and height is being calculated, 
    // if label is null or empty string header height is 4 and thus leaves us with a very small
    // table-header, fix this by returning a space (-> font-size is incorporated)
    return "".equals(this.header) ? " " : this.header;
}
项目:spring-rich-client    文件:TitleConfigurableBeanPostProcessor.java   
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
    if (bean instanceof TitleConfigurable) {
        TitleConfigurable configurable = (TitleConfigurable) bean;

        try {
            String title = messageSource.getMessage(new DefaultMessageSourceResolvable(name + "." + TITLE_KEY),
                    Locale.getDefault());

            if (StringUtils.hasText(title)) {
                configurable.setTitle(title);
            }
        }
        catch (NoSuchMessageException e) {
            throw new BeanInitializationException("Unable to initialize bean " + name, e);
        }
    }

    return bean;
}
项目:spring-rich-client    文件:LabelConfigurableBeanPostProcessor.java   
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
    if (bean instanceof LabelConfigurable) {
        LabelConfigurable configurable = (LabelConfigurable) bean;

        try {
            String label = messageSource.getMessage(new DefaultMessageSourceResolvable(name + "." + LABEL_KEY),
                    Locale.getDefault());

            if (StringUtils.hasText(label)) {
                configurable.setLabelInfo(LabelInfo.valueOf(label));
            }
        }
        catch (NoSuchMessageException e) {
            throw new BeanInitializationException("Unable to initialize bean " + name, e);
        }
    }

    return bean;
}
项目:molgenis    文件:SpringExceptionHandlerTest.java   
@BeforeClass
public void beforeClass()
{
    AllPropertiesMessageSource molgenisLocalizationMessages = new AllPropertiesMessageSource();
    molgenisLocalizationMessages.addMolgenisNamespaces("web");
    ResourceBundleMessageSource hibernateValidationMessages = new ResourceBundleMessageSource();
    hibernateValidationMessages.addBasenames("org.hibernate.validator.ValidationMessages");
    molgenisLocalizationMessages.setParentMessageSource(hibernateValidationMessages);
    MessageSourceHolder.setMessageSource(molgenisLocalizationMessages);

    globalError = new ObjectError("entityCollectionRequestV2", new String[] { "TwoFieldsSet" }, new Object[] { 1 },
            "must have two fields set");
    fieldError = new FieldError("entityCollectionRequestV2", "num", -10, false,
            new String[] { "Min.entityCollectionRequestV2.num", "Min.num", "Min.int", "Min" }, new Object[] {
            new DefaultMessageSourceResolvable(new String[] { "entityCollectionRequestV2.num", "num" }, null,
                    "num"), 0 }, "must be greater than or equal to 0");
}
项目:spring-richclient    文件:PropertyColumn.java   
/**
 * Returns the header to be used as column title. If no explicit header was set, the headerKeys are used
 * to fetch a message from the available resources.
 */
public String getHeader()
{
    if (this.header == null)
    {
        if (this.headerKeys == null)
        {
            this.headerKeys = new String[2];
            this.headerKeys[0] = getPropertyName() + ".header";
            this.headerKeys[1] = getPropertyName();
        }
        this.header = RcpSupport.getMessage(new DefaultMessageSourceResolvable(this.headerKeys, null,
                this.headerKeys[this.headerKeys.length - 1]));
    }
    // JTableHeader has a reusable defaultHeaderRenderer on which the default height must be correct.
    // when painting, the columns headers are processed in order and height is being calculated, 
    // if label is null or empty string header height is 4 and thus leaves us with a very small
    // table-header, fix this by returning a space (-> font-size is incorporated)
    return "".equals(this.header) ? " " : this.header;
}
项目:spring-richclient    文件:TitleConfigurableBeanPostProcessor.java   
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
    if (bean instanceof TitleConfigurable) {
        TitleConfigurable configurable = (TitleConfigurable) bean;

        try {
            String title = messageSource.getMessage(new DefaultMessageSourceResolvable(name + "." + TITLE_KEY),
                    Locale.getDefault());

            if (StringUtils.hasText(title)) {
                configurable.setTitle(title);
            }
        }
        catch (NoSuchMessageException e) {
            throw new BeanInitializationException("Unable to initialize bean " + name, e);
        }
    }

    return bean;
}
项目:spring-richclient    文件:LabelConfigurableBeanPostProcessor.java   
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
    if (bean instanceof LabelConfigurable) {
        LabelConfigurable configurable = (LabelConfigurable) bean;

        try {
            String label = messageSource.getMessage(new DefaultMessageSourceResolvable(name + "." + LABEL_KEY),
                    Locale.getDefault());

            if (StringUtils.hasText(label)) {
                configurable.setLabelInfo(LabelInfo.valueOf(label));
            }
        }
        catch (NoSuchMessageException e) {
            throw new BeanInitializationException("Unable to initialize bean " + name, e);
        }
    }

    return bean;
}
项目:unity    文件:ValidationExceptionHandler.java   
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity handleMethodArgumentNotValidException(
        final MethodArgumentNotValidException exception,
        final HttpServletRequest req) {
    log.warn("Processing method argument not valid exception: {}", exception.getMessage());

    final String message = exception.getBindingResult().getFieldErrors()
            .stream()
            .map(DefaultMessageSourceResolvable::getDefaultMessage)
            .collect(Collectors.joining("\n"));

    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ExceptionResponse(message));
}
项目:PlutusAPI    文件:EndpointUtils.java   
public static ResponseEntity<Response> createErrorResponse( BindingResult result ){
    Response.Builder response = new Response.Builder();
    response.errors( result.getAllErrors()
            .stream()
            .map( DefaultMessageSourceResolvable::getDefaultMessage )
            .collect( Collectors.toList() )
    );
    return new ResponseEntity<>( response.meta( Meta.badRequest() ).build(), HttpStatus.BAD_REQUEST );
}
项目:eMonocot    文件:PhylogeneticTreeController.java   
@RequestMapping(value = "/{id}",  method = RequestMethod.GET, params = "delete", produces = "text/html")
public String delete(@PathVariable Long id, RedirectAttributes redirectAttributes) {
    PhylogeneticTree tree = getService().load(id);
    getService().deleteById(id);
    String[] codes = new String[] { "phylogeny.deleted" };
    Object[] args = new Object[] { tree.getTitle() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/search?facet=base.class_s%3aorg.emonocot.model.PhylogeneticTree";
}
项目:eMonocot    文件:IdentificationKeyController.java   
@RequestMapping(value = "/{id}",  method = RequestMethod.GET, params = "delete", produces = "text/html")
public String delete(@PathVariable Long id, RedirectAttributes redirectAttributes) {
    IdentificationKey key = getService().load(id);
    getService().deleteById(id);
    String[] codes = new String[] { "key.deleted" };
    Object[] args = new Object[] { key.getTitle() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/search?facet=base.class_s%3aorg.emonocot.model.IdentificationKey";
}
项目:eMonocot    文件:GroupController.java   
/**
 * @param identifier
 *            Set the identifier of the group
 * @param user the user to add to the group
 * @param session Set the session
 * @return the view name
 */
@RequestMapping(value = "/{groupIdentifier}", params = { "members", "!delete" }, method = RequestMethod.POST, produces = "text/html")
public String addMember(@PathVariable String groupIdentifier,
        @ModelAttribute("user") User user,
        RedirectAttributes redirectAttributes) {
    userService.addUserToGroup(user.getUsername(), groupIdentifier);
    String[] codes = new String[] {"user.added.to.group" };
    Object[] args = new Object[] {user.getUsername() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group/" + groupIdentifier + "?form";
}
项目:eMonocot    文件:GroupController.java   
/**
 * @param identifier
 *            Set the identifier of the group
 * @param user Set the user to remove
 * @param session Set the session
 * @return the view name
 */
@RequestMapping(value = "/{groupIdentifier}", params = { "members",
"delete" }, method = RequestMethod.GET, produces = "text/html")
public String removeMember(@PathVariable String groupIdentifier,
        @RequestParam String user, RedirectAttributes redirectAttributes) {
    userService.removeUserFromGroup(user, groupIdentifier);
    String[] codes = new String[] {"user.removed.from.group" };
    Object[] args = new Object[] {user };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(
            codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group/" + groupIdentifier + "?form";
}
项目:eMonocot    文件:GroupController.java   
@RequestMapping(value = "/{identifier}",  method = RequestMethod.GET, params = "delete", produces = "text/html")
public String delete(@PathVariable String identifier, RedirectAttributes redirectAttributes) {
    Group group = getService().find(identifier);
    userService.deleteGroup(identifier);
    String[] codes = new String[] { "group.deleted" };
    Object[] args = new Object[] { group.getName() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/group";
}
项目:eMonocot    文件:UserController.java   
@RequestMapping(value = "/{id}",  method = RequestMethod.GET, params = "delete", produces = "text/html")
public String delete(@PathVariable Long id, RedirectAttributes redirectAttributes) {
    User user = getService().find(id);
    getService().deleteUser(user.getUsername());
    String[] codes = new String[] { "user.deleted" };
    Object[] args = new Object[] { user.getUsername() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/user";
}
项目:eMonocot    文件:OrganisationController.java   
/**
 * @param organisationId
 *            Set the identifier
 * @param session
 *            Set the session
 * @param organisation
 *            Set the source
 * @param result
 *            Set the binding results
 * @return the model name
 */
@RequestMapping(value = "/{organisationId}", method = RequestMethod.POST, produces = "text/html")
public String post(
        @PathVariable String organisationId,
        @Valid Organisation organisation, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "organisation/update";
    }
    Organisation persistedSource = getService().load(organisationId);
    persistedSource.setTitle(organisation.getTitle());
    persistedSource.setUri(organisation.getUri());
    persistedSource.setCreator(organisation.getCreator());
    persistedSource.setCreatorEmail(organisation.getCreatorEmail());
    persistedSource.setCreated(organisation.getCreated());
    persistedSource.setDescription(organisation.getDescription());
    persistedSource.setPublisherName(organisation.getPublisherName());
    persistedSource.setPublisherEmail(organisation.getPublisherEmail());
    persistedSource.setCommentsEmailedTo(organisation.getCommentsEmailedTo());
    persistedSource.setInsertCommentsIntoScratchpad(organisation.getInsertCommentsIntoScratchpad());
    persistedSource.setSubject(organisation.getSubject());
    persistedSource.setBibliographicCitation(organisation.getBibliographicCitation());
    persistedSource.setLogoUrl(organisation.getLogoUrl());
    persistedSource.setFooterLogoPosition(organisation.getFooterLogoPosition());
    getService().saveOrUpdate(persistedSource);
    String[] codes = new String[] { "organisation.updated" };
    Object[] args = new Object[] { organisation.getTitle() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/organisation/" + organisationId;
}
项目:eMonocot    文件:OrganisationController.java   
@RequestMapping(value = "/{identifier}",  method = RequestMethod.GET, params = {"delete"}, produces = "text/html")
public String delete(@PathVariable String identifier, RedirectAttributes redirectAttributes) {
    Organisation organisation = getService().find(identifier);
    getService().delete(identifier);
    String[] codes = new String[] { "organisation.deleted" };
    Object[] args = new Object[] { organisation.getTitle() };
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
    redirectAttributes.addFlashAttribute("info", message);
    return "redirect:/organisation";
}
项目:eMonocot    文件:ResourceController.java   
/**
 * @param organisationId
 *            Set the identifier of the source
 * @param resourceId the identifier of the job
 * @param name the name of the parameter to add
 * @param session Set the session
 * @return the view name
 */
@RequestMapping(value = "/{resourceId}", params = { "parameters", "!delete" }, method = RequestMethod.POST)
public String addParameter(@PathVariable Long resourceId,
     @ModelAttribute("parameter") ResourceParameterDto parameter,
     RedirectAttributes redirectAttributes) {
 Resource resource = getService().load(resourceId);
 resource.getParameters().put(parameter.getName(), "");
 getService().saveOrUpdate(resource);
 String[] codes = new String[] {"parameter.added.to.resource" };
 Object[] args = new Object[] { parameter.getName() };
 DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
 redirectAttributes.addFlashAttribute("info", message);
 return "redirect:/resource/{resourceId}?form=true";
}
项目:eMonocot    文件:ResourceController.java   
/**
 * @param organisationId
 *            Set the identifier of the source
 * @param resourceId Set the job identifier
 * @param name the name of the parameter to delete
 * @param session Set the session
 * @return the view name
 */
@RequestMapping(value = "/{resourceId}", params = { "parameters", "delete" }, method = RequestMethod.GET)
public String removeParameter(@PathVariable Long resourceId,
     @RequestParam("name") String name, RedirectAttributes redirectAttributes) {
 Resource resource = getService().load(resourceId);
 resource.getParameters().remove(name);
 getService().saveOrUpdate(resource);
 String[] codes = new String[] {"parameter.removed.from.resource" };
 Object[] args = new Object[] { name };
 DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
 redirectAttributes.addFlashAttribute("info", message);
 return "redirect:/resource/{resourceId}?form=true";
}
项目:eMonocot    文件:ResourceController.java   
@RequestMapping(value = "/{id}",  method = RequestMethod.GET, params = "delete", produces = "text/html")
public String delete(@PathVariable Long id, RedirectAttributes redirectAttributes) {
 Resource resource = getService().find(id);
 getService().deleteById(id);
 String[] codes = new String[] { "resource.deleted" };
 Object[] args = new Object[] { resource.getTitle() };
 DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(codes, args);
 redirectAttributes.addFlashAttribute("info", message);
 return "redirect:/resource";
}
项目:openmrs-module-legacyui    文件:OpenmrsMessageTagTest.java   
/**
 * @see OpenmrsMessageTag#doEndTag()
 */
@Test
@Verifies(value = "evaluate specified message resolvable", method = "doEndTag()")
public void doEndTag_shouldEvaluateSpecifiedMessageResolvable() throws Exception {
    String expectedOutput = "this is a test";
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" }, expectedOutput);
    openmrsMessageTag.setMessage(message);

    checkDoEndTagEvaluation(expectedOutput);
}
项目:openmrs-module-legacyui    文件:OpenmrsMessageTagTest.java   
@Test
@Verifies(value = "resolve a Tag with var not set to null", method = "doEndTag()")
public void doEndTag_shouldEvaluateVarIfIsNotNull() throws Exception {
    final String varName = "Mary";
    final String expectedOutput = "had a little lamb"; 
    openmrsMessageTag.setVar(varName);
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" }, expectedOutput);
    openmrsMessageTag.setMessage(message);
    openmrsMessageTag.setScope(TagUtils.SCOPE_PAGE);

    checkDoEndTagEvaluationOfVar(varName, PageContext.PAGE_SCOPE, expectedOutput);
}
项目:openmrs-module-legacyui    文件:OpenmrsMessageTagTest.java   
/**
 * @see OpenmrsMessageTag#doEndTag()
 */
@Test
@Verifies(value = "javaScript escaping works when activated", method = "doEndTag()")
public void doEndTag_javaScriptEscapingWorks() throws Exception {
    final String unescapedText = "'Eensy Weensy' spider";
    openmrsMessageTag.setJavaScriptEscape("true");
    final DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" }, unescapedText);
    openmrsMessageTag.setMessage(message);

    checkDoEndTagEvaluation("\\'Eensy Weensy\\' spider");
}