List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys();
From source file:com.linkedin.pinot.common.segment.fetcher.SegmentFetcherFactory.java
public static void initSegmentFetcherFactory(Configuration pinotHelixProperties) { Configuration segmentFetcherFactoryConfig = pinotHelixProperties .subset(CommonConstants.Server.PREFIX_OF_CONFIG_OF_SEGMENT_FETCHER_FACTORY); Iterator segmentFetcherFactoryConfigIterator = segmentFetcherFactoryConfig.getKeys(); while (segmentFetcherFactoryConfigIterator.hasNext()) { Object configKeyObject = segmentFetcherFactoryConfigIterator.next(); try {/* w w w .jav a 2 s .co m*/ String segmentFetcherConfigKey = configKeyObject.toString(); String protocol = segmentFetcherConfigKey.split(".", 2)[0]; if (!SegmentFetcherFactory.containsProtocol(protocol)) { SegmentFetcherFactory .initSegmentFetcher(new ConfigurationMap(segmentFetcherFactoryConfig.subset(protocol))); } } catch (Exception e) { LOGGER.error("Got exception to process the key: " + configKeyObject); } } }
From source file:com.github.mbredel.commons.configuration.ConfigurationAssert.java
/** * Checks the content of a configuration. * * @param expected the expected properties * @param actual the configuration to check *///from w w w. ja v a2 s . co m @SuppressWarnings("unused") public static void assertEquals(Configuration expected, Configuration actual) { // check that the actual configuration contains all the properties of the expected configuration for (Iterator<String> it = expected.getKeys(); it.hasNext();) { String key = it.next(); Assert.assertTrue("The actual configuration doesn't contain the expected key '" + key + "'", actual.containsKey(key)); Assert.assertEquals("Value of the '" + key + "' property", expected.getProperty(key), actual.getProperty(key)); } // check that the actual configuration has no extra properties for (Iterator<String> it = actual.getKeys(); it.hasNext();) { String key = it.next(); Assert.assertTrue("The actual configuration contains an extra key '" + key + "'", expected.containsKey(key)); } }
From source file:maltcms.ui.fileHandles.properties.tools.PropertyLoader.java
/** * * @param cfg/* w ww.jav a 2 s . c o 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();/*from w w w . ja v a2 s .co m*/ if (key != null) { Object value = from.getProperty(key); if (value != null) { to.setProperty(key, value); } } } }
From source file:gobblin.metastore.util.DatabaseJobHistoryStoreSchemaManager.java
private static Properties getProperties(Configuration config) { Properties props = new Properties(); char delimiter = (config instanceof AbstractConfiguration) ? ((AbstractConfiguration) config).getListDelimiter() : ','; Iterator keys = config.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); List list = config.getList(key); props.setProperty("flyway." + key, StringUtils.join(list.iterator(), delimiter)); }// w w w .jav a 2 s. c o m return props; }
From source file:com.vmware.qe.framework.datadriven.config.DDConfig.java
/** * Overrides the properties that exist in original configuration with the properties specified * in new configuration, if they already exist. Otherwise, they are added. * /*from ww w. j av a 2 s. co m*/ * @param orgConfig original configuration * @param newConfig new configuration */ private static Configuration overrideConfigProperties(Configuration orgConfig, Configuration newConfig) { if (newConfig == null) { return orgConfig; } if (orgConfig == null) { return newConfig; } Iterator<String> itr = newConfig.getKeys(); while (itr.hasNext()) { String key = itr.next(); orgConfig.setProperty(key, newConfig.getProperty(key)); } return orgConfig; }
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 ww . j a v a2 s . c o m if (objValue instanceof String) { value = (String) objValue; } else { value = objValue.toString(); } properties.setProperty(key, value); } return properties; }
From source file:com.comcast.viper.flume2storm.spout.FlumeSpoutConfiguration.java
/** * @param configuration/*from w w w . j av a 2s .c o m*/ * A configuration object * @return A map that contains the configuration key/values (in order to * serialize it via Kryo) */ protected static Map<String, Object> getMapFromConfiguration(Configuration configuration) { Map<String, Object> result = new HashMap<String, Object>(); Iterator<?> it = configuration.getKeys(); while (it.hasNext()) { String key = it.next().toString(); result.put(key, configuration.getProperty(key)); } return result; }
From source file:com.netflix.config.util.ConfigurationUtils.java
/** * Utility method to obtain <code>Properties</code> given an instance of <code>AbstractConfiguration</code>. * Returns an empty <code>Properties</code> object if the config has no properties or is null. * @param config Configuration to get the properties * @return properties extracted from the configuration *//*from w w w.j a v a 2 s .c o m*/ public static Properties getProperties(Configuration config) { Properties p = new Properties(); if (config != null) { Iterator<String> it = config.getKeys(); while (it.hasNext()) { String key = it.next(); if (key != null) { Object value = config.getProperty(key); if (value != null) { p.put(key, value); } } } } return p; }
From source file:ffx.autoparm.Keyword_poltype.java
/** * This method sets up configuration properties in the following precedence * order: 1.) Java system properties a.) -Dkey=value from the Java command * line b.) System.setProperty("key","value") within Java code. * * 2.) Structure specific properties (for example pdbname.properties) * * 3.) User specific properties (~/.ffx/ffx.properties) * * 4.) System wide properties (file defined by environment variable * FFX_PROPERTIES)/*w ww . j a v a 2 s.c o m*/ * * 5.) Internal force field definition. * * @since 1.0 * @param file a {@link java.io.File} object. * @return a {@link org.apache.commons.configuration.CompositeConfiguration} * object. */ public static CompositeConfiguration loadProperties(File file) { /** * Command line options take precedences. */ CompositeConfiguration properties = new CompositeConfiguration(); properties.addConfiguration(new SystemConfiguration()); /** * Structure specific options are 2nd. */ if (file != null && file.exists() && file.canRead()) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String prmfilename = br.readLine().split(" +")[1]; File prmfile = new File(prmfilename); if (prmfile.exists() && prmfile.canRead()) { properties.addConfiguration(new PropertiesConfiguration(prmfile)); properties.addProperty("propertyFile", prmfile.getCanonicalPath()); } } catch (Exception e1) { e1.printStackTrace(); } } // /** // * User specific options are 3rd. // */ // String filename = System.getProperty("user.home") + File.separator // + ".ffx/ffx.properties"; // File userPropFile = new File(filename); // if (userPropFile.exists() && userPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // userPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // // /** // * System wide options are 2nd to last. // */ // filename = System.getenv("FFX_PROPERTIES"); // if (filename != null) { // File systemPropFile = new File(filename); // if (systemPropFile.exists() && systemPropFile.canRead()) { // try { // properties.addConfiguration(new PropertiesConfiguration( // systemPropFile)); // } catch (Exception e) { // logger.info("Error loading " + filename + "."); // } // } // } /** * Echo the interpolated configuration. */ if (logger.isLoggable(Level.FINE)) { Configuration config = properties.interpolatedConfiguration(); Iterator<String> i = config.getKeys(); while (i.hasNext()) { String s = i.next(); logger.fine("Key: " + s + ", Value: " + Arrays.toString(config.getList(s).toArray())); } } return properties; }