[cvs] expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n Messages.java

JCorporate Ltd jcorp at jcorp2.servlets.net
Sun Sep 12 01:10:04 PDT 2004


Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n
In directory jcorp2.servlets.net:/tmp/cvs-serv32579/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n

Modified Files:
	Messages.java 
Log Message:
provide tools for getString() that doesn't throw


Index: Messages.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n/Messages.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** Messages.java	9 Sep 2004 18:11:33 -0000	1.24
--- Messages.java	12 Sep 2004 08:10:02 -0000	1.25
***************
*** 279,282 ****
--- 279,314 ----
          return result;
      }
+     /**
+      * Convenience method that gets a string using the schemaStack, looping
+      * through it until the key is found
+      *
+      * @param schemaStack A Stack of schemas
+      * @param ourLocale   The specified Locale Object
+      * @param stringCode  The string code to retrieve
+      * @param args        the formatting arguments for the String
+      * @return The properly formatted string as read from the messages bundle or the key if not found
+      * @throws IllegalArgumentException if the given string code doesn't exist in any schema in stack.
+      */
+     public static String getStringUnrequired(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args) throws IllegalArgumentException {
+         String result = null;
+ 
+         for (ListIterator li = schemaStack.listIterator(schemaStack.size()); li.hasPrevious();) {
+             String schema = (String) li.previous();
+             result = getStringOrNull(schema, ourLocale, stringCode, args);
+             if (result != null) {
+                 break;
+             }
+         }
+ 
+         // stack might have been empty, or not included default
+         if (result == null) {
+             // last chance; will throw
+             result = getStringOrNull(defaultSchema, ourLocale, stringCode, args);
+         }
+ 
+         if ( result == null ) result = stringCode;
+ 
+         return result;
+     }
  
      /**



More information about the cvs mailing list