[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n
Messages.java
JCorporate Ltd
jcorp at jcorp2.servlets.net
Mon Jul 26 23:17:28 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-serv3791/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/i18n
Modified Files:
Messages.java
Log Message:
test a stack of schemas without error messages if finally found, though not found in previously popped schemas.
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.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** Messages.java 1 Apr 2004 21:17:51 -0000 1.21
--- Messages.java 27 Jul 2004 06:17:26 -0000 1.22
***************
*** 82,85 ****
--- 82,86 ----
import com.jcorporate.expresso.services.dbobj.UserPreferenceDef;
import org.apache.log4j.Logger;
+ import org.apache.log4j.Priority;
import javax.servlet.ServletException;
***************
*** 98,110 ****
* parameters in the message string if necessary.
* The appropriate local language is determined by means of the following:
! *
* Created on January 10, 2001, 8:35 AM
! * @version $Revision$ $Date$
! * @author Michael Nash
*/
public class Messages
extends java.lang.Object {
! /** Schema to use by default if none is specified */
private static String defaultSchema = "com.jcorporate.expresso.core.ExpressoSchema";
--- 99,113 ----
* parameters in the message string if necessary.
* The appropriate local language is determined by means of the following:
! * <p/>
* Created on January 10, 2001, 8:35 AM
! *
! * @author Michael Nash
*/
public class Messages
extends java.lang.Object {
! /**
! * Schema to use by default if none is specified
! */
private static String defaultSchema = "com.jcorporate.expresso.core.ExpressoSchema";
***************
*** 128,134 ****
* to the cache if it must be created
*
! * @param schemaName
! * @param language
! * @param country
* @return
*/
--- 131,136 ----
* to the cache if it must be created
*
! * @param schemaName
! * @param l locale to use
* @return
*/
***************
*** 147,152 ****
bundleKey.append(country);
! MessageBundle myBundle = (MessageBundle) messageBundlesBySchema.get(
! bundleKey.toString());
if (myBundle == null) {
--- 149,153 ----
bundleKey.append(country);
! MessageBundle myBundle = (MessageBundle) messageBundlesBySchema.get(bundleKey.toString());
if (myBundle == null) {
***************
*** 158,163 ****
messageBundlesBySchema.put(bundleKey.toString(), myBundle);
! FastStringBuffer pathKey = new FastStringBuffer(
! myBundle.getBundlePath());
pathKey.append("|");
pathKey.append(language);
--- 159,163 ----
messageBundlesBySchema.put(bundleKey.toString(), myBundle);
! FastStringBuffer pathKey = new FastStringBuffer(myBundle.getBundlePath());
pathKey.append("|");
pathKey.append(language);
***************
*** 174,180 ****
* object, but in this case for a specified bundle path.
*
! * @param bundlePath
! * @param language
! * @param country
* @return
*/
--- 174,180 ----
* object, but in this case for a specified bundle path.
*
! * @param bundlePath
! * @param language
! * @param country
* @return
*/
***************
*** 188,193 ****
bundleKey.append(country);
! MessageBundle myBundle = (MessageBundle) messageBundlesByPath.get(
! bundleKey.toString());
if (myBundle == null) {
--- 188,192 ----
bundleKey.append(country);
! MessageBundle myBundle = (MessageBundle) messageBundlesByPath.get(bundleKey.toString());
if (myBundle == null) {
***************
*** 197,202 ****
myBundle.setLanguage(language);
myBundle.setCountry(country);
! messageBundlesByPath.put(
! myBundle.getBundlePath() + "|" + language + "|" + country,
myBundle);
}
--- 196,200 ----
myBundle.setLanguage(language);
myBundle.setCountry(country);
! messageBundlesByPath.put(myBundle.getBundlePath() + "|" + language + "|" + country,
myBundle);
}
***************
*** 210,217 ****
* methods to determine them
*
! * @param schemaClass the schema class
! * @param l the Locale
! * @param stringCode the string code
! * @param args any arguments.
* @return java.lang.String
*/
--- 208,215 ----
* methods to determine them
*
! * @param schemaClass the schema class
! * @param l the Locale
! * @param stringCode the string code
! * @param args any arguments.
* @return java.lang.String
*/
***************
*** 228,281 ****
} /* getString(String, String, String, String, Object[] */
! /**
! * Return a string out of our message bundle associated with the specified schemaClass,
! * throwing an exception if it's not found
! *
! * @param schemaClass the schema class
! * @param l the Locale
! * @param stringCode the string code
! * @param args any arguments.
! * @return java.lang.String
! *
! * @throws IllegalArgumentException if the given string code doesn't exist in the given bundle.
! */
! public static String getStringRequired(String schemaClass, Locale l,
! String stringCode, Object[] args) throws IllegalArgumentException {
! if (l == null) {
! l = Locale.getDefault();
! }
! MessageBundle mb = getBundleBySchema(schemaClass, l);
! return mb.getStringRequired(stringCode, args);
! } /* getString(String, String, String, String, Object[] */
!
! /**
! * 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 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) */
/**
--- 226,277 ----
} /* getString(String, String, String, String, Object[] */
! /**
! * Return a string out of our message bundle associated with the specified schemaClass,
! * throwing an exception if it's not found
! *
! * @param schemaClass the schema class
! * @param l the Locale
! * @param stringCode the string code
! * @param args any arguments.
! * @return java.lang.String
! * @throws IllegalArgumentException if the given string code doesn't exist in the given bundle.
! */
! public static String getStringRequired(String schemaClass, Locale l,
! String stringCode, Object[] args) throws IllegalArgumentException {
! if (l == null) {
! l = Locale.getDefault();
! }
! MessageBundle mb = getBundleBySchema(schemaClass, l);
! return mb.getStringRequired(stringCode, args);
! } /* getString(String, String, String, String, Object[] */
!
! /**
! * 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 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) */
/**
***************
*** 283,291 ****
* path
*
! * @param bundlePath
! * @param language
! * @param country
! * @param stringCode
! * @param args
* @return
*/
--- 279,287 ----
* path
*
! * @param bundlePath
! * @param language
! * @param country
! * @param stringCode
! * @param args
* @return
*/
***************
*** 301,305 ****
* Set the default schema to a class name of a Schema object
*
! * @param newDefault
*/
public static void setDefaultSchema(String newDefault) {
--- 297,301 ----
* Set the default schema to a class name of a Schema object
*
! * @param newDefault
*/
public static void setDefaultSchema(String newDefault) {
***************
*** 311,315 ****
* schema, with no arguments
*
! * @param stringCode
* @return
*/
--- 307,311 ----
* schema, with no arguments
*
! * @param stringCode
* @return
*/
***************
*** 325,330 ****
* but with the specified arguments
*
! * @param stringCode
! * @param args
* @return
*/
--- 321,326 ----
* but with the specified arguments
*
! * @param stringCode
! * @param args
* @return
*/
***************
*** 334,341 ****
/**
! *
! *
! * @param schemaClass
! * @param stringCode
* @return
*/
--- 330,335 ----
/**
! * @param schemaClass
! * @param stringCode
* @return
*/
***************
*** 344,380 ****
} /* getString(String, String) */
! /**
* 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
! */
! public static String getString(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args) {
! 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 getString(defaultSchema, ourLocale, stringCode, args);
! } /* getString(String, String) */
/**
* Convenience method to use the current default schema
*
! * @param schemaClass
! * @param req
! * @param stringCode
! * @param args
! * @throws ServletException
* @return
*/
--- 338,398 ----
} /* getString(String, String) */
! /**
* Convenience method that gets a string using the schemaStack, looping
! * through stack 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
! */
! public static String getString(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args) {
! 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;
! }
!
! // // one last try for default schema
! // if ( result == null ) result = getStringOrNull(defaultSchema, ourLocale, stringCode, args);
!
! if (result == null) {
! result = stringCode;
! // log warning
! if (log.isEnabledFor(Priority.WARN)) {
! String msg = "No such key '" +
! stringCode + "' in bundle for schemas: '" + schemaStack.toString() + "'";
! if (log.isDebugEnabled()) {
! msg += " with language '" + ourLocale.getLanguage() + "', " + "Country '" +
! ourLocale.getCountry() + "'";
! }
! log.warn(msg);
! }
! }
!
! return result;
! } /* getString(String, String) */
!
! /**
! * @return translation string, or null if not found
! */
! private static String getStringOrNull(String schema, Locale ourLocale, String stringCode, Object[] args) {
! if (ourLocale == null) {
! ourLocale = Locale.getDefault();
! }
!
! MessageBundle mb = getBundleBySchema(schema, ourLocale);
! return mb.getStringOrNull(stringCode, args);
! }
/**
* Convenience method to use the current default schema
*
! * @param schemaClass
! * @param req
! * @param stringCode
! * @param args
* @return
*/
***************
*** 388,393 ****
! public static String getString(Locale l, String stringCode)
! throws ServletException {
Object[] args = {};
--- 406,410 ----
! public static String getString(Locale l, String stringCode) {
Object[] args = {};
***************
*** 395,400 ****
}
! public static String getString(Locale l, String stringCode, Object[] args)
! throws ServletException {
return getString(defaultSchema, l, stringCode, args);
}
--- 412,416 ----
}
! public static String getString(Locale l, String stringCode, Object[] args) {
return getString(defaultSchema, l, stringCode, args);
}
***************
*** 604,610 ****
* defaults in the property file, we use english
*
! * @param schemaClass
! * @param stringCode
! * @param args
* @return
*/
--- 620,626 ----
* defaults in the property file, we use english
*
! * @param schemaClass
! * @param stringCode
! * @param args
* @return
*/
***************
*** 629,637 ****
* Convenience method to use the current default schema
*
! * @param uid
! * @param dbName
! * @param schemaClass
! * @param stringCode
! * @param args
* @return
*/
--- 645,653 ----
* Convenience method to use the current default schema
*
! * @param uid
! * @param dbName
! * @param schemaClass
! * @param stringCode
! * @param args
* @return
*/
***************
*** 697,705 ****
/**
! *
! *
! * @param req
! * @param stringCode
! * @throws ServletException
* @return
*/
--- 713,718 ----
/**
! * @param req
! * @param stringCode
* @return
*/
***************
*** 715,722 ****
* Return a string out of our message bundle
*
! * @param req
! * @param stringCode
! * @param firstReplace
! * @throws ServletException
* @return
*/
--- 728,734 ----
* Return a string out of our message bundle
*
! * @param req
! * @param stringCode
! * @param firstReplace
* @return
*/
***************
*** 733,741 ****
* Return a string out of our message bundle
*
! * @param req
! * @param stringCode
! * @param firstReplace
! * @param secondReplace
! * @throws ServletException
* @return
*/
--- 745,752 ----
* Return a string out of our message bundle
*
! * @param req
! * @param stringCode
! * @param firstReplace
! * @param secondReplace
* @return
*/
***************
*** 753,762 ****
* string arguments as the replacement arguments
*
! * @param req
! * @param stringCode
! * @param firstReplace
! * @param secondReplace
! * @param thirdReplace
! * @throws ServletException
* @return
*/
--- 764,772 ----
* string arguments as the replacement arguments
*
! * @param req
! * @param stringCode
! * @param firstReplace
! * @param secondReplace
! * @param thirdReplace
* @return
*/
More information about the cvs
mailing list