You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pe...@apache.org on 2010/12/20 14:08:16 UTC

svn commit: r1051089 - in /wicket/trunk: wicket-examples/src/main/java/org/apache/wicket/examples/compref/ wicket/src/main/java/org/apache/wicket/model/ wicket/src/test/java/org/apache/wicket/model/

Author: pete
Date: Mon Dec 20 13:08:15 2010
New Revision: 1051089

URL: http://svn.apache.org/viewvc?rev=1051089&view=rev
Log:
WICKET-3266: introduce varargs for parameters in StringResourceModel

Modified:
    wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LabelPage.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java

Modified: wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LabelPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LabelPage.java?rev=1051089&r1=1051088&r2=1051089&view=diff
==============================================================================
--- wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LabelPage.java (original)
+++ wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LabelPage.java Mon Dec 20 13:08:15 2010
@@ -60,7 +60,7 @@ public class LabelPage extends WicketExa
 		// for
 		// parameter substitution.
 		StringResourceModel stringResourceModel = new StringResourceModel("label.current.locale",
-			this, null, new Object[] { getLocale() });
+			this, null, getLocale());
 		add(new Label("resourceLabel", stringResourceModel));
 
 		// and here we add a label that contains markup. Normally, this markup

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java?rev=1051089&r1=1051088&r2=1051089&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java Mon Dec 20 13:08:15 2010
@@ -262,43 +262,6 @@ public class StringResourceModel extends
 	}
 
 	/**
-	 * Construct.
-	 * 
-	 * @param resourceKey
-	 *            The resource key for this string resource
-	 * @param component
-	 *            The component that the resource is relative to
-	 * @param model
-	 *            The model to use for property substitutions
-	 * @see #StringResourceModel(String, Component, IModel, Object[])
-	 */
-	public StringResourceModel(final String resourceKey, final Component component,
-		final IModel<?> model)
-	{
-		this(resourceKey, component, model, null, null);
-	}
-
-	/**
-	 * Construct.
-	 * 
-	 * @param resourceKey
-	 *            The resource key for this string resource
-	 * @param component
-	 *            The component that the resource is relative to
-	 * @param model
-	 *            The model to use for property substitutions
-	 * @param defaultValue
-	 *            The default value if the resource key is not found.
-	 * 
-	 * @see #StringResourceModel(String, Component, IModel, Object[])
-	 */
-	public StringResourceModel(final String resourceKey, final Component component,
-		final IModel<?> model, final String defaultValue)
-	{
-		this(resourceKey, component, model, null, defaultValue);
-	}
-
-	/**
 	 * Creates a new string resource model using the supplied parameters.
 	 * <p>
 	 * The relative component parameter should generally be supplied, as without it resources can
@@ -310,7 +273,7 @@ public class StringResourceModel extends
 	 * to take place on either the resource key or the actual resource strings.
 	 * <p>
 	 * The parameters parameter is also optional and is used for substitutions.
-	 * 
+	 *
 	 * @param resourceKey
 	 *            The resource key for this string resource
 	 * @param component
@@ -321,9 +284,9 @@ public class StringResourceModel extends
 	 *            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);
+		this(resourceKey, component, model, null, parameters);
 	}
 
 	/**
@@ -351,7 +314,7 @@ public class StringResourceModel extends
 	 *            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 String defaultValue, final Object... parameters)
 	{
 		if (resourceKey == null)
 		{
@@ -360,40 +323,8 @@ public class StringResourceModel extends
 		this.resourceKey = resourceKey;
 		this.component = component;
 		this.model = model;
-		this.parameters = parameters;
 		this.defaultValue = defaultValue;
-	}
-
-	/**
-	 * Construct.
-	 * 
-	 * @param resourceKey
-	 *            The resource key for this string resource
-	 * @param model
-	 *            The model to use for property substitutions
-	 * @see #StringResourceModel(String, Component, IModel, Object[])
-	 */
-	public StringResourceModel(final String resourceKey, final IModel<?> model)
-	{
-		this(resourceKey, null, model, null, null);
-	}
-
-	/**
-	 * Construct.
-	 * 
-	 * @param resourceKey
-	 *            The resource key for this string resource
-	 * @param model
-	 *            The model to use for property substitutions
-	 * @param defaultValue
-	 *            The default value if the resource key is not found.
-	 * 
-	 * @see #StringResourceModel(String, Component, IModel, Object[])
-	 */
-	public StringResourceModel(final String resourceKey, final IModel<?> model,
-		final String defaultValue)
-	{
-		this(resourceKey, null, model, null, defaultValue);
+		this.parameters = parameters;
 	}
 
 	/**
@@ -412,9 +343,9 @@ public class StringResourceModel extends
 	 *            The parameters to substitute using a Java MessageFormat object
 	 */
 	public StringResourceModel(final String resourceKey, final IModel<?> model,
-		final Object[] parameters)
+		final Object... parameters)
 	{
-		this(resourceKey, null, model, parameters, null);
+		this(resourceKey, null, model, null, parameters);
 	}
 
 	/**
@@ -435,9 +366,9 @@ public class StringResourceModel extends
 	 *            The default value if the resource key is not found.
 	 */
 	public StringResourceModel(final String resourceKey, final IModel<?> model,
-		final Object[] parameters, final String defaultValue)
+		final String defaultValue, final Object... parameters)
 	{
-		this(resourceKey, null, model, parameters, defaultValue);
+		this(resourceKey, null, model, defaultValue, parameters);
 	}
 
 
