dgraham 2003/03/12 17:44:48 Modified: src/share/org/apache/struts/util PropertyMessageResources.java Log: Synchronized loadLocale to fix PR #17328. Revision Changes Path 1.7 +28 -28 jakarta-struts/src/share/org/apache/struts/util/PropertyMessageResources.java Index: PropertyMessageResources.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/PropertyMessageResources.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PropertyMessageResources.java 17 Oct 2002 02:56:58 -0000 1.6 +++ PropertyMessageResources.java 13 Mar 2003 01:44:47 -0000 1.7 @@ -7,7 +7,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,16 +62,15 @@ package org.apache.struts.util; - import java.io.InputStream; -import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.Locale; import java.util.Properties; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - /** * Concrete subclass of <code>MessageResources</code> that reads message keys * and corresponding strings from named property resources in the same manner @@ -89,7 +88,6 @@ * @author Craig R. McClanahan * @version $Revision$ $Date$ */ - public class PropertyMessageResources extends MessageResources { @@ -196,8 +194,9 @@ synchronized (messages) { message = (String) messages.get(messageKey); if (message != null) { - if (addIt) + if (addIt) { messages.put(originalKey, message); + } return (message); } } @@ -205,8 +204,9 @@ // Strip trailing modifiers to try a more general locale key addIt = true; underscore = localeKey.lastIndexOf("_"); - if (underscore < 0) + if (underscore < 0) { break; + } localeKey = localeKey.substring(0, underscore); } @@ -238,10 +238,11 @@ } // Return an appropriate error indication - if (returnNull) + if (returnNull) { return (null); - else + } else { return ("???" + messageKey(locale, key) + "???"); + } } @@ -260,23 +261,23 @@ * * @param localeKey Locale key for the messages to be retrieved */ - protected void loadLocale(String localeKey) { + protected synchronized void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } - + // Have we already attempted to load messages for this locale? - synchronized (locales) { - if (locales.get(localeKey) != null) - return; - locales.put(localeKey, localeKey); + if (locales.get(localeKey) != null) { + return; } + locales.put(localeKey, localeKey); // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); - if (localeKey.length() > 0) + if (localeKey.length() > 0) { name += "_" + localeKey; + } name += ".properties"; InputStream is = null; Properties props = new Properties(); @@ -311,18 +312,17 @@ } // Copy the corresponding values into our cache - if (props.size() < 1) + if (props.size() < 1) { return; + } synchronized (messages) { - Enumeration names = props.keys(); - while (names.hasMoreElements()) { - String key = (String) names.nextElement(); + Iterator names = props.keySet().iterator(); + while (names.hasNext()) { + String key = (String) names.next(); if (log.isTraceEnabled()) { - log.trace(" Saving message key '" + - messageKey(localeKey, key)); + log.trace(" Saving message key '" + messageKey(localeKey, key)); } - messages.put(messageKey(localeKey, key), - props.getProperty(key)); + messages.put(messageKey(localeKey, key), props.getProperty(key)); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]