Java Code Examples for org.apache.commons.configuration.Configuration#getKeys()

The following examples show how to use org.apache.commons.configuration.Configuration#getKeys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Kramerius4ExportOptions.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
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();
        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;
}
 
Example 2
Source File: HtmlBenchmarkReportGenerator.java    From ldbc_graphalytics with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getAllBenchmarkConfigurations() {
	Map<String, String> confs = new HashMap<>();

	Set<String> keysWithStringArray = new HashSet<>();
	keysWithStringArray.add("graphs.names");

	Configuration benchmarkConf = ConfigurationUtil.loadConfiguration(BENCHMARK_PROPERTIES_FILE);

	Iterator<String> keys = benchmarkConf.getKeys();
	while(keys.hasNext()) {
		String key = keys.next();

		if(keysWithStringArray.contains(key)) {
			String[] valueArray = benchmarkConf.getStringArray(key);
			String summarizedValue = Arrays.asList(valueArray).toString();
			confs.put(key, summarizedValue);
		} else {
			confs.put(key, benchmarkConf.getString(key));
		}
	}
	return confs;
}
 
Example 3
Source File: SettingsLoader.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
public static Map<String, JSONObject> loadKnownHosts(String config_path)
		throws ConfigurationException, ParseException {
	Configuration hosts = new PropertiesConfiguration(config_path);

	Iterator<String> keys = hosts.getKeys();
	Map<String, JSONObject> known_hosts = new HashMap<String, JSONObject>();
	JSONParser parser = new JSONParser();

	while (keys.hasNext()) {
		String key = keys.next().trim();
		JSONArray value = (JSONArray) parser.parse(hosts.getProperty(key)
				.toString());
		known_hosts.put(key, (JSONObject) value.get(0));
	}

	return known_hosts;
}
 
Example 4
Source File: LensAPI.java    From cognition with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for creating the spark context from the given cognition configuration
 * @return a new configured spark context
 */
public SparkContext createSparkContext() {
  SparkConf conf = new SparkConf();

  Configuration config = cognition.getProperties();

  conf.set("spark.serializer", KryoSerializer.class.getName());
  conf.setAppName(config.getString("app.name"));
  conf.setMaster(config.getString("master"));

  Iterator<String> iterator = config.getKeys("spark");
  while (iterator.hasNext()) {
    String key = iterator.next();
    conf.set(key, config.getString(key));
  }

  SparkContext sc = new SparkContext(conf);
  for (String jar : config.getStringArray("jars")) {
    sc.addJar(jar);
  }

  return sc;
}
 
Example 5
Source File: JSONEncoderHelper.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
@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);
		}
	}
	return output;
}
 
Example 6
Source File: ConfUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into
 * target configuration <i>targetConf</i>.
 *
 * @param targetConf
 *          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));
        }
    }
}
 
Example 7
Source File: DatabaseJobHistoryStoreSchemaManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
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));
    }
    return props;
}
 
Example 8
Source File: GenericExternalProcess.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private static Map<String, String> addResultParamaters(Configuration conf,
        String processorId, Map<String, String> result) {

    for (Iterator<String> it = conf.getKeys("param"); it.hasNext();) {
        String param = it.next();
        String value = interpolateParameters(conf.getString(param), result);
        String resultName = processorId == null ? param : processorId + '.' + param;
        result.put(resultName, value);
    }
    return result;
}
 
Example 9
Source File: ApplicationProperties.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private static void logConfiguration(Configuration configuration) {
    if (LOG.isDebugEnabled()) {
        Iterator<String> keys = configuration.getKeys();
        LOG.debug("Configuration loaded:");
        while (keys.hasNext()) {
            String key = keys.next();
            LOG.debug("{} = {}", key, configuration.getProperty(key));
        }
    }
}
 
Example 10
Source File: DefaultJBakeConfiguration.java    From jbake with MIT License 5 votes vote down vote up
@Override
public List<String> getAsciidoctorOptionKeys() {
    List<String> options = new ArrayList<>();
    Configuration subConfig = compositeConfiguration.subset(JBakeProperty.ASCIIDOCTOR_OPTION);

    Iterator<String> iterator = subConfig.getKeys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        options.add(key);
    }

    return options;
}
 
Example 11
Source File: ConfigurationUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void logConfigurationState(Configuration c, Logger logger, Level logLevel) {
    Iterator<String> configKeys = c.getKeys();
    while (configKeys.hasNext()) {
        String k = configKeys.next();
        logger.log(logLevel, String.format("Configuration: %s: %s", k, c.getProperty(k)));
    }
}
 
Example 12
Source File: ConfUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into
 * target configuration <i>targetConf</i>.
 *
 * @param targetConf
 *          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));
        }
    }
}
 