@@ -493,10 +424,11 @@ public class StringResourceModel extends
 			locale = Session.get().getLocale();
 		}
 
-		String value = null;
+		String value;
+
 		// Substitute any parameters if necessary
 		Object[] parameters = getParameters();
-		if (parameters == null)
+		if (parameters == null || parameters.length == 0)
 		{
 			// Get the string resource, doing any property substitutions as part
 			// of the get operation
@@ -682,4 +614,4 @@ public class StringResourceModel extends
 	{
 		throw new UnsupportedOperationException();
 	}
-}
\ No newline at end of file
+}

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java?rev=1051089&r1=1051088&r2=1051089&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java Mon Dec 20 13:08:15 2010
@@ -135,8 +135,8 @@ public class StringResourceModelTest ext
 	public void testSubstitutedPropertyAndParameterResource()
 	{
 		StringResourceModel model = new StringResourceModel("weather.mixed", page, wsModel,
-			new Object[] { new PropertyModel<Double>(wsModel, "currentTemperature"),
-					new PropertyModel<String>(wsModel, "units") });
+			new PropertyModel<Double>(wsModel, "currentTemperature"),
+					new PropertyModel<String>(wsModel, "units"));
 		MessageFormat format = new MessageFormat(
 			"Weather station \"Europe''s main weather station\" reports that the temperature is {0} {1}");
 
@@ -161,9 +161,9 @@ public class StringResourceModelTest ext
 			"The report for {0,date,medium}, shows the temperature as {2,number,###.##} {3} and the weather to be {1}",
 			page.getLocale());
 		StringResourceModel model = new StringResourceModel("weather.detail", page, wsModel,
-			new Object[] { cal.getTime(), "${currentStatus}",
+			        cal.getTime(), "${currentStatus}",
 					new PropertyModel<Double>(wsModel, "currentTemperature"),
-					new PropertyModel<String>(wsModel, "units") });
+					new PropertyModel<String>(wsModel, "units"));
 		String expected = format.format(new Object[] { cal.getTime(), "sunny", 25.7, "\u00B0C" });
 		Assert.assertEquals("Text should be as expected", expected, model.getString());
 		ws.setCurrentStatus("raining");
@@ -176,8 +176,7 @@ public class StringResourceModelTest ext
 	public void testSubstitutionParametersResourceWithSingleQuote() throws Exception
 	{
 		tester.getSession().setLocale(Locale.ENGLISH);
-		StringResourceModel model = new StringResourceModel("with.quote", page, null, new Object[] {
-				10, 20 });
+		StringResourceModel model = new StringResourceModel("with.quote", page, null, 10, 20);
 		assertEquals("2010.00", model.getString());
 
 	}