Example usage for org.apache.commons.configuration Configuration getList

List of usage examples for org.apache.commons.configuration Configuration getList

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getList.

Prototype

List getList(String key);

Source Link

Document

Get a List of strings associated with the given configuration key.

Usage

From source file:com.bluescopesteel.foldermonitor.FolderMonitorMain.java

public static void main(String[] args) {
    log.info("Starting Folder Monitor....");

    Configuration config = ConfigManager.getConfig();
    List<Object> folders = config.getList("monitor.folders");

    for (Object object : folders) {
        String path = (String) object;
        log.info("Creating folder monitor for path " + path);
    }/*from   w  w  w.j a  v a2 s  .  c o m*/

}

From source file:com.discursive.jccook.configuration.AdditionalXmlConfigurationExample.java

public static void main(String[] args) throws Exception {
    AdditionalXmlConfigurationExample example = new AdditionalXmlConfigurationExample();

    ConfigurationFactory factory = new ConfigurationFactory();
    URL configURL = example.getClass().getResource("additional-xml-configuration.xml");
    factory.setConfigurationURL(configURL);

    Configuration config = factory.getConfiguration();

    List startCriteria = config.getList("start-criteria.criteria");
    System.out.println("Start Criteria: " + startCriteria);

    int horsepower = config.getInt("horsepower");
    System.out.println("Horsepower: " + horsepower);
}

From source file:com.discursive.jccook.configuration.TypedConfigurationExample.java

public static void main(String[] args) throws Exception {
    Configuration config = new PropertiesConfiguration("test.properties");

    System.out.println("Speed: " + config.getFloat("speed"));
    System.out.println("Names: " + config.getList("names"));
    System.out.println("Correct: " + config.getBoolean("correct"));
}

From source file:com.discursive.jccook.configuration.XmlConfigurationExample.java

public static void main(String[] args) throws Exception {
    String resource = "com/discursive/jccook/configuration/global.xml";
    Configuration config = new XMLConfiguration(resource);
    /* //from w w w  .jav a 2  s .c o m
     * ========================================================================
     * 
     * Copyright 2005 Tim O'Brien.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     * 
     *   http://www.apache.org/licenses/LICENSE-2.0
     * 
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * 
     * ========================================================================
     */

    List startCriteria = config.getList("start-criteria.criteria");
    int horsepower = config.getInt("horsepower");
}

From source file:com.murdock.tools.distinct.util.AutoConfigUtils.java

/**
 * jakartaconfigurationxmlauto-config.xml
 * /*  w  ww  .  java2  s . c o m*/
 * @param file
 * @return
 */
