Example usage for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable

List of usage examples for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable

Introduction

In this page you can find the example usage for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable.

Prototype

public DefaultMessageSourceResolvable(String[] codes, Object[] arguments) 

Source Link

Document

Create a new DefaultMessageSourceResolvable.

Usage

From source file:cherry.foundation.logicalerror.LogicalErrorUtil.java

public static MessageSourceResolvable resolve(String code, Object... args) {
    return new DefaultMessageSourceResolvable(new String[] { code }, args);
}

From source file:abid.password.springmvc.DefaultFeedbackMessage.java

public void addMessage(String code, Serializable... arguments) {
    messages.add(new DefaultMessageSourceResolvable(new String[] { code }, arguments));
}

From source file:com.asual.summer.core.spring.ExtendedBindingErrorProcessor.java

protected Object[] getArgumentsForBindError(String objectName, String field) {
    String[] codes = new String[] { objectName + Errors.NESTED_PATH_SEPARATOR + field, field };
    return new Object[] { new DefaultMessageSourceResolvable(codes, field), null };
}

From source file:org.obiba.onyx.engine.Stage.java

public MessageSourceResolvable getDescription() {
    // Codes are <module>.<name>.description, <name>.description
    return new DefaultMessageSourceResolvable(
            new String[] { getModule() + "." + getName() + DESCRIPTION_KEY, getName() + DESCRIPTION_KEY },
            getName());//from   w ww  .j  av a2  s .  c  o  m
}

From source file:org.obiba.onyx.core.service.impl.DefaultUserPasswordServiceImpl.java

public List<MessageSourceResolvable> assignPassword(User user, String password) {
    List<MessageSourceResolvable> errors = passwordValidationStrategy.validatePassword(user, password);
    if (errors.size() > 0)
        return errors;
    // validate // problem
    // check for reuse // problem
    boolean newPassword = userService.isNewPassword(user, password); // TODO or userService.isPasswordUsed....
    if (!newPassword) {
        MessageSourceResolvable msg = new DefaultMessageSourceResolvable(
                new String[] { PasswordValidationErrors.OLD_PASSWORD_REUSE.name() },
                "DefaultUserPasswordServiceImpl.cannotReusePassword");
        errors.add(msg);//w w w.j a va 2 s  .  c o  m
        return errors;
    }
    // save
    userService.updatePassword(user, password); // TODO User new api to save
    return errors;
}

From source file:org.openmrs.web.taglib.OpenmrsMessageTagTest.java

/**
 * @see OpenmrsMessageTag#doEndTag()//from   w ww . jav  a 2 s .  c o  m
 */
@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);
}

From source file:org.obiba.onyx.engine.ActionDefinition.java

public MessageSourceResolvable getLabel() {
    return new DefaultMessageSourceResolvable(ActionDefinitionConfiguration.calculateCodes(this, null),
            getType().toString());/*ww w.j  a v  a  2s .  co m*/
}

From source file:org.obiba.onyx.engine.ActionDefinition.java

public MessageSourceResolvable getDescription() {
    return new DefaultMessageSourceResolvable(
            ActionDefinitionConfiguration.calculateCodes(this, ".description"), getType().toString());
}

From source file:org.openmrs.web.taglib.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);/*from ww w .j  ava2 s. com*/
    DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" },
            expectedOutput);
    openmrsMessageTag.setMessage(message);
    openmrsMessageTag.setScope(TagUtils.SCOPE_PAGE);

    checkDoEndTagEvaluationOfVar(varName, PageContext.PAGE_SCOPE, expectedOutput);
}

From source file:org.springjutsu.validation.ValidationErrorMessageHandler.java

/**
 * In the event that a validation rule fails, this method is responsible
 * for recording an error message on the affected path of the Errors object.
 * The error message is gathered in three parts:
 * First the base message, if not provided is based on the rule executor class.
 * This is a message like "\{0} should be longer than \{1} chars."
 * Next, the first argument \{0} is the model descriptor. This will resolve to a 
 * label for the path that failed, based on second to last path subBean and the
 * field that failed. So, if "account.accountOwner.username" had an error, 
 * it would look for a message based on the class name of accountOwner, and the
 * field username: like "user.username". If the message files contained a 
 * "user.username=User name", then the message would now read something like
 * "User name should be longer than \{1} chars." 
 * Finally, the argument is resolved. /* w  w  w. j  ava 2 s. c  o  m*/
 * If the argument is just a flat string, like "16", then you would get 
 * "User name should be longer than 16 chars."
 * If the argument contained EL that resolved on the model, it would perform
 * the same model lookup detailed above, so you could potentially have something 
 * like "User name should be longer than First name", which is a bit weird, but
 * has its uses.
 * For either the model or argument lookup, if EL is used in the path 
 * which resolves off the model, the literal value of the evaluated 
 * EL expression is used.
 * @param rule the rule which failed
 * @param rootModel the root model (not failed bean)
 * @param errors standard Errors object to record error on.
 */
protected void logError(ValidationEvaluationContext context, ValidationRule rule) {
    String localizedRulePath = context.localizePath(rule.getPath());
    String errorMessageKey = rule.getMessage();
    if (errorMessageKey == null || errorMessageKey.isEmpty()) {
        errorMessageKey = (errorMessagePrefix != null && !errorMessagePrefix.isEmpty()
                ? errorMessagePrefix + "."
                : "") + rule.getType();
    }

    String defaultError = localizedRulePath + " " + rule.getType();
    String modelMessageKey = getMessageResolver(context, rule, true);
    String ruleArg = getMessageResolver(context, rule, false);

    MessageSourceResolvable modelMessageResolvable = new DefaultMessageSourceResolvable(
            new String[] { modelMessageKey }, modelMessageKey);
    MessageSourceResolvable argumentMessageResolvable = new DefaultMessageSourceResolvable(
            new String[] { ruleArg }, ruleArg);

    // get the local path to error, in case errors object is on nested path.
    String errorMessagePath = rule.getErrorPath();
    if (errorMessagePath != null && !errorMessagePath.isEmpty()) {
        errorMessagePath = context.localizePath(errorMessagePath);
    } else {
        errorMessagePath = localizedRulePath;
    }

    if (PathUtils.containsEL(errorMessagePath)) {
        throw new IllegalStateException("Could not log error for rule: " + rule.toString()
                + ". Rules with EL path should specify the errorPath attribute.");
    }

    context.getErrors().rejectValue(errorMessagePath, errorMessageKey,
            new Object[] { modelMessageResolvable, argumentMessageResolvable }, defaultError);
}