Author: gseitz
Date: Tue Nov 20 18:23:53 2007
New Revision: 596906

URL: http://svn.apache.org/viewvc?rev=596906&view=rev
Log:
moved single-quote-escaping from PropertyVariableInterpolator to 
StringResourceModel

Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.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/util/string/interpolator/PropertyVariableInterpolatorTest.java

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=596906&r1=596905&r2=596906&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
 Tue Nov 20 18:23:53 2007
@@ -25,6 +25,7 @@
 import org.apache.wicket.Localizer;
 import org.apache.wicket.Session;
 import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.string.interpolator.PropertyVariableInterpolator;
 
 
@@ -214,7 +215,7 @@
         * @see #StringResourceModel(String, Component, IModel, Object[])
         */
        public StringResourceModel(final String resourceKey, final Component 
component,
-                       final IModel model)
+               final IModel model)
        {
                this(resourceKey, component, model, null, null);
        }
@@ -234,7 +235,7 @@
         * @see #StringResourceModel(String, Component, IModel, Object[])
         */
        public StringResourceModel(final String resourceKey, final Component 
component,
-                       final IModel model, final String defaultValue)
+               final IModel model, final String defaultValue)
        {
                this(resourceKey, component, model, null, defaultValue);
        }
@@ -262,7 +263,7 @@
         *            The parameters to substitute using a Java MessageFormat 
object
         */
        public StringResourceModel(final String resourceKey, final Component 
component,
-                       final IModel model, final Object[] parameters)
+               final IModel model, final Object[] parameters)
        {
                this(resourceKey, component, model, parameters, null);
        }
@@ -292,7 +293,7 @@
         *            The default value if the resource key is not found.
         */
        public StringResourceModel(final String resourceKey, final Component 
component,
-                       final IModel model, final Object[] parameters, final 
String defaultValue)
+               final IModel model, final Object[] parameters, final String 
defaultValue)
        {
                if (resourceKey == null)
                {
@@ -362,7 +363,7 @@
                                        else if (model != null && parameters[i] 
instanceof String)
                                        {
                                                realParams[i] = 
PropertyVariableInterpolator.interpolate(
-                                                               
(String)parameters[i], model.getObject());
+                                                       (String)parameters[i], 
model.getObject());
                                        }
                                        else
                                        {
@@ -370,9 +371,11 @@
                                        }
                                }
 
+                               // escape single quotes for MessageFormat
+                               value = Strings.replaceAll(value, "'", 
"''").toString();
                                // Apply the parameters
-                               final MessageFormat format = new 
MessageFormat(value, component != null ? component
-                                               .getLocale() : locale);
+                               final MessageFormat format = new 
MessageFormat(value, component != null
+                                       ? component.getLocale() : locale);      
                        
                                value = format.format(realParams);
                        }
                }
@@ -461,7 +464,7 @@
                else
                {
                        throw new WicketRuntimeException(
-                                       "Cannot attach a string resource model 
without a Session context because that is required to get a Localizer");
+                               "Cannot attach a string resource model without 
a Session context because that is required to get a Localizer");
                }
                return getString();
        }

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java?rev=596906&r1=596905&r2=596906&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java
 Tue Nov 20 18:23:53 2007
@@ -17,7 +17,6 @@
 package org.apache.wicket.util.string.interpolator;
 
 import org.apache.wicket.util.lang.PropertyResolver;
-import org.apache.wicket.util.string.Strings;
 
 /**
  * Interpolates values into <code>String</code>s that are produced by 
interpreting property
@@ -85,6 +84,6 @@
        protected String getValue(final String variableName)
        {
                Object value = PropertyResolver.getValue(variableName, model);
-               return value != null ? Strings.replaceAll(value.toString(), 
"'", "''").toString() : null;
+               return (value != null) ? value.toString() : null;
        }
 }

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=596906&r1=596905&r2=596906&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
 Tue Nov 20 18:23:53 2007
@@ -124,12 +124,12 @@
                StringResourceModel model = new 
StringResourceModel("weather.message", page, wsModel);
                Assert.assertEquals(
                        "Text should be as expected",
-                       "Weather station \"Europe''s main weather station\" 
reports that the temperature is 25.7 \u00B0C",
+                       "Weather station \"Europe's main weather station\" 
reports that the temperature is 25.7 \u00B0C",
                        model.getString());
                ws.setCurrentTemperature(11.5);
                Assert.assertEquals(
                        "Text should be as expected",
-                       "Weather station \"Europe''s main weather station\" 
reports that the temperature is 11.5 \u00B0C",
+                       "Weather station \"Europe's main weather station\" 
reports that the temperature is 11.5 \u00B0C",
                        model.getString());
        }
 

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java?rev=596906&r1=596905&r2=596906&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java
 Tue Nov 20 18:23:53 2007
@@ -44,16 +44,6 @@
                assertEquals("${key}", result.toString());
        }
 
-       /**
-        * 
-        */
-       public void testWithValueWithSingleQuotes()
-       {
-               TestClass object = new TestClass("'value '' with multiple' 
quotes'");
-               String result = 
PropertyVariableInterpolator.interpolate("${key}", object);
-               assertEquals("''value '''' with multiple'' quotes''", result);
-       }
-
        private static class TestClass
        {
                private final String key;


Reply via email to