@SuppressWarnings("unchecked")
public static final List<String> getAutoConfigKeyNames(File file) {
    if (file == null || !file.exists()) {
        throw new IllegalArgumentException();
    }

    try {
        Configuration configuration = new XMLConfiguration(file);

        return configuration.getList("group.property[@name]");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.gs.obevo.db.apps.reveng.DbMergeInfo.java

public static MutableCollection<DbMergeInfo> parseFromProperties(Configuration config) {
    Set<String> dbs = new HashSet<String>(config.getList("instances"));

    MutableList<DbMergeInfo> dbMergeInfos = Lists.mutable.empty();
    for (String db : dbs) {
        Configuration subset = config.subset(db);
        if (subset.containsKey("inputDir")) {
            File inputDir = new File(subset.getString("inputDir"));
            DbMergeInfo mergeInfo = new DbMergeInfo(db, inputDir);
            if (subset.containsKey("driverClassName")) {
                mergeInfo.setDriverClassName(subset.getString("driverClassName"));
                mergeInfo.setUrl(subset.getString("url"));
                mergeInfo.setUsername(subset.getString("username"));
                mergeInfo.setPassword(subset.getString("password"));
                mergeInfo.setPhysicalSchema(subset.getString("physicalSchema"));
            }//  www  . j a  v  a 2 s.  c o m

            dbMergeInfos.add(mergeInfo);
        }
    }

    return dbMergeInfos;
}

From source file:io.servicecomb.serviceregistry.config.ConfigurePropertyUtils.java

@SuppressWarnings("unchecked")
public static List<BasePath> getMicroservicePaths(Configuration configuration) {
    List<BasePath> basePaths = new ArrayList<>();
    for (Object path : configuration.getList("service_description.paths")) {
        BasePath basePath = new BasePath();
        Map<String, ?> pathMap = (Map<String, ?>) path;
        basePath.setPath(buildPath((String) pathMap.get("path")));
        basePath.setProperty((Map<String, String>) pathMap.get("property"));
        basePaths.add(basePath);//from   w w w  .  ja  v a 2 s.c om
    }
    return basePaths;
}

From source file:com.github.fengtan.sophie.beans.Config.java

/**
 * Add a Solr server to favorites listed in the properties file.
 * //  w  ww . j a v  a2 s  .c  o m
 * @param favorite
 *            The new favorite (either a Solr URL or a ZooKeeper host).
 */
public static void addFavorite(String favorite) {
    try {
        Configuration configuration = getConfiguration();
        List<Object> favorites = configuration.getList("favorites");
        // If the server is already listed in the favorites, then do
        // nothing.
        if (!favorites.contains(favorite)) {
            configuration.addProperty("favorites", favorite);
        }
    } catch (ConfigurationException e) {
        // Silently do not add the favorite and log the exception.
        Sophie.log.warn("Unable to add favorite to configuration file: " + favorite, e);
    }
}

From source file:com.boozallen.cognition.ingest.storm.util.ConfigurationMapEntryUtils.java

/**
 * Extracts Map&lt;String, String&gt; from XML of the format:
 * <pre>/*from w  ww  .  ja  v a2 s .c o m*/
 * {@code <mapName>
 *     <entry>
 *       <key>k0</key>
 *       <value>v0</value>
 *     </entry>
 *     <entry>
 *       <key>k1</key>
 *       <value>v1</value>
 *     </entry>
 *   </mapName>
 * }
 * </pre>
 *
 * @param conf
 * @param mapName
 * @param entry
 * @param key
 * @param value
 * @return
 */
public static Map<String, String> extractSimpleMap(final Configuration conf, final String mapName,
        final String entry, final String key, final String value) {
    List<Object> fieldsList = conf.getList(mapName + "." + entry + "." + key);
    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
    for (int i = 0; i < fieldsList.size(); i++) {
        String relevanceField = conf.getString(mapName + "." + entry + "(" + i + ")." + value);
        map.put(fieldsList.get(i).toString(), relevanceField);
    }
    return map;
}

From source file:com.boozallen.cognition.ingest.storm.util.ConfigurationMapEntryUtils.java

/**
 * Extracts map entries from configuration.
 *
 * @param conf//from ww  w  .  j ava  2s .  com
 * @param mappingEntry
 * @param fields       first field should be unique and exist in all entries, other fields are optional from map
 * @return
 */
public static Map<String, Map<String, String>> extractMapList(final Configuration conf,
        final String mappingEntry, final String... fields) {
    String keyField = fields[0];
    List<Object> keys = conf.getList(mappingEntry + "." + keyField);
    Map<String, Map<String, String>> maps = new HashMap<>(keys.size());

    for (int i = 0; i < keys.size(); i++) {
        Map<String, String> map = new HashMap<>();
        Object key = keys.get(i);
        map.put(keyField, key.toString());

        for (int j = 1; j < fields.length; j++) {
            String field = fields[j];
            String fieldPath = String.format("%s(%s).%s", mappingEntry, i, field);
            String value = conf.getString(fieldPath);
            if (value != null)
                map.put(field, value);
        }

        maps.put(key.toString(), map);
    }
    return maps;
}