You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2007/08/29 12:17:18 UTC
svn commit: r570737 -
/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.java
Author: jcompagner
Date: Wed Aug 29 03:17:06 2007
New Revision: 570737
URL: http://svn.apache.org/viewvc?rev=570737&view=rev
Log:
better toString impl
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/StringResourceModel.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=570737&r1=570736&r2=570737&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 Wed Aug 29 03:17:06 2007
@@ -17,6 +17,7 @@
package org.apache.wicket.model;
import java.text.MessageFormat;
+import java.util.Arrays;
import java.util.Locale;
import org.apache.wicket.Application;
@@ -28,61 +29,52 @@
/**
- * This model class encapsulates the full power of localization support within
- * the Wicket framework. It combines the flexible Wicket resource loading
- * mechanism with property expressions, property models and standard Java
- * <code>MessageFormat</code> substitutions. This combination should be able
- * to solve any dynamic localization requirement that a project has.
+ * This model class encapsulates the full power of localization support within the Wicket framework.
+ * It combines the flexible Wicket resource loading mechanism with property expressions, property
+ * models and standard Java <code>MessageFormat</code> substitutions. This combination should be
+ * able to solve any dynamic localization requirement that a project has.
* <p>
- * The model should be created with four parameters, which are described in
- * detail below:
+ * The model should be created with four parameters, which are described in detail below:
* <ul>
- * <li><b>resourceKey </b>- This is the most important parameter as it contains
- * the key that should be used to obtain resources from any string resource
- * loaders. This paramater is mandatory: a null value will throw an exception.
- * Typically it will contain an ordinary string such as
- * "label.username". To add extra power to the key functionality the
- * key may also contain a property expression which will be evaluated if the
- * model parameter (see below) is not null. This allows keys to be changed
- * dynamically as the application is running. For example, the key could be
- * "product.${product.id}" which prior to rendering will call
- * model.getObject().getProduct().getId() and substitute this value into the
- * resource key before is is passed to the loader.
- * <li><b>component </b>- This parameter should be a component that the string
- * resource is relative to. In a simple application this will usually be the
- * Page on which the component resides. For reusable components/containers that
- * are packaged with their own string resource bundles it should be the actual
- * component/container rather than the page. For more information on this please
- * see {@link org.apache.wicket.resource.loader.ComponentStringResourceLoader}.
- * The relative component may actually be <code>null</code> when all resource
- * loading is to be done from a global resource loader. However, we recommend
- * that a relative component is still supplied even in these cases in order to
- * 'future proof' your application with regards to changing resource loading
+ * <li><b>resourceKey </b>- This is the most important parameter as it contains the key that should
+ * be used to obtain resources from any string resource loaders. This paramater is mandatory: a null
+ * value will throw an exception. Typically it will contain an ordinary string such as
+ * "label.username". To add extra power to the key functionality the key may also contain
+ * a property expression which will be evaluated if the model parameter (see below) is not null.
+ * This allows keys to be changed dynamically as the application is running. For example, the key
+ * could be "product.${product.id}" which prior to rendering will call
+ * model.getObject().getProduct().getId() and substitute this value into the resource key before is
+ * is passed to the loader.
+ * <li><b>component </b>- This parameter should be a component that the string resource is relative
+ * to. In a simple application this will usually be the Page on which the component resides. For
+ * reusable components/containers that are packaged with their own string resource bundles it should
+ * be the actual component/container rather than the page. For more information on this please see
+ * {@link org.apache.wicket.resource.loader.ComponentStringResourceLoader}. The relative component
+ * may actually be <code>null</code> when all resource loading is to be done from a global
+ * resource loader. However, we recommend that a relative component is still supplied even in these
+ * cases in order to 'future proof' your application with regards to changing resource loading
* strategies.
- * <li><b>model </b>- This parameter is mandatory if either the resourceKey,
- * the found string resource (see below) or any of the substitution parameters
- * (see below) contain property expressions. Where property expressions are
- * present they will all be evaluated relative to this model object. If there
- * are no property expressions present then this model parameter may be
+ * <li><b>model </b>- This parameter is mandatory if either the resourceKey, the found string
+ * resource (see below) or any of the substitution parameters (see below) contain property
+ * expressions. Where property expressions are present they will all be evaluated relative to this
+ * model object. If there are no property expressions present then this model parameter may be
* <code>null</code>
- * <li><b>parameters </b>- The parameters parameter allows an array of objects
- * to be passed for substitution on the found string resource (see below) using
- * a standard <code>java.text.MessageFormat</code> object. Each parameter may
- * be an ordinary Object, in which case it will be processed by the standard
- * formatting rules associated with <code>java.text.MessageFormat</code>.
- * Alternatively, the parameter may be an instance of <code>IModel</code> in
- * which case the <code>getObject()</code> method will be applied prior to the
- * parameter being passed to the <code>java.text.MessageFormat</code>. This
- * allows such features dynamic parameters that are obtained using a
- * <code>PropertyModel</code> object or even nested string resource models.
+ * <li><b>parameters </b>- The parameters parameter allows an array of objects to be passed for
+ * substitution on the found string resource (see below) using a standard
+ * <code>java.text.MessageFormat</code> object. Each parameter may be an ordinary Object, in which
+ * case it will be processed by the standard formatting rules associated with
+ * <code>java.text.MessageFormat</code>. Alternatively, the parameter may be an instance of
+ * <code>IModel</code> in which case the <code>getObject()</code> method will be applied prior
+ * to the parameter being passed to the <code>java.text.MessageFormat</code>. This allows such
+ * features dynamic parameters that are obtained using a <code>PropertyModel</code> object or even
+ * nested string resource models.
* </ul>
- * As well as the supplied parameters, the found string resource can contain
- * formatting information. It may contain property expressions in which case
- * these are evaluated using the model object supplied when the string resource
- * model is created. The string resource may also contain
- * <code>java.text.MessageFormat</code> style markup for replacement of
- * parameters. Where a string resource contains both types of formatting
- * information then the property expression will be applied first.
+ * As well as the supplied parameters, the found string resource can contain formatting information.
+ * It may contain property expressions in which case these are evaluated using the model object
+ * supplied when the string resource model is created. The string resource may also contain
+ * <code>java.text.MessageFormat</code> style markup for replacement of parameters. Where a string
+ * resource contains both types of formatting information then the property expression will be
+ * applied first.
* <p>
* <b>Example 1 </b>
* <p>
@@ -98,13 +90,11 @@
* }
* </pre>
*
- * Where the resource bundle for the page contains the entry
- * <code>label.username=Username</code>
+ * Where the resource bundle for the page contains the entry <code>label.username=Username</code>
* <p>
* <b>Example 2 </b>
* <p>
- * In this example, the resource key is selected based on the evaluation of a
- * property expression:
+ * In this example, the resource key is selected based on the evaluation of a property expression:
*
* <pre>
* public MyPage extends WebPage
@@ -118,9 +108,8 @@
* }
* </pre>
*
- * Which will call the WeatherStation.getCurrentStatus() method each time the
- * string resource model is used and where the resource bundle for the page
- * contains the entries:
+ * Which will call the WeatherStation.getCurrentStatus() method each time the string resource model
+ * is used and where the resource bundle for the page contains the entries:
*
* <pre>
* weather.sunny=Don't forget sunscreen!
@@ -132,8 +121,8 @@
* <p>
* <b>Example 3 </b>
* <p>
- * In this example the found resource string contains a property expression that
- * is substituted via the model:
+ * In this example the found resource string contains a property expression that is substituted via
+ * the model:
*
* <pre>
* public MyPage extends WebPage
@@ -147,15 +136,13 @@
* }
* </pre>
*
- * Where the resource bundle contains the entry
- * <code>weather.message=Weather station reports that
+ * Where the resource bundle contains the entry <code>weather.message=Weather station reports that
* the temperature is ${currentTemperature} ${units}</code>
* <p>
* <b>Example 4 </b>
* <p>
- * In this example, the use of substitution parameters is employed to format a
- * quite complex message string. This is an example of the most complex and
- * powerful use of the string resource model:
+ * In this example, the use of substitution parameters is employed to format a quite complex message
+ * string. This is an example of the most complex and powerful use of the string resource model:
*
* <pre>
* public MyPage extends WebPage
@@ -195,8 +182,8 @@
private transient Locale locale;
/**
- * The localizer to be used to access localized resources and the associated
- * locale for formatting.
+ * The localizer to be used to access localized resources and the associated locale for
+ * formatting.
*/
private transient Localizer localizer;
@@ -255,14 +242,13 @@
/**
* Creates a new string resource model using the supplied parameters.
* <p>
- * The relative component parameter should generally be supplied, as without
- * it resources can not be obtained from resouce bundles that are held
- * relative to a particular component or page. However, for application that
- * use only global resources then this parameter may be null.
+ * The relative component parameter should generally be supplied, as without it resources can
+ * not be obtained from resouce bundles that are held relative to a particular component or
+ * page. However, for application that use only global resources then this parameter may be
+ * null.
* <p>
- * The model parameter is also optional and only needs to be supplied if
- * value substitutions are to take place on either the resource key or the
- * actual resource strings.
+ * The model parameter is also optional and only needs to be supplied if value substitutions are
+ * 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.
*
@@ -284,14 +270,13 @@
/**
* Creates a new string resource model using the supplied parameters.
* <p>
- * The relative component parameter should generally be supplied, as without
- * it resources can not be obtained from resouce bundles that are held
- * relative to a particular component or page. However, for application that
- * use only global resources then this parameter may be null.
+ * The relative component parameter should generally be supplied, as without it resources can
+ * not be obtained from resouce bundles that are held relative to a particular component or
+ * page. However, for application that use only global resources then this parameter may be
+ * null.
* <p>
- * The model parameter is also optional and only needs to be supplied if
- * value substitutions are to take place on either the resource key or the
- * actual resource strings.
+ * The model parameter is also optional and only needs to be supplied if value substitutions are
+ * 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.
*
@@ -331,10 +316,9 @@
}
/**
- * Gets the string currently represented by this string resource model. The
- * string that is returned may vary for each call to this method depending
- * on the values contained in the model and an the parameters that were
- * passed when this string resource model was created.
+ * Gets the string currently represented by this string resource model. The string that is
+ * returned may vary for each call to this method depending on the values contained in the model
+ * and an the parameters that were passed when this string resource model was created.
*
* @return The string
*/
@@ -398,9 +382,8 @@
}
/**
- * Sets the localizer that is being used by this string resource model. This
- * method is provided to allow the default application localizer to be
- * overridden if required.
+ * Sets the localizer that is being used by this string resource model. This method is provided
+ * to allow the default application localizer to be overridden if required.
*
* @param localizer
* The localizer to use
@@ -411,15 +394,23 @@
}
/**
- * Override of the default method to return the resource string represented
- * by this string resource model. Useful in debugging and so on, to avoid
- * the explicit need to call the getString() method.
+ * Override of the default method to return the resource string represented by this string
+ * resource model. Useful in debugging and so on, to avoid the explicit need to call the
+ * getString() method.
*
* @return The string for this model object
*/
public String toString()
{
- return getString();
+ StringBuffer sb = new StringBuffer("StringResourceModel[");
+ sb.append("key:");
+ sb.append(resourceKey);
+ sb.append(",default:");
+ sb.append(defaultValue);
+ sb.append(",params:");
+ sb.append(Arrays.asList(parameters));
+ sb.append("]");
+ return sb.toString();
}
/**
@@ -433,9 +424,9 @@
}
/**
- * Gets the resource key for this string resource. If the resource key
- * contains property expressions and the model is null then the returned
- * value is the actual resource key with all substitutions undertaken.
+ * Gets the resource key for this string resource. If the resource key contains property
+ * expressions and the model is null then the returned value is the actual resource key with all
+ * substitutions undertaken.
*
* @return The (possibly substituted) resource key
*/
@@ -452,9 +443,8 @@
}
/**
- * Gets the string that this string resource model currently represents. The
- * string is returned as an object to allow it to be used generically within
- * components.
+ * Gets the string that this string resource model currently represents. The string is returned
+ * as an object to allow it to be used generically within components.
*
*/
protected Object load()
@@ -463,8 +453,8 @@
final Session session = Session.get();
if (session != null)
{
- this.localizer = Application.get().getResourceSettings().getLocalizer();
- this.locale = session.getLocale();
+ localizer = Application.get().getResourceSettings().getLocalizer();
+ locale = session.getLocale();
}
else
{
@@ -486,7 +476,7 @@
}
// Null out references
- this.localizer = null;
- this.locale = null;
+ localizer = null;
+ locale = null;
}
}