Example 13
Source File: DefaultRestClient.java    From qaf with MIT License 5 votes vote down vote up
@Override
protected Client createClient() {
	Configuration props = getBundle().subset(REST_CLIENT_PROP_PREFIX);
	Iterator<?> iter = props.getKeys();

	while (iter.hasNext()) {
		String prop = (String) iter.next();
		client.getProperties().put(REST_CLIENT_PROP_PREFIX + prop,
				props.getString(prop));
	}
	return client;
}
 
Example 14
Source File: LoggerConfigurationWriter.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Configuration configuration, Filter filter) {
    if (!logger.isDebugEnabled()) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("Configuring service with configuration properties:");
    Iterator<String> keys = configuration.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        sb.append("\n    ").append(key).append("=").append(configuration.getProperty(key));
    }
    logger.debug(sb.toString());
}
 
Example 15
Source File: ConfigUtils.java    From IGUANA with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param config
 * @param suffix
 * @return
 */
public static String[] getStringArrayWithSuffix(Configuration config, String suffix) {
	Iterator<String> keySet = config.getKeys();
	while(keySet.hasNext()) {
		String key = keySet.next();
		if(key.endsWith(suffix)) {
			return config.getStringArray(key);
		}
	}
	return null;
}
 
Example 16
Source File: IguanaConfig.java    From IGUANA with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void addRecursive(Configuration target, Configuration source, String key) {
	Iterator<String> keys2 = source.getKeys(key);
	while(keys2.hasNext()) {
		String key2 = keys2.next();
		target.addProperty(key2, source.getProperty(key2));
		for(String tmpKey : source.getStringArray(key2)) {
			addRecursive(target, source, tmpKey);
		}
	}
}
 
Example 17
Source File: ConfigurationHelperTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the actual configuration contains the expected ones.
 */
private static void assertContains(Configuration expected, Configuration actual) {
  @SuppressWarnings("rawtypes")
  Iterator keys = expected.getKeys();
  while (keys.hasNext()) {
    String key = (String) keys.next();
    assertPropertyEquals(key, expected.getString(key), actual.getString(key));
  }
}
 
Example 18
Source File: ConfigurationHelperTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the configuration matches the properties and that they have
 * the same number of entries. If the value for a key contains the list delimiter
 * then this method will only confirm that the <em>first</em> value in the delimited
 * list matches the key's value in <code>properties</code>.
 */
private static void assertPropertiesEquals(Map<String, String> properties,
    Configuration configuration) {
  int count = 0;
  @SuppressWarnings("rawtypes")
  Iterator keys = configuration.getKeys();
  while (keys.hasNext()) {
    String key = (String) keys.next();
    assertPropertyEquals(key, properties.get(key), configuration.getString(key));
    count++;
  }
  assertEquals("Configuration does not have the same number of properties",
      properties.size(), count);
}
 
Example 19
Source File: HugeConfig.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
public HugeConfig(Configuration config) {
    if (config == null) {
        throw new ConfigException("The config object is null");
    }

    this.reloadIfNeed(config);

    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        this.addProperty(key, config.getProperty(key));
    }
    this.checkRequiredOptions();
}
 
Example 20
Source File: LogConfigUtils.java    From singer with Apache License 2.0 5 votes vote down vote up
/**
 * validates the datapipelines.properties configuration
 *
 * @throws ConfigurationException if any topics are in the topic_names
 *                                declaration at the top of the config, but do
 *                                not have any settings for it or vice-versa
 */
public static void validateNewConfig(Configuration config) throws ConfigurationException {
  // get topic names from declaration in config
  String topicNamesString = config.getString(SingerConfigDef.TOPIC_NAMES);
  String[] topicNames = topicNamesString.isEmpty() ? new String[0]
      : topicNamesString.split("[,\\s]+");
  HashSet<String> topicsFromDeclaration = new HashSet<>(Arrays.asList(topicNames));

  // get topic names referenced by any setting
  HashSet<String> topicsFromSettings = new HashSet<>();
  for (Iterator<String> it = config.getKeys(); it.hasNext();) {
    // setting keys are in the form `topic_name.<a>.<b>`
    String settingKey = it.next();
    String topicName = settingKey.split("\\.")[0];

    // these are not settings
    if (topicName.equals("topic_names") || topicName.equals("merced")
        || topicName.equals("singer") || topicName.isEmpty()) {
      continue;
    }
    topicsFromSettings.add(topicName);
  }

  // determine which topics are in the declaration, but not in settings or
  // vice-versa. this is done with an XOR
  HashSet<String> errorTopics = new HashSet<>();
  errorTopics.addAll(topicsFromDeclaration);
  errorTopics.addAll(topicsFromSettings);
  topicsFromDeclaration.retainAll(topicsFromSettings);
  errorTopics.removeAll(topicsFromDeclaration);

  if (!errorTopics.isEmpty()) {
    throw new ConfigurationException(
        String.format("Following topics are not properly defined in %s: %s",
            DirectorySingerConfigurator.DATAPIPELINES_CONFIG, String.join(", ", errorTopics)));
  }
}