dgraham     2003/07/01 20:29:27

  Modified:    src/share/org/apache/struts/validator Resources.java
  Log:
  Rewrote getArgs() method to use arrays and loops which considerably 
  decreased the length of the method.  This can improve even more when
  commons-validator 1.1 is released because it unifies the Arg handling into
  arrays instead of a limited number (4) of args.
  
  Revision  Changes    Path
  1.14      +32 -50    
jakarta-struts/src/share/org/apache/struts/validator/Resources.java
  
  Index: Resources.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/validator/Resources.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Resources.java    2 Jul 2003 03:19:43 -0000       1.13
  +++ Resources.java    2 Jul 2003 03:29:27 -0000       1.14
  @@ -209,54 +209,36 @@
       * @param locale   the locale
       * @param field the validator field
       */
  -   public static String[] getArgs(String actionName, MessageResources messages,
  -                                  Locale locale, Field field) {
  +    public static String[] getArgs(
  +        String actionName,
  +        MessageResources messages,
  +        Locale locale,
  +        Field field) {
  +
  +        String[] argMessages = new String[4];
  +
  +        Arg[] args =
  +            new Arg[] {
  +                field.getArg0(actionName),
  +                field.getArg1(actionName),
  +                field.getArg2(actionName),
  +                field.getArg3(actionName)};
  +
  +        for (int i = 0; i < args.length; i++) {
  +            if (args[i] == null) {
  +                continue;
  +            }
  +
  +            if (args[i].getResource()) {
  +                argMessages[i] = getMessage(messages, locale, args[i].getKey());
  +            } else {
  +                argMessages[i] = args[i].getKey();
  +            }
   
  -      Arg arg0 = field.getArg0(actionName);
  -      Arg arg1 = field.getArg1(actionName);
  -      Arg arg2 = field.getArg2(actionName);
  -      Arg arg3 = field.getArg3(actionName);
  -
  -      String sArg0 = null;
  -      String sArg1 = null;
  -      String sArg2 = null;
  -      String sArg3 = null;
  -
  -      if (arg0 != null) {
  -         if (arg0.getResource()) {
  -            sArg0 = getMessage(messages, locale, arg0.getKey());
  -         } else {
  -            sArg0 = arg0.getKey();
  -         }
  -      }
  -
  -      if (arg1 != null) {
  -         if (arg1.getResource()) {
  -            sArg1 = getMessage(messages, locale, arg1.getKey());
  -         } else {
  -            sArg1 = arg1.getKey();
  -         }
  -      }
  -
  -      if (arg2 != null) {
  -         if (arg2.getResource()) {
  -            sArg2 = getMessage(messages, locale, arg2.getKey());
  -         } else {
  -            sArg2 = arg2.getKey();
  -         }
  -      }
  -
  -      if (arg3 != null) {
  -         if (arg3.getResource()) {
  -            sArg3 = getMessage(messages, locale, arg3.getKey());
  -         } else {
  -            sArg3 = arg3.getKey();
  -         }
  -      }
  +        }
   
  -      return new String[] { sArg0, sArg1, sArg2, sArg3 };
  -
  -   }
  +        return argMessages;
  +    }
   
      /**
       * Initialize the <code>Validator</code> to perform validation.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to