/**
  * Iterate over the validation result to check for any validation failure. For the very first
  * validation failure, it reads the oneinc-resource.properties encapsulated in member variable
  * apps and set the user friendly message along with the IRC and throws the
  * OneIncValidationException.
  *
  * @param bean - Bean to be validated
  * @param results - contains the validation result
  * @param resources2 - ValidatorResources object prepared for validation-rules.xml
  * @param form - contains the mapping for field and their validation rule.
  * @throws CWValidationException - if validation gets fail.
  */
 @SuppressWarnings({"unchecked", "deprecation"})
 private void checkResults(
     Serializable bean, ValidatorResults results, ValidatorResources resources2, Form form)
     throws CWValidationException {
   Iterator propertyNames = results.getPropertyNames().iterator();
   while (propertyNames.hasNext()) {
     String propertyName = (String) propertyNames.next();
     ValidatorResult result = results.getValidatorResult(propertyName);
     Map actionMap = result.getActionMap();
     Iterator keys = actionMap.keySet().iterator();
     Field field = form.getField(propertyName);
     String prettyFieldName = apps.getString(field.getArg(0).getKey());
     while (keys.hasNext()) {
       String actName = (String) keys.next();
       ValidatorAction action = resources.getValidatorAction(actName);
       if (!result.isValid(actName)) {
         String message = apps.getString(action.getMsg());
         Object[] args = {prettyFieldName};
         String formatMsg = MessageFormat.format(message, args);
         int colonIndex = formatMsg.indexOf(',');
         String imfResponseCode = null;
         String msg = null;
         if (colonIndex > 0) {
           imfResponseCode = formatMsg.substring(0, colonIndex);
           msg = formatMsg.substring(colonIndex);
         }
         throw new CWValidationException(msg, imfResponseCode);
       }
     }
   }
 }
Example #2
0
  /**
   * Gets the locale sensitive message based on the <code>ValidatorAction</code> message and the
   * <code>Field</code>'s arg objects.
   *
   * @param messages The Message resources
   * @param locale The locale
   * @param va The Validator Action
   * @param field The Validator Field
   */
  public static String getMessage(
      MessageResources messages, Locale locale, ValidatorAction va, Field field) {

    String args[] = getArgs(va.getName(), messages, locale, field);
    String msg = field.getMsg(va.getName()) != null ? field.getMsg(va.getName()) : va.getMsg();

    return messages.getMessage(locale, msg, args);
  }
Example #3
0
  /**
   * Gets the <code>ActionMessage</code> based on the <code>ValidatorAction</code> message and the
   * <code>Field</code>'s arg objects.
   *
   * @param request the servlet request
   * @param va Validator action
   * @param field the validator Field
   */
  public static ActionMessage getActionMessage(
      HttpServletRequest request, ValidatorAction va, Field field) {

    String args[] =
        getArgs(
            va.getName(),
            getMessageResources(request),
            RequestUtils.getUserLocale(request, null),
            field);

    String msg = field.getMsg(va.getName()) != null ? field.getMsg(va.getName()) : va.getMsg();

    return new ActionMessage(msg, args);
  }
Example #4
0
  /**
   * Gets the <code>ActionMessage</code> based on the <code>ValidatorAction</code> message and the
   * <code>Field</code>'s arg objects.
   *
   * @param validator the Validator
   * @param request the servlet request
   * @param va Validator action
   * @param field the validator Field
   */
  public static ActionMessage getActionMessage(
      Validator validator, HttpServletRequest request, ValidatorAction va, Field field) {

    Msg msg = field.getMessage(va.getName());
    if (msg != null && !msg.isResource()) {
      return new ActionMessage(msg.getKey(), false);
    }

    String msgKey = null;
    String msgBundle = null;
    if (msg == null) {
      msgKey = va.getMsg();
    } else {
      msgKey = msg.getKey();
      msgBundle = msg.getBundle();
    }

    if (msgKey == null || msgKey.length() == 0) {
      return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
    }

    ServletContext application =
        (ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
    MessageResources messages = getMessageResources(application, request, msgBundle);
    Locale locale = RequestUtils.getUserLocale(request, null);

    Arg[] args = field.getArgs(va.getName());
    String[] argValues = getArgValues(application, request, messages, locale, args);

    ActionMessage actionMessage = null;
    if (msgBundle == null) {
      actionMessage = new ActionMessage(msgKey, argValues);
    } else {
      String message = messages.getMessage(locale, msgKey, argValues);
      actionMessage = new ActionMessage(message, false);
    }
    return actionMessage;
  }
Example #5
0
  /**
   * Gets the <code>Locale</code> sensitive value based on the key passed in.
   *
   * @param application the servlet context
   * @param request the servlet request
   * @param defaultMessages The default Message resources
   * @param locale The locale
   * @param va The Validator Action
   * @param field The Validator Field
   */
  public static String getMessage(
      ServletContext application,
      HttpServletRequest request,
      MessageResources defaultMessages,
      Locale locale,
      ValidatorAction va,
      Field field) {

    Msg msg = field.getMessage(va.getName());
    if (msg != null && !msg.isResource()) {
      return msg.getKey();
    }

    String msgKey = null;
    String msgBundle = null;
    MessageResources messages = defaultMessages;
    if (msg == null) {
      msgKey = va.getMsg();
    } else {
      msgKey = msg.getKey();
      msgBundle = msg.getBundle();
      if (msg.getBundle() != null) {
        messages = getMessageResources(application, request, msg.getBundle());
      }
    }

    if (msgKey == null || msgKey.length() == 0) {
      return "??? " + va.getName() + "." + field.getProperty() + " ???";
    }

    // Get the arguments
    Arg[] args = field.getArgs(va.getName());
    String[] argValues = getArgValues(application, request, messages, locale, args);

    // Return the message
    return messages.getMessage(locale, msgKey, argValues);
  }