4

Possible Duplicate:
How to reference another property in java.util.Properties?

I want to refer to other variables in my properties file, e.g.:

name=World
text=Hello $(name)!

"text" should now be "Hello World!".

I know I could do it by hand but is there anything I could use which does the work for me?

Community
  • 1
  • 1
jhasse
  • 2,379
  • 1
  • 30
  • 40
  • And what should happen, if at a later point, the property `name` is changed to "grils and guys"? Will `text`remain "Hello World!" or will it become "Hello Gils and guys!"? – rds Dec 05 '11 at 10:22
  • doesn't really matter for me. so remaining "Hello World!" would be fine ;) – jhasse Dec 05 '11 at 10:26

3 Answers3

2

Doing it by hand is the normal way to go. But I suppose you could also override the put method of Properties so that it's done only once.

@Override
public Object put(Object key, Object value) {
    super.put(key, substitute(value))
}

/** Substitutes variables with their value */
private String substitue(String string) {
   // TODO: find "{...}" and replace it by the value obtained by get()
   // Be careful here!
}
rds
  • 26,253
  • 19
  • 107
  • 134
2

One of the options mentioned in the question that Michael linked to in his comment above that I feel may help you is eproperties. Looks pretty promising.

HTH!

Community
  • 1
  • 1
aishwarya
  • 1,970
  • 1
  • 14
  • 22
0

Get all the building blogs from the properties file and then programatically construct what you need in java.

dimitrisli
  • 20,895
  • 12
  • 59
  • 63