}
private String getString(final Component component)
{
final Localizer localizer = getLocalizer();
String value;
// Substitute any parameters if necessary
Object[] parameters = getParameters();
if (parameters == null || parameters.length == 0)
{
// Get the string resource, doing any property substitutions as part
// of the get operation
String defaultVal = defaultValue != null ? defaultValue.getObject() : null;
value = localizer.getString(getResourceKey(), component, model, defaultVal);
if (value == null)
{
value = defaultVal;
}
}
else
{
// Get the string resource, doing not any property substitutions
// that has to be done later after MessageFormat
String defaultVal = defaultValue != null ? defaultValue.getObject() : null;
value = localizer.getString(getResourceKey(), component, null, defaultVal);
if (value == null)
{
value = defaultVal;
}
if (value != null)
{
// Build the real parameters
Object[] realParams = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++)
{
if (parameters[i] instanceof IModel<?>)
{
realParams[i] = ((IModel<?>)parameters[i]).getObject();
}
else if (model != null && parameters[i] instanceof String)
{
realParams[i] = localizer.substitutePropertyExpressions(component,
(String)parameters[i], model);
}
else
{
realParams[i] = parameters[i];
}
}
// Escape all single quotes outside {..}
if (value.indexOf('\'') != -1)
{
value = escapeQuotes(value);
}
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, getLocale());
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);
}
}
}
// Return the string resource