0

I have a lot of rows/entry in my properties file. Rows are grouped in categories to keep file easier to maintain. I have two key which have the same value. I don't want to remove one because it makes my file harder to maintain.

#category1
var1=foo
....
#category2
var2=foo

Is there any way to make var1 points to var2? I think about sth like that:

    #category1
    var1=->var2 #point to var2
    ....
    #category2
    var2=foo
Mariusz
  • 1,907
  • 3
  • 24
  • 39

1 Answers1

0

java.util.Properties implements the Map interface so you can do everything that this interface offers with it. To allow value to represent a reference to an other key you could wrap the code for getting the value in such a ways that it check whether the value is actually key and then return the value that is mapped by that key.

so you could implement something like this:

String value1 = p.getProperty("var1");
while(p.containsKey(value1)) {
    value1 = p.getProperty(value1);
}

better: add a prefix - $ for example - to value to identify a reference, only if present then resolve:

String value1 = p.getProperty("var1");
while(value1.startsWith("$")) {
    value1 = p.getProperty(value1.substring(1));
}

A good way for wrapping the retrieve-code is by extending the Properties class and override the method getProperty.

For org.springframework.context.support.ReloadableResourceBundleMessageSource you could extend it, override which ever methods you want and configure spring to inject your version of the class.

A4L
  • 17,353
  • 6
  • 49
  • 70
  • 1
    I wanted a quick way to facilitate my task. Your way is not quick becasue of the need to extend ReloadableResourceBundleMessageSource. I do not like to shoot out of a cannon to fly. But your answer is correct so I accepted it. Thanks. – Mariusz Sep 23 '13 at 22:04