2222import org .apache .commons .configuration2 .PropertiesConfiguration ;
2323import org .apache .commons .configuration2 .builder .FileBasedBuilderParametersImpl ;
2424import org .apache .commons .configuration2 .builder .FileBasedConfigurationBuilder ;
25+ import org .apache .commons .configuration2 .convert .DefaultListDelimiterHandler ;
26+ import org .apache .commons .configuration2 .convert .ListDelimiterHandler ;
2527import org .apache .commons .configuration2 .ex .ConfigurationException ;
2628import org .apache .commons .configuration2 .io .FileHandler ;
2729import org .apache .commons .configuration2 .io .FileLocator ;
3638 */
3739public class ConfigUtils {
3840
41+ private static final ListDelimiterHandler LIST_DELIMITER_HANDLER = new DefaultListDelimiterHandler ( ',' );
42+
3943 /**
4044 * @param file
4145 * @return
@@ -51,7 +55,7 @@ public static FileBasedConfigurationBuilder<PropertiesConfiguration> getConfigBu
5155 }
5256 FileBasedConfigurationBuilder <PropertiesConfiguration > builder = new FileBasedConfigurationBuilder <PropertiesConfiguration >(
5357 PropertiesConfiguration .class );
54- builder .configure ( new FileBasedBuilderParametersImpl ().setFile ( file ) );
58+ builder .configure ( new FileBasedBuilderParametersImpl ().setFile ( file ). setListDelimiterHandler ( LIST_DELIMITER_HANDLER ) );
5559 return builder ;
5660 }
5761
@@ -96,7 +100,7 @@ public static PropertiesConfiguration loadClasspathConfig( String name ) throws
96100 throw new ConfigurationException ( "Couldn't locate: " + name );
97101 }
98102
99- PropertiesConfiguration pc = new PropertiesConfiguration ();
103+ PropertiesConfiguration pc = createConfiguration ();
100104 FileHandler handler = new FileHandler ( pc );
101105 handler .setURL ( url );
102106 handler .load ();
@@ -116,7 +120,7 @@ public static PropertiesConfiguration loadConfig( File file ) throws Configurati
116120 throw new ConfigurationException ( "Couldn't create the file: " + e .getMessage () );
117121 }
118122 }
119- PropertiesConfiguration pc = new PropertiesConfiguration ();
123+ PropertiesConfiguration pc = createConfiguration ();
120124 FileHandler handler = new FileHandler ( pc );
121125 handler .setFile ( file );
122126 handler .load ();
@@ -187,4 +191,10 @@ public static URL locate( String name ) {
187191 FileLocator fl = FileLocatorUtils .fileLocator ().fileName ( name ).create ();
188192 return FileLocatorUtils .locate ( fl );
189193 }
194+
195+ private static PropertiesConfiguration createConfiguration () {
196+ PropertiesConfiguration pc = new PropertiesConfiguration ();
197+ pc .setListDelimiterHandler ( LIST_DELIMITER_HANDLER );
198+ return pc ;
199+ }
190200}
0 commit comments