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

JCorporate Ltd jcorp at jcorp2.servlets.net
Mon Jul 26 23:14:32 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-serv3631/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n

Modified Files:
	MessageBundle.java 
Log Message:
provide getStringOrNull() to provide ability to test a stack of schemas without error messages if not found.


Index: MessageBundle.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n/MessageBundle.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** MessageBundle.java	8 Jul 2004 05:55:33 -0000	1.21
--- MessageBundle.java	27 Jul 2004 06:14:30 -0000	1.22
***************
*** 225,233 ****
  
      /**
!      * Formats the string code with the appropriate argument array.
       *
       * @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
       * @see java.text.MessageFormat
       */
--- 225,233 ----
  
      /**
!      * Formats the string code with the appropriate argument array. Issues warning log if code is not found.
       *
       * @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 stringCode if not found
       * @see java.text.MessageFormat
       */
***************
*** 432,435 ****
--- 432,467 ----
      }
  
+     /**
+      * Formats the string code with the appropriate argument array. Does NOT issue warning log if code is not found, but rather returns null
+      *
+      * @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 null if not found
+      * @see java.text.MessageFormat
+      */
+     public String getStringOrNull(String stringCode, Object[] args) {
+         try {
+             Locale l = null;
+ 
+             if (myLanguage != null) {
+                 if (myCountry.equals("default")) {
+                     l = new Locale(myLanguage, "");
+                 } else {
+                     l = new Locale(myLanguage, myCountry);
+                 }
+             } else {
+                 l = Locale.getDefault();
+             }
+ 
+             String messageString = getStringFromBundle(l, stringCode);
+             MessageFormat formatter = new MessageFormat("");
+             formatter.setLocale(l);
+             formatter.applyPattern(messageString);
+ 
+             return StringUtil.notNull(formatter.format(args));
+         } catch (Exception se) {
+             return null;
+         }
+     }
  }
  



More information about the cvs mailing list