List of usage examples for org.apache.commons.configuration Configuration getProperty
Object getProperty(String key);
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static JSONObject getJSON(Configuration config) { JSONObject output = new JSONObject(); if (!config.isEmpty()) { Iterator it = config.getKeys(); while (it.hasNext()) { String k = (String) it.next(); // noinspection unchecked String v = (String) config.getProperty(k); output.put(k, v);/* w ww .ja v a 2 s . co m*/ } } return output; }
From source file:com.linkedin.pinot.server.starter.helix.DefaultHelixStarterServerConfig.java
public static ServerConf getDefaultHelixServerConfig(Configuration externalConfigs) { Configuration defaultConfigs = loadDefaultServerConf(); @SuppressWarnings("unchecked") Iterator<String> iterable = externalConfigs.getKeys(); while (iterable.hasNext()) { String key = iterable.next(); defaultConfigs.setProperty(key, externalConfigs.getProperty(key)); LOGGER.info("External config key: {}, value: {}", key, externalConfigs.getProperty(key)); }/*from w w w .j a v a 2s . co m*/ return new ServerConf(defaultConfigs); }
From source file:io.servicecomb.serviceregistry.config.ConfigurePropertyUtils.java
public static Map<String, String> getPropertiesWithPrefix(Configuration configuration, String prefix) { Map<String, String> propertiesMap = new HashMap<>(); Iterator<String> keysIterator = configuration.getKeys(prefix); while (keysIterator.hasNext()) { String key = keysIterator.next(); propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(configuration.getProperty(key))); }/*from w w w . j a v a 2 s .c o m*/ return propertiesMap; }
From source file:com.zavakid.mushroom.impl.ConfigUtil.java
static void assertEq(Configuration expected, Configuration actual) { // Check that the actual config contains all the properties of the expected for (Iterator<?> it = expected.getKeys(); it.hasNext();) { String key = (String) it.next(); assertTrue("actual should contain " + key, actual.containsKey(key)); assertEquals("value of " + key, expected.getProperty(key), actual.getProperty(key)); }/*from w w w . j a va2s . c o m*/ // Check that the actual config has no extra properties for (Iterator<?> it = actual.getKeys(); it.hasNext();) { String key = (String) it.next(); assertTrue("expected should contain " + key, expected.containsKey(key)); } }
From source file:com.linkedin.pinot.routing.RoutingTableSelectorFactory.java
public static RoutingTableSelector getRoutingTableSelector(Configuration config) { RoutingTableSelector routingTableSelector = new PercentageBasedRoutingTableSelector(); if (config == null) { LOGGER.warn("No config for routing table selector. Using default"); } else {/*from w w w . j a v a2 s.co m*/ String selectorClassName = null; try { selectorClassName = (String) config.getProperty(CLASSNAME_KEY); } catch (Exception e) { LOGGER.warn("Could not parse property '{}'. Using {}", CLASSNAME_KEY, defaultClasssName, e); } Class<? extends RoutingTableSelector> clazz; if (selectorClassName == null || selectorClassName.isEmpty()) { LOGGER.info("Null or empty selector class name. Using default"); } else { try { clazz = (Class<? extends RoutingTableSelector>) Class.forName(selectorClassName); routingTableSelector = clazz.newInstance(); } catch (ClassNotFoundException e) { LOGGER.warn("Could not load '{}'. Loading {}", selectorClassName, defaultClasssName, e); } catch (InstantiationException e) { LOGGER.warn("Could not instantiate '{}'. Instantiating {}", selectorClassName, defaultClasssName, e); } catch (IllegalAccessException e) { LOGGER.warn("Could not instantiate '{}'. Instantiating {}", selectorClassName, defaultClasssName, e); } } } routingTableSelector.init(config); return routingTableSelector; }
From source file:com.netflix.config.util.ConfigurationUtils.java
private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) { String nextLoadKeyToUse = null; for (String key : nextLoadPropertyKeys) { if (propConfig.getProperty(key) != null) { nextLoadKeyToUse = key;//ww w . j a va 2s . com break; } } // there is no next load for this properties file if (nextLoadKeyToUse == null) { return null; } // make a copy of current existing properties ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); // need to have all the properties to interpolate next load property value copyProperties(ConfigurationManager.getConfigInstance(), config); copyProperties(propConfig, config); // In case this is a list of files to load, always treat the value as a list List<Object> list = config.getList(nextLoadKeyToUse); StringBuilder sb = new StringBuilder(); for (Object value : list) { sb.append(value).append(","); } String nextLoad = sb.toString(); propConfig.clearProperty(nextLoadKeyToUse); return nextLoad; }
From source file:maltcms.ui.fileHandles.properties.tools.PropertyLoader.java
/** * * @param cfg//from w w w.j av a2 s.co m * @return */ public static Map<String, Object> asHash(Configuration cfg) { Map<String, Object> hash = new HashMap<>(); Iterator i = cfg.getKeys(); String key; while (i.hasNext()) { key = (String) i.next(); Object o = cfg.getProperty(key); hash.put(key, o); } return hash; }
From source file:com.netflix.config.util.ConfigurationUtils.java
public static void copyProperties(Configuration from, Configuration to) { for (Iterator<String> i = from.getKeys(); i.hasNext();) { String key = i.next();/* w w w .j ava2 s .c o m*/ if (key != null) { Object value = from.getProperty(key); if (value != null) { to.setProperty(key, value); } } } }
From source file:com.twitter.distributedlog.util.ConfUtils.java
/** * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into * target configuration <i>targetConf</i>. * * @param targetConf/* www . j av a 2 s . c om*/ * Target Configuration * @param srcConf * Source Configuration * @param section * Section Key */ public static void loadConfiguration(Configuration targetConf, Configuration srcConf, String section) { Iterator confKeys = srcConf.getKeys(); while (confKeys.hasNext()) { Object keyObject = confKeys.next(); if (!(keyObject instanceof String)) { continue; } String key = (String) keyObject; if (key.startsWith(section)) { targetConf.setProperty(key.substring(section.length()), srcConf.getProperty(key)); } } }
From source file:com.xemantic.tadedon.configuration.Configurations.java
public static Properties toProperties(Configuration configuraton) { Properties properties = new Properties(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = configuraton.getKeys(); iterator.hasNext();) { String key = iterator.next(); Object objValue = configuraton.getProperty(key); String value;//from w w w .j av a 2s. com if (objValue instanceof String) { value = (String) objValue; } else { value = objValue.toString(); } properties.setProperty(key, value); } return properties; }