1 16 17 package org.apache.commons.configuration; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.Properties ; 23 import java.util.Vector ; 24 25 import org.apache.commons.collections.ExtendedProperties; 26 27 34 public final class ConfigurationConverter 35 { 36 private ConfigurationConverter() 37 { 38 } 40 41 47 public static Configuration getConfiguration(ExtendedProperties eprops) 48 { 49 return new MapConfiguration(eprops); 50 } 51 52 58 public static Configuration getConfiguration(Properties props) 59 { 60 return new MapConfiguration(props); 61 } 62 63 69 public static ExtendedProperties getExtendedProperties(Configuration config) 70 { 71 ExtendedProperties props = new ExtendedProperties(); 72 73 Iterator keys = config.getKeys(); 74 75 while (keys.hasNext()) 76 { 77 String key = (String ) keys.next(); 78 Object property = config.getProperty(key); 79 80 if (property instanceof List ) 82 { 83 property = new Vector ((List ) property); 84 } 85 86 props.setProperty(key, property); 87 } 88 89 return props; 90 } 91 92 99 public static Properties getProperties(Configuration config) 100 { 101 Properties props = new Properties (); 102 103 Iterator keys = config.getKeys(); 104 105 while (keys.hasNext()) 106 { 107 String key = (String ) keys.next(); 108 List list = config.getList(key); 109 110 StringBuffer property = new StringBuffer (); 112 Iterator it = list.iterator(); 113 while (it.hasNext()) 114 { 115 property.append(String.valueOf(it.next())); 116 if (it.hasNext()) 117 { 118 property.append(", "); 119 } 120 } 121 122 props.setProperty(key, property.toString()); 123 } 124 125 return props; 126 } 127 128 134 public static Map getMap(Configuration config) 135 { 136 return new ConfigurationMap(config); 137 } 138 139 } 140 | Popular Tags |