I've been playing a bit with the Struts MessageResources lately, I'm trying to use a Configuration as the underlying structure for storing internationalized messages. This brings 2 interesting improvements, interpolation and automatic reloading when it's committed.

However I stumbled on a issue with the current implementation, strings are always considered as comma separated values and splitted into a List. This behavior isn't desirable for a resource file with several sentences, or even for a common configuration file storing a number format like "###,##0.00".

That's why I'm suggesting an additional flag enabling or disabling property splitting, it would be enabled by default. I'm attaching a patch implementing this idea.

Emmanuel Bourg

Index: src/java/org/apache/commons/configuration/AbstractConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
retrieving revision 1.2
diff -u -r1.2 AbstractConfiguration.java
--- src/java/org/apache/commons/configuration/AbstractConfiguration.java        24 Dec 
2003 14:28:22 -0000      1.2
+++ src/java/org/apache/commons/configuration/AbstractConfiguration.java        13 Jan 
2004 16:13:42 -0000
@@ -86,6 +86,9 @@
     /** end token */
     protected static final String END_TOKEN = "}";
 
+    /** split properties on PropertiesTokenizer.DELIMITER */
+    protected boolean splitString = true;
+
     /**
      * Empty constructor.
      */
@@ -126,10 +129,13 @@
     {
         if (token instanceof String)
         {
-            for(Iterator it = processString((String) token).iterator();
-            it.hasNext();)
-            {
-                addPropertyDirect(key, it.next());
+            if (splitString) {
+                for (Iterator it = processString((String) token).iterator(); 
it.hasNext();)
+                {
+                    addPropertyDirect(key, it.next());
+                }
+            } else {
+                addPropertyDirect(key, token);
             }
         }
         else if (token instanceof Collection)
@@ -1440,6 +1446,20 @@
             value = ((Container) value).get(0);
         }
         return value;
+    }
+
+    /**
+     * Tell if properties are split on commas or not.
+     */
+    public boolean isSplitString() {
+        return splitString;
+    }
+
+    /**
+     * Enable or disable the splitting of properties.
+     */
+    public void setSplitString(boolean splitString) {
+        this.splitString = splitString;
     }
 
     /**

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



Reply via email to