You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/07/03 04:42:58 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/actions LookupDispatchAction.java
dgraham 2003/07/02 19:42:58
Modified: src/share/org/apache/struts/actions
LookupDispatchAction.java
Log:
Fixed synchronization problem for PR# 21224. Also refactored some code
into a new initLookupMap() method.
Revision Changes Path
1.12 +42 -40 jakarta-struts/src/share/org/apache/struts/actions/LookupDispatchAction.java
Index: LookupDispatchAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/actions/LookupDispatchAction.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- LookupDispatchAction.java 1 Feb 2003 21:56:33 -0000 1.11
+++ LookupDispatchAction.java 3 Jul 2003 02:42:58 -0000 1.12
@@ -201,55 +201,57 @@
// Based on this request's Locale get the lookupMap
Map lookupMap = null;
- Locale userLocale = getLocale(request);
- boolean newLookupMap = false;
+
synchronized (localeMap) {
+ Locale userLocale = this.getLocale(request);
lookupMap = (Map) this.localeMap.get(userLocale);
+
if (lookupMap == null) {
- newLookupMap = true;
- lookupMap = new HashMap();
+ lookupMap = this.initLookupMap(request, userLocale);
this.localeMap.put(userLocale, lookupMap);
}
}
-
- synchronized (lookupMap) {
- if (newLookupMap) {
- /*
- * This is the first time this Locale is used so build the reverse lookup Map.
- * Search for message keys in all configured MessageResources for
- * the current module.
- */
- this.keyMethodMap = this.getKeyMethodMap();
-
- ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
- MessageResourcesConfig[] mrc = moduleConfig.findMessageResourcesConfigs();
-
- // Look through all module's MessageResources
- for (int i = 0; i < mrc.length; i++) {
- MessageResources resources =
- this.getResources(request, mrc[i].getKey());
-
- // Look for key in MessageResources
- Iterator iter = this.keyMethodMap.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- String text = resources.getMessage(userLocale, key);
-
- // Found key and haven't added to Map yet, so add the text
- if ((text != null) && !lookupMap.containsKey(text)) {
- lookupMap.put(text, key);
- }
- }
- }
- }
- }
// Find the key
String key = (String) lookupMap.get(name);
String methodName = (String) keyMethodMap.get(key);
- return dispatchMethod(mapping, form, request, response, methodName);
+ return this.dispatchMethod(mapping, form, request, response, methodName);
+ }
+
+ /**
+ * This is the first time this Locale is used so build the reverse lookup Map.
+ * Search for message keys in all configured MessageResources for
+ * the current module.
+ */
+ private Map initLookupMap(HttpServletRequest request, Locale userLocale) {
+ Map lookupMap = new HashMap();
+ this.keyMethodMap = this.getKeyMethodMap();
+
+ ModuleConfig moduleConfig =
+ (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
+
+ MessageResourcesConfig[] mrc = moduleConfig.findMessageResourcesConfigs();
+
+ // Look through all module's MessageResources
+ for (int i = 0; i < mrc.length; i++) {
+ MessageResources resources = this.getResources(request, mrc[i].getKey());
+
+ // Look for key in MessageResources
+ Iterator iter = this.keyMethodMap.keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ String text = resources.getMessage(userLocale, key);
+
+ // Found key and haven't added to Map yet, so add the text
+ if ((text != null) && !lookupMap.containsKey(text)) {
+ lookupMap.put(text, key);
+ }
+ }
+ }
+
+ return lookupMap;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org