[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n
Messages.java
JCorporate Ltd
jcorp at jcorp2.servlets.net
Thu Sep 9 11:05:44 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-serv11420/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n
Modified Files:
Messages.java
Log Message:
improve getstringrequired to not complain if answer is found anywhere in stack
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.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Messages.java 27 Jul 2004 06:17:26 -0000 1.22
--- Messages.java 9 Sep 2004 18:05:42 -0000 1.23
***************
*** 212,216 ****
* @param stringCode the string code
* @param args any arguments.
! * @return java.lang.String
*/
public static String getString(String schemaClass, Locale l,
--- 212,216 ----
* @param stringCode the string code
* @param args any arguments.
! * @return translated string, or if not found, the stringCode
*/
public static String getString(String schemaClass, Locale l,
***************
*** 258,277 ****
* @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 the given bundle.
*/
public static String getStringRequired(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args) throws IllegalArgumentException {
for (ListIterator li = schemaStack.listIterator(schemaStack.size()); li.hasPrevious();) {
! try {
! String schema = (String) li.previous();
! return getStringRequired(schema, ourLocale, stringCode, args);
! } catch (IllegalArgumentException ex) {
! if (!li.hasPrevious()) {
! return getString(defaultSchema, ourLocale, stringCode, args);
! }
}
}
! return getStringRequired(defaultSchema, ourLocale, stringCode, args);
! } /* getString(String, String) */
/**
--- 258,282 ----
* @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 getStringRequired(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args) throws IllegalArgumentException {
+ String result = stringCode;
+
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 = getStringRequired(defaultSchema, ourLocale, stringCode, args);
! }
!
! return result;
! }
/**
***************
*** 356,362 ****
}
- // // one last try for default schema
- // if ( result == null ) result = getStringOrNull(defaultSchema, ourLocale, stringCode, args);
-
if (result == null) {
result = stringCode;
--- 361,364 ----
***************
*** 395,399 ****
* @param stringCode
* @param args
! * @return
*/
public static String getString(String schemaClass, HttpServletRequest req,
--- 397,401 ----
* @param stringCode
* @param args
! * @return translated string, or if not found, the stringCode
*/
public static String getString(String schemaClass, HttpServletRequest req,
***************
*** 418,421 ****
--- 420,425 ----
/**
* getString(schema, locale, stringCode)
+ *
+ * @return translated string, or if not found, the stringCode
*/
public static String getString(String schemaClass, Locale l, String stringCode) {
***************
*** 623,630 ****
* @param stringCode
* @param args
! * @return
*/
public static String getString(String schemaClass, String stringCode,
Object[] args) {
String language = "en";
String country = "US";
--- 627,647 ----
* @param stringCode
* @param args
! * @return translated string, or if not found, the stringCode
*/
public static String getString(String schemaClass, String stringCode,
Object[] args) {
+ Locale theLocale = getDefaultLocale();
+
+ return getString(schemaClass, theLocale,
+ stringCode, args);
+ }
+
+ /**
+ * get default locale (much better to get it from user's request!!)
+ *
+ * @return locale based on 'default' config context
+ * @see #getLocale(javax.servlet.http.HttpServletRequest)
+ */
+ public static Locale getDefaultLocale() {
String language = "en";
String country = "US";
***************
*** 638,647 ****
}
! return getString(schemaClass, new Locale(language, country),
! stringCode, args);
! } /* getString(String, String, Object[]) */
/**
! * Convenience method to use the current default schema
*
* @param uid
--- 655,665 ----
}
! Locale theLocale = new Locale(language, country);
! return theLocale;
! }
/**
! * use locale based on user ID, which is set as user preference;
! * use with discrimination--it may be better to get locale from request
*
* @param uid
***************
*** 650,654 ****
* @param stringCode
* @param args
! * @return
*/
public static String getStringForUser(int uid, String dbName,
--- 668,673 ----
* @param stringCode
* @param args
! * @return translated string, or if not found, the stringCode
! * @see #getString(java.util.Locale, String)
*/
public static String getStringForUser(int uid, String dbName,
***************
*** 715,719 ****
* @param req
* @param stringCode
! * @return
*/
public static String getString(HttpServletRequest req, String stringCode)
--- 734,738 ----
* @param req
* @param stringCode
! * @return translated string, or if not found, the stringCode
*/
public static String getString(HttpServletRequest req, String stringCode)
More information about the cvs
mailing list