Author: jcompagner
Date: Sun Mar  9 09:11:48 2008
New Revision: 635266

URL: http://svn.apache.org/viewvc?rev=635266&view=rev
Log:
see WICKET-1319
this is a bit of a hack to get it working correctly
in 1.4 we could change the interfaces of 
Localizer.substitutePropertyExpression() so that we can give a new Interface 
EscapeStrategy to that method that will escape the values first before applying 
it.

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java?rev=635266&r1=635265&r2=635266&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java 
(original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java 
Sun Mar  9 09:11:48 2008
@@ -347,7 +347,7 @@
         *            The model
         * @return The resulting string
         */
-       protected String substitutePropertyExpressions(final Component 
component, final String string,
+       public String substitutePropertyExpressions(final Component component, 
final String string,
                final IModel model)
        {
                if ((string != null) && (model != null))

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java?rev=635266&r1=635265&r2=635266&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
 Sun Mar  9 09:11:48 2008
@@ -338,19 +338,29 @@
                        }
                }
 
-               // Get the string resource, doing any property substitutions as 
part
-               // of the get operation
-               String value = localizer.getString(getResourceKey(), component, 
model, defaultValue);
-               if (value == null)
+               String value = null;
+               // Substitute any parameters if necessary
+               Object[] parameters = getParameters();
+               if (parameters == null)
                {
-                       value = defaultValue;
+                       // Get the string resource, doing any property 
substitutions as part
+                       // of the get operation
+                       value = localizer.getString(getResourceKey(), 
component, model, defaultValue);
+                       if (value == null)
+                       {
+                               value = defaultValue;
+                       }
                }
-
-               if (value != null)
+               else
                {
-                       // Substitute any parameters if necessary
-                       Object[] parameters = getParameters();
-                       if (parameters != null)
+                       // Get the string resource, doing not any property 
substitutions
+                       // that has to be done later after MessageFormat
+                       value = localizer.getString(getResourceKey(), 
component, null, defaultValue);
+                       if (value == null)
+                       {
+                               value = defaultValue;
+                       }
+                       if (value != null)
                        {
                                // Build the real parameters
                                Object[] realParams = new 
Object[parameters.length];
@@ -371,12 +381,24 @@
                                        }
                                }
 
-                               // escape single quotes for MessageFormat
-                               value = Strings.replaceAll(value, "'", 
"''").toString();
+                               if (model != null)
+                               {
+                                       // First escape all substitute 
properties so that message format doesn't try to
+                                       // parse that.
+                                       value = Strings.replaceAll(value, "${", 
"$'{'").toString();
+                               }
                                // Apply the parameters
                                final MessageFormat format = new 
MessageFormat(value, component != null
-                                       ? component.getLocale() : locale);      
                        
+                                       ? component.getLocale() : locale);
                                value = format.format(realParams);
+
+                               if (model != null)
+                               {
+                                       // un escape the substitute properties
+                                       value = Strings.replaceAll(value, 
"$'{'", "${").toString();
+                                       // now substitute the properties
+                                       value = 
localizer.substitutePropertyExpressions(component, value, model);
+                               }
                        }
                }
 

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java?rev=635266&r1=635265&r2=635266&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
 Sun Mar  9 09:11:48 2008
@@ -19,6 +19,7 @@
 import java.io.Serializable;
 import java.text.MessageFormat;
 import java.util.Calendar;
+import java.util.Locale;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -177,6 +178,16 @@
                expected = format.format(new Object[] { cal.getTime(), 
"raining", new Double(11.568),
                                "\u00B0C" });
                Assert.assertEquals("Text should be as expected", expected, 
model.getString());
+       }
+
+
+       public void testSubstitutionParametersResourceWithSingleQuote() throws 
Exception
+       {
+               tester.getWicketSession().setLocale(Locale.ENGLISH);
+               StringResourceModel model = new 
StringResourceModel("with.quote", page, null, new Object[] {
+                               new Integer(10), new Integer(20) });
+               assertEquals("2010.00", model.getString());
+
        }
 
        /**

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties?rev=635266&r1=635265&r2=635266&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties
 Sun Mar  9 09:11:48 2008
@@ -21,4 +21,5 @@
 weather.raining=It's raining, take an umbrella
 weather.message=Weather station "${name}" reports that the temperature is 
${currentTemperature} ${units}
 weather.mixed=Weather station "${name}" reports that the temperature is {0} {1}
-weather.detail=The report for {0,date,medium}, shows the temperature as 
{2,number,###.##} {3} and the weather to be {1}
\ No newline at end of file
+weather.detail=The report for {0,date,medium}, shows the temperature as 
{2,number,###.##} {3} and the weather to be {1}
+with.quote={0,choice,-1#n/a|-1<'{1}{0,number,#,##0.00}'}


Reply via email to