List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys();
From source file:cz.cas.lib.proarc.common.export.Kramerius4ExportOptions.java
public static Kramerius4ExportOptions from(Configuration config) { Kramerius4ExportOptions options = new Kramerius4ExportOptions(); String[] excludeIds = config.getStringArray(PROP_EXCLUDE_DATASTREAM_ID); options.setExcludeDatastreams(new HashSet<String>(Arrays.asList(excludeIds))); Configuration renames = config.subset(PROP_RENAME_PREFIX); HashMap<String, String> dsIdMap = new HashMap<String, String>(); // use RAW if FULL ds is not available dsIdMap.put(BinaryEditor.RAW_ID, "IMG_FULL"); for (Iterator<String> it = renames.getKeys(); it.hasNext();) { String dsId = it.next();// www. j a v a 2 s . c o m String newDsId = renames.getString(dsId); dsIdMap.put(dsId, newDsId); } options.setDsIdMap(dsIdMap); String policy = config.getString(PROP_POLICY); if (policy != null && !policy.isEmpty()) { options.setPolicy(policy); } return options; }
From source file:com.tamnd.core.util.ZConfig.java
private static void ConfigToMap(ConcurrentMap<String, String> map, Configuration config, boolean overwrDup) { if (config == null) { return;// ww w .jav a 2 s . com } Iterator<String> keyIt = config.getKeys(); while (keyIt.hasNext()) { String key = keyIt.next(); if (key == null || key.isEmpty()) { continue; } try { String value = config.getString(key); if (value == null) { continue; } if (overwrDup) { String oldVal = map.put(key, value); if (oldVal != null) { System.out.println("Configuration key \"" + key + "\" has old value \"" + oldVal + "\" has been overwritten by new value \"" + value + "\""); } } else { String oldVal = map.putIfAbsent(key, value); if (oldVal != null) { System.out.println("Configuration key \"" + key + "\" has value \"" + oldVal + "\" NOT be overwrited by new value \"" + value + "\""); } } } catch (Exception ex) { System.err.println(ex); } } }
From source file:dk.itst.oiosaml.sp.service.util.Utils.java
public static Map<String, SAMLHandler> getHandlers(Configuration config, ServletContext servletContext) { Map<String, SAMLHandler> handlers = new HashMap<String, SAMLHandler>(); for (Iterator<?> i = config.getKeys(); i.hasNext();) { String key = (String) i.next(); if (!key.startsWith("oiosaml-sp.protocol.endpoints.")) continue; log.debug("Checking " + key); try {//from w ww .j av a 2 s .c o m Class<?> c = Class.forName(config.getString(key)); SAMLHandler instance; try { Constructor<?> constructor = c.getConstructor(Configuration.class); instance = (SAMLHandler) constructor.newInstance(config); } catch (NoSuchMethodException e) { try { Constructor<?> constructor = c.getConstructor(ServletContext.class); instance = (SAMLHandler) constructor.newInstance(servletContext); } catch (NoSuchMethodException ex) { instance = (SAMLHandler) c.newInstance(); } } // log.info("instance:" + instance.toString()); // pdurbin handlers.put(key.substring(key.lastIndexOf('.') + 1), instance); } catch (Exception e) { log.error("Unable to instantiate " + key + ": " + config.getString(key), e); throw new RuntimeException(e); } } return handlers; }
From source file:com.cisco.oss.foundation.message.HornetQMessagingFactory.java
private static boolean isActiveActiveMode(Configuration subset) { Iterator<String> keys = subset.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (key.contains(".instance")) { return true; }/*from w w w. j a v a 2 s . c om*/ } return false; }
From source file:com.qmetry.qaf.automation.testng.report.ReporterUtil.java
public static synchronized void updateOverview(ITestContext context, ITestResult result) { try {/*from ww w . j a va2 s. co m*/ String file = ApplicationProperties.JSON_REPORT_DIR.getStringVal() + "/" + getTestName(context) + "/overview.json"; TestOverview overview = getJsonObjectFromFile(file, TestOverview.class); if (null == result) { Map<String, Object> runPrams = new HashMap<String, Object>( context.getCurrentXmlTest().getAllParameters()); Configuration env = getBundle().subset("env"); Iterator<?> iter = env.getKeys(); while (iter.hasNext()) { String key = (String) iter.next(); runPrams.put(key, env.getString(key)); } Map<String, Object> envInfo = new HashMap<String, Object>(); envInfo.put("isfw-build-info", getBundle().getObject("isfw.build.info")); envInfo.put("run-parameters", runPrams); envInfo.put("browser-desired-capabilities", getBundle().getObject("driver.desiredCapabilities")); envInfo.put("browser-actual-capabilities", getActualCapabilities()); overview.setEnvInfo(envInfo); Map<String, Object> executionEnvInfo = new HashMap<String, Object>(); executionEnvInfo.put("os.name", System.getProperty("os.name")); executionEnvInfo.put("os.version", System.getProperty("os.version")); executionEnvInfo.put("os.arch", System.getProperty("os.arch")); executionEnvInfo.put("java.version", System.getProperty("java.version")); executionEnvInfo.put("java.vendor", System.getProperty("java.vendor")); executionEnvInfo.put("java.arch", System.getProperty("sun.arch.data.model")); executionEnvInfo.put("user.name", System.getProperty("user.name")); try { executionEnvInfo.put("host", InetAddress.getLocalHost().getHostName()); } catch (Exception e) { // This code added for MAC to fetch hostname String hostname = execHostName("hostname"); executionEnvInfo.put("host", hostname); } envInfo.put("execution-env-info", executionEnvInfo); } int pass = getPassCnt(context); int fail = getFailCnt(context) + getFailWithPassPerCnt(context); int skip = getSkipCnt(context); int total = getTotal(context); overview.setTotal(total > (pass + fail + skip) ? total : pass + fail + skip); overview.setPass(pass); overview.setSkip(skip); overview.setFail(fail); if (null != result) { overview.getClasses().add(result.getTestClass().getName()); } if ((overview.getStartTime() > 0)) { overview.setEndTime(System.currentTimeMillis()); } else { overview.setStartTime(System.currentTimeMillis()); } writeJsonObjectToFile(file, overview); updateMetaInfo(context.getSuite()); } catch (Exception e) { logger.debug(e); } }
From source file:com.qmetry.qaf.automation.testng.pro.DataProviderUtil.java
public static List<Object[]> getDataSetAsMap(String key) { Configuration config = ConfigurationManager.getBundle().subset(key); ArrayList<Object[]> dataset = new ArrayList<Object[]>(); if (config.isEmpty()) { logger.error("Missing data with key [" + key + "]. "); throw new DataProviderException("Not test data found with key:" + key); }/*from w ww .j a va2 s .c om*/ int size = config.getList(config.getKeys().next().toString()).size(); for (int i = 0; i < size; i++) { Map<String, String> map = new LinkedHashMap<String, String>(); Iterator<?> iter = config.getKeys(); while (iter.hasNext()) { String dataKey = String.valueOf(iter.next()); try { map.put(dataKey, config.getStringArray(dataKey)[i]); } catch (ArrayIndexOutOfBoundsException e) { logger.error( "Missing entry for property " + dataKey + ". Provide value for each property (or blank) in each data set in data file.", e); throw e; } } dataset.add(new Object[] { map }); } return dataset; }
From source file:com.yahoo.ads.pb.PistachiosServer.java
public static Producer getKafkaProducerInstance() { try {/*from w ww .j av a 2s . c om*/ if (kafkaProducer == null) { synchronized (logger) { if (kafkaProducer == null) { logger.debug("first time using kafka producer, creating it"); try { Properties props = new Properties(); Configuration conf = ConfigurationManager.getConfiguration(); @SuppressWarnings("unchecked") Iterator<String> iter = conf.getKeys(); while (iter.hasNext()) { String key = iter.next(); if (key.startsWith("kafka.") == true) { String stormSetting = key.substring(6); props.put(stormSetting, conf.getString(key)); logger.info("Strom setting::{}={}", stormSetting, conf.getString(key)); } } ProducerConfig kafkaConf = new ProducerConfig(props); kafkaProducer = new Producer<String, byte[]>(kafkaConf); } catch (Throwable t) { logger.error("Exception in creating Producer:", t); } logger.debug("created kafka producer"); } } } } catch (Throwable t) { logger.error("error creating kafka producer instance", t); } return kafkaProducer; }
From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java
private static VelocityContext createVelocityContext(Configuration configuration) { VelocityContext velocityContext = new VelocityContext(); if (configuration != null) { String key = null;/*from w ww. j ava 2 s. co m*/ for (Iterator<String> it = configuration.getKeys(); it.hasNext();) { key = it.next(); velocityContext.put(key, configuration.getString(key)); } } return velocityContext; }
From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java
@SuppressWarnings("unchecked") public static Map<String, Map<String, Map<String, String>>> getClusterConfiguration( final Configuration configuration, SortedSet<String> mounts) throws IOException { Map<String, Map<String, Map<String, String>>> clusterConfiguration = new HashMap<String, Map<String, Map<String, String>>>(); Iterator<String> keys = configuration.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (key.startsWith(CONFIG_WHIRR_CM_CONFIG_PREFIX)) { String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key, CONFIG_WHIRR_CM_CONFIG_PREFIX); clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2], configuration.getString(key)); }/* w ww .jav a2s .c o m*/ } keys = configuration.getKeys(); while (keys.hasNext()) { final String key = keys.next(); if (key.startsWith(CONFIG_WHIRR_INTERNAL_CM_CONFIG_DEFAULT_PREFIX)) { String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key, CONFIG_WHIRR_INTERNAL_CM_CONFIG_DEFAULT_PREFIX); if (configuration.getString( CONFIG_WHIRR_CM_CONFIG_PREFIX + keyTokens[1].toLowerCase() + "." + keyTokens[2]) == null) { if ((keyTokens[2].endsWith(CONFIG_CM_DIR_SUFFIX_LIST) || keyTokens[2].endsWith(CONFIG_CM_DIR_SUFFIX_PLURAL)) && !mounts.isEmpty()) { clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2], Joiner.on(',') .join(Lists.transform(Lists.newArrayList(mounts), new Function<String, String>() { @Override public String apply(String input) { return input + configuration.getString(key); } }))); } else { clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2], (mounts.isEmpty() ? configuration.getString(CONFIG_WHIRR_INTERNAL_DATA_DIRS_DEFAULT) : mounts.iterator().next()) + configuration.getString(key)); } } } } keys = configuration.getKeys(); while (keys.hasNext()) { final String key = keys.next(); if (key.startsWith(CONFIG_WHIRR_CM_CONFIG_PREFIX) && key.endsWith(CONFIG_CM_DB_SUFFIX_TYPE)) { String[] keyTokens = getClusterConfigurationKeyTokens(clusterConfiguration, key, CONFIG_WHIRR_CM_CONFIG_PREFIX); if (configuration.getString(key) != null && configuration.getString(key).length() == 0) { clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put(keyTokens[2], configuration.getString(CONFIG_WHIRR_DB_TYPE)); if (configuration .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT)) != null && configuration .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT)) .length() == 0) { clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put( keyTokens[2].replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_PORT), configuration.getString(CONFIG_WHIRR_INTERNAL_PORTS_DB_PREFIX + configuration.getString(CONFIG_WHIRR_DB_TYPE))); } else if (configuration .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST)) != null && !configuration .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST)) .contains(":")) { clusterConfiguration.get(keyTokens[0]).get(keyTokens[1]).put( keyTokens[2].replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST), configuration .getString(key.replace(CONFIG_CM_DB_SUFFIX_TYPE, CONFIG_CM_DB_SUFFIX_HOST)) + ":" + configuration.getString(CONFIG_WHIRR_INTERNAL_PORTS_DB_PREFIX + configuration.getString(CONFIG_WHIRR_DB_TYPE))); } } } } if (clusterConfiguration.get(CM_API_BASE_VERSION) == null) { clusterConfiguration.put(CM_API_BASE_VERSION, new HashMap<String, Map<String, String>>()); } if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) == null) { clusterConfiguration.get(CM_API_BASE_VERSION).put(CmServerServiceType.CLUSTER.getId(), new HashMap<String, String>()); } if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) .get(CONFIG_CM_LICENSE_PROVIDED) == null) { if (Utils.urlForURI(configuration.getString(CONFIG_WHIRR_CM_LICENSE_URI)) != null) { clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) .put(CONFIG_CM_LICENSE_PROVIDED, Boolean.TRUE.toString()); } else { clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) .put(CONFIG_CM_LICENSE_PROVIDED, Boolean.FALSE.toString()); } } if (clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.CLUSTER.getId()) .get(CONFIG_CM_LICENSE_PROVIDED).equals(Boolean.TRUE.toString())) { if (clusterConfiguration.get(CM_API_BASE_VERSION) .get(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId()) == null) { clusterConfiguration.get(CM_API_BASE_VERSION) .put(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId(), new HashMap<String, String>()); } clusterConfiguration.get(CM_API_BASE_VERSION).get(CmServerServiceType.MAPREDUCE_TASK_TRACKER.getId()) .put(CONFIG_CM_TASKTRACKER_INSTRUMENTATION, "org.apache.hadoop.mapred.TaskTrackerCmonInst"); } return clusterConfiguration; }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
private static Map<String, String> createSubstitutionContext(Configuration configuration) { Map<String, String> substitutionContextMap = null; if (configuration != null) { substitutionContextMap = new HashMap<String, String>(); String key = null;// w w w . j av a 2 s. c o m for (Iterator<String> it = configuration.getKeys(); it.hasNext();) { key = it.next(); substitutionContextMap.put(key, configuration.getString(key)); } } return substitutionContextMap; }