Ejemplo n.º 1
0
  /**
   * Gets the message arguments based on the current <code>ValidatorAction</code> and <code>Field
   * </code>.
   *
   * @param actionName action name
   * @param messages message resources
   * @param locale the locale
   * @param field the validator field
   */
  public static String[] getArgs(
      String actionName, MessageResources messages, Locale locale, Field field) {

    String[] argMessages = new String[4];

    Arg[] args =
        new Arg[] {
          field.getArg(actionName, 0),
          field.getArg(actionName, 1),
          field.getArg(actionName, 2),
          field.getArg(actionName, 3)
        };

    for (int i = 0; i < args.length; i++) {
      if (args[i] == null) {
        continue;
      }

      if (args[i].isResource()) {
        argMessages[i] = getMessage(messages, locale, args[i].getKey());
      } else {
        argMessages[i] = args[i].getKey();
      }
    }

    return argMessages;
  }
Ejemplo n.º 2
0
 /**
  * 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);
       }
     }
   }
 }