You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2007/01/24 08:33:25 UTC

svn commit: r499294 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/config/ test/java/org/apache/struts2/config/

Author: mrdon
Date: Tue Jan 23 23:33:24 2007
New Revision: 499294

URL: http://svn.apache.org/viewvc?view=rev&rev=499294
Log:
Moved processing of localization files from struts.properties to any usual properties setting 
technique (web.xml, struts.properties, struts.xml)
WW-1668

Added:
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java
Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?view=diff&rev=499294&r1=499293&r2=499294
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java Tue Jan 23 23:33:24 2007
@@ -21,6 +21,7 @@
 package org.apache.struts2.config;
 
 import java.util.Properties;
+import java.util.StringTokenizer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -43,6 +44,7 @@
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.inject.Scope;
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.ObjectTypeDeterminer;
 import com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory;
 import com.opensymphony.xwork2.util.XWorkConverter;
@@ -166,6 +168,26 @@
             props.setProperty("devMode", "true");
         } else {
             props.setProperty("devMode", "false");
+        }
+        
+        // TODO: This should be moved to XWork after 2.0.4
+        // struts.custom.i18n.resources
+        try {
+
+            LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
+            StringTokenizer customBundles = new StringTokenizer(props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", ");
+
+            while (customBundles.hasMoreTokens()) {
+                String name = customBundles.nextToken();
+                try {
+                    LOG.info("Loading global messages from " + name);
+                    LocalizedTextUtil.addDefaultResourceBundle(name);
+                } catch (Exception e) {
+                    LOG.error("Could not find messages file " + name + ".properties. Skipping");
+                }
+            }
+        } catch (IllegalArgumentException e) {
+            // Assume it's OK, since many applications do not provide custom resource bundles. 
         }
     }
     

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java?view=diff&rev=499294&r1=499293&r2=499294
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java Tue Jan 23 23:33:24 2007
@@ -94,24 +94,6 @@
             // like the struts.custom.properties, which is commented out
         }
 
-        // struts.custom.i18n.resources
-        try {
-
-            LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
-            StringTokenizer customBundles = new StringTokenizer(delegate.getImpl(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", ");
-
-            while (customBundles.hasMoreTokens()) {
-                String name = customBundles.nextToken();
-                try {
-                    log.info("DefaultSettings: Loading global messages from " + name);
-                    LocalizedTextUtil.addDefaultResourceBundle(name);
-                } catch (Exception e) {
-                    log.error("DefaultSettings: Could not find " + name + ".properties. Skipping");
-                }
-            }
-        } catch (IllegalArgumentException e) {
-            // Assume it's OK, since many applications do not provide custom resource bundles. 
-        }
     }
 
     // See superclass for Javadoc

Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java?view=auto&rev=499294
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java (added)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java Tue Jan 23 23:33:24 2007
@@ -0,0 +1,50 @@
+/*
+ * $Id: SettingsTest.java 498215 2007-01-20 23:59:10Z mrdon $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.config;
+
+import java.util.Locale;
+
+import org.apache.struts2.StrutsConstants;
+
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.util.LocalizedTextUtil;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+
+import junit.framework.TestCase;
+
+public class BeanSelectionProviderTest extends TestCase {
+
+    public void testRegister() {
+        Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
+
+        LocalizedTextUtil.clearDefaultResourceBundles();
+        LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
+        assertEquals("The form has already been processed or no token was supplied, please try again.", LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", Locale.getDefault()));
+        
+        LocatableProperties props = new LocatableProperties();
+        props.setProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES, "testmessages,testmessages2");
+        
+        new BeanSelectionProvider().register(new ContainerBuilder(), props);
+
+        assertEquals("Replaced message for token tag", LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", Locale.getDefault()));
+    }
+
+}

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java?view=diff&rev=499294&r1=499293&r2=499294
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java Tue Jan 23 23:33:24 2007
@@ -56,18 +56,6 @@
         assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault()));
     }
 
-    public void testReplaceDefaultMessages() {
-        Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
-
-        LocalizedTextUtil.clearDefaultResourceBundles();
-        LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
-        assertEquals("The form has already been processed or no token was supplied, please try again.", LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", Locale.getDefault()));
-        Settings.reset();
-
-        assertEquals("testmessages,testmessages2", Settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES));
-        assertEquals("Replaced message for token tag", LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", Locale.getDefault()));
-    }
-
     public void testSetSettings() {
         Settings.setInstance(new TestSettings());