Well, I need this function in order to: bind the values ββof individual values ββwith properties and be able to extract them all even by interpolation.
So, I wrote my own interpolation class and custom property configuration. Works well even with backslash and default delimiter values.
So the custom interpolation class:
Class CustomInterPolation
public class CustomInterpolation extends StrLookup { @Override public String lookup(String arg0) { String result = null;
Now, to properly use this customInterpolation class, we need to use a custom property configuration:
CustomPropertiesConfiguration class
public class CustomPropertiesConfiguration extends PropertiesConfiguration { private String delimiter; public CustomPropertiesConfiguration() { super(); delimiter = PropertiesConfiguration.getDefaultListDelimiter() + ""; } public CustomPropertiesConfiguration (File file) throws ConfigurationException{ super(file); delimiter = PropertiesConfiguration.getDefaultListDelimiter() + ""; } public CustomPropertiesConfiguration(String fileName) throws ConfigurationException { super(fileName); delimiter = PropertiesConfiguration.getDefaultListDelimiter() + ""; } public CustomPropertiesConfiguration(URL url) throws ConfigurationException{ super(url); delimiter = PropertiesConfiguration.getDefaultListDelimiter() + ""; } @Override public List<Object> getList(String key) {
And here is a small main class:
public class TestMacro { /** * @param args */ public static void main(String[] args) { // Load properties file : try { // Add an interpolation to the configuration. // The string "custom" will be used to find value to interpolate // with the custom interpolation ConfigurationInterpolator.registerGlobalLookup("custom", new CustomInterpolation()); // Set the properties configuration. Configuration config = new CustomPropertiesConfiguration( "ressources/macro.properties"); String baseProp = "base.prop"; String firstProp = "first.prop"; String secondProp = "second.prop"; ArrayList<Object> values = (ArrayList<Object>) config .getList(baseProp); System.out.println(baseProp + "=>"); for (int i = 0; i < values.size(); ++i) { System.out.println("[" + i + "]" + values.get(i)); } System.out.println(); values = (ArrayList<Object>) config.getList(firstProp); System.out.println(firstProp + "=>"); for (int i = 0; i < values.size(); ++i) { System.out.println("[" + i + "]" + values.get(i)); } System.out.println(); values = (ArrayList<Object>) config.getList(secondProp); System.out.println(secondProp + "=>"); for (int i = 0; i < values.size(); ++i) { System.out.println("[" + i + "]" + values.get(i)); } } catch (ConfigurationException e) { e.printStackTrace(); } } }
For tests, I used the following properties file:
base.prop = /base, /root\\\\\\\\, t\\,t\\,t\\,t\\, first.prop = ${custom:base.prop}, /first\\,/base second.prop = ${custom:first.prop}, /second
And I get the following output:
base.prop=> [0]/base [1]/root\\ [2]t,t,t,t, first.prop=> [0]/base [1]/root\\ [2]t,t,t,t, [3]/first,/base second.prop=> [0]/base [1]/root\\ [2]t,t,t,t, [3]/first,/base [4]/second
As you can see, the solution can handle property values ββwith a backslash and default separator ','. Some templates containing these two elements may not be processed correctly, but this solution should handle the basic values.