commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Woonsan Ko (JIRA)" <>
Subject [jira] [Commented] (LANG-893) Default value for StrSubstitutor
Date Tue, 23 Jul 2013 15:58:48 GMT


Woonsan Ko commented on LANG-893:

Hi Lauri / Gary,

I met this issue while looking for a solution to set a default value for unresolved property
value in log4j2 which uses the same StrSubstitutor code [1].
I think it would be more valuable and flexible if it supports default value setting syntax
for each property like what Freemarker provides. [2]
For example, we might want to use the following instead:


If "number" property is not found, it should return "N/A" as default value (the optional value
delimiter is "!" by default). This way it would give more flexibility.
What do you think?
If my idea sounds okay to you, I would like to try to create a patch for it.



> Default value for StrSubstitutor
> --------------------------------
>                 Key: LANG-893
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.text.*
>    Affects Versions: 2.4
>            Reporter: Lauri Siltanen
>            Priority: Minor
> public static void main(String[] args) {
> 		String s = "The number of ${item} items currently available: ${number}";		
> 		String result = StrSubstitutor.replace(s, Collections.singletonMap("item", "monitor"));
> 		System.out.println(result);
> 	}
> This results in: "The number of monitor items currently available: ${number}".
> I'd need a default value for a placeholder that cannot be resolved.
> String result = StrSubstitutor.replace(s, Collections.singletonMap("item", "monitor"),
> -> "The number of monitor items currently available: N/A".

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message