[
https://issues.apache.org/jira/browse/LANG-893?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13716518#comment-13716518
]
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:
${number!"N/A"}
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.
Cheers,
Woonsan
[1]
http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
[2]
http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_missing_default
> Default value for StrSubstitutor
> --------------------------------
>
> Key: LANG-893
> URL: https://issues.apache.org/jira/browse/LANG-893
> 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"), "N/A");
> -> "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: http://www.atlassian.com/software/jira