Example usage for org.apache.commons.configuration HierarchicalINIConfiguration getSection

List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration getSection

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalINIConfiguration getSection.

Prototype

public SubnodeConfiguration getSection(String name) 

Source Link

Document

Returns a configuration with the content of the specified section.

Usage

From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java

private static void reload(String fileName) throws Exception {
    log.trace("Loading module configuration from '{}'", fileName);

    MODULES.clear();/*  w w w .jav  a 2 s .  com*/
    MODULES.put(SoftwareModuleType.TYPE, new SoftwareModuleType());

    HierarchicalINIConfiguration conf = new HierarchicalINIConfiguration(fileName);

    for (String uid : conf.getSections()) {
        if (StringUtils.isBlank(uid)) {
            log.error("No UID specified for module, skipping...");

            continue;
        }

        try {
            parseSection(uid, conf.getSection(uid));
        } catch (ConfigurationRuntimeException e) {
            log.error("Parse section failed with", e);
        }
    }
}

From source file:de.clusteval.framework.repository.config.RepositoryConfig.java

/**
 * This method parses a repository configuration from the file at the given
 * absolute path./*www .ja v a2 s.co m*/
 * 
 * <p>
 * A repository configuration contains several sections and possible
 * options:
 * <ul>
 * <li><b>[mysql]</b></li>
 * <ul>
 * <li><b>host</b>: The ip address of the mysql host server.</li>
 * <li><b>database</b>: The mysql database name.</li>
 * <li><b>user</b>: The username used to connect to the database.</li>
 * <li><b>password</b>: The mysql password used to connect to the database.
 * The password is prompted from the console and not parsed from the file.</li>
 * </ul>
 * <li><b>[threading]</b></li>
 * <li><b>NameOfTheThreadSleepTime</b>: Sleeping time of the thread
 * 'NameOfTheThread'. This option can be used to control the frequency, with
 * which the threads check for changes on the filesystem.</li> </ul>
 * 
 * @param absConfigPath
 *            The absolute path of the repository configuration file.
 * @return The parsed repository configuration.
 * @throws RepositoryConfigNotFoundException
 * @throws RepositoryConfigurationException
 */
public static RepositoryConfig parseFromFile(final File absConfigPath)
        throws RepositoryConfigNotFoundException, RepositoryConfigurationException {
    if (!absConfigPath.exists())
        throw new RepositoryConfigNotFoundException(
                "Repository config \"" + absConfigPath + "\" does not exist!");

    Logger log = LoggerFactory.getLogger(RepositoryConfig.class);

    log.debug("Parsing repository config \"" + absConfigPath + "\"");

    try {

        HierarchicalINIConfiguration props = new HierarchicalINIConfiguration(absConfigPath);
        props.setThrowExceptionOnMissing(true);

        boolean usesMysql = false;
        MysqlConfig mysqlConfig = null;

        if (props.getSections().contains("mysql")
                && !ClustevalBackendServer.getBackendServerConfiguration().getNoDatabase()) {
            usesMysql = true;
            String mysqlUsername, mysqlDatabase, mysqlHost;
            SubnodeConfiguration mysql = props.getSection("mysql");
            mysqlUsername = mysql.getString("user");

            mysqlDatabase = mysql.getString("database");
            mysqlHost = mysql.getString("host");
            mysqlConfig = new MysqlConfig(usesMysql, mysqlUsername, mysqlDatabase, mysqlHost);
        } else
            mysqlConfig = new MysqlConfig(usesMysql, "", "", "");

        Map<String, Long> threadingSleepTimes = new HashMap<String, Long>();

        if (props.getSections().contains("threading")) {
            SubnodeConfiguration threading = props.getSection("threading");
            Iterator<String> it = threading.getKeys();
            while (it.hasNext()) {
                String key = it.next();
                if (key.endsWith("SleepTime")) {
                    String subKey = key.substring(0, key.indexOf("SleepTime"));
                    try {
                        threadingSleepTimes.put(subKey, threading.getLong(key));
                    } catch (Exception e) {
                        // in case anything goes wrong, we just ignore this
                        // option
                        e.printStackTrace();
                    }
                }
            }
        }

        return new RepositoryConfig(mysqlConfig, threadingSleepTimes);
    } catch (ConfigurationException e) {
        throw new RepositoryConfigurationException(e.getMessage());
    } catch (NoSuchElementException e) {
        throw new RepositoryConfigurationException(e.getMessage());
    }
}

From source file:com.hipstogram.storm.context.config.Config.java

public Config(File configFile, File... otherConfigFile) throws ConfigurationException {
    HierarchicalINIConfiguration iniConfig = new HierarchicalINIConfiguration(configFile);
    this.kafkaSection = new KafkaSection(iniConfig.getSection("kafka"));
    this.zookeeperSection = new ZookeeperSection(iniConfig.getSection("zookeeper"));
}

From source file:com.hipstogram.context.config.Config.java

public Config(File configFile, File... otherConfigFile) throws ConfigurationException {
    HierarchicalINIConfiguration iniConfig = new HierarchicalINIConfiguration(configFile);
    this.kafkaSection = new KafkaSection(iniConfig.getSection("kafka"));
    this.serverSection = new ServerSection(iniConfig.getSection("server"));
    this.zookeeperSection = new ZookeeperSection(iniConfig.getSection("zookeeper"));
    this.cassandraSection = new CassandraSection(iniConfig.getSection("cassandra"));
    this.mongoSection = new MongoDBSection(iniConfig.getSection("mongodb"));
}

From source file:com.bist.elasticsearch.jetty.security.AuthorizationConfigurationLoader.java

protected QueryConstraints loadIni(HierarchicalINIConfiguration iniConfiguration,
        QueryConstraints queryConstraints) {
    for (String section : iniConfiguration.getSections()) {
        SubnodeConfiguration subnodeConfiguration = iniConfiguration.getSection(section);
        switch (section) {
        case "Public":
            for (String query : subnodeConfiguration.getStringArray("Queries")) {
                queryConstraints.addPublicQuery(query);
            }//from   ww  w.  j  a  v a 2s  .  com
            break;
        case "Authenticated":
            for (String query : subnodeConfiguration.getStringArray("Queries")) {
                queryConstraints.addAuthenticatedQuery(query);
            }
            break;
        default:
            loadIndiceAuthZ(queryConstraints, section, subnodeConfiguration);
            break;
        }
    }
    { // make it atomic
        return queryConstraints;

    }
}

From source file:iddb.web.security.SecurityConfig.java

private SecurityConfig() {
    try {//from w w w  . j  av a  2s .  c  om
        HierarchicalINIConfiguration configFile = new HierarchicalINIConfiguration(
                this.getClass().getClassLoader().getResource("security.properties"));
        for (Object section : configFile.getSections()) {
            SubnodeConfiguration node = configFile.getSection((String) section);
            Map<String, String> map = new LinkedHashMap<String, String>();
            for (@SuppressWarnings("unchecked")
            Iterator<Object> it = node.getKeys(); it.hasNext();) {
                String key = it.next().toString();
                if (log.isTraceEnabled()) {
                    log.trace("Loading '{}' with value '{}' on section '{}'",
                            new String[] { key, node.getString(key), section.toString() });
                }
                map.put(key, node.getString(key));
            }
            config.put(section.toString(), map);
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage());
    }
}

From source file:com.baasbox.db.DbHelper.java

public static void populateConfiguration() throws IOException, ConfigurationException {
    BaasBoxLogger.info("Load initial configuration...");
    InputStream is;//from   www .j a v  a  2s  .c o m
    if (Play.application().isProd())
        is = Play.application().resourceAsStream(CONFIGURATION_FILE_NAME);
    else
        is = new FileInputStream(Play.application().getFile("conf/" + CONFIGURATION_FILE_NAME));
    HierarchicalINIConfiguration c = new HierarchicalINIConfiguration();
    c.setEncoding("UTF-8");
    c.load(is);
    CharSequence doubleDot = "..";
    CharSequence dot = ".";

    Set<String> sections = c.getSections();
    for (String section : sections) {
        Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section);
        if (en == null) {
            BaasBoxLogger.warn(section + " is not a valid configuration section, it will be skipped!");
            continue;
        }
        SubnodeConfiguration subConf = c.getSection(section);
        Iterator<String> it = subConf.getKeys();
        while (it.hasNext()) {
            String key = (it.next());
            Object value = subConf.getString(key);
            key = key.replace(doubleDot, dot);//bug on the Apache library: if the key contain a dot, it will be doubled!
            try {
                BaasBoxLogger.info("Setting " + value + " to " + key);
                PropertiesConfigurationHelper.setByKey(en, key, value);
            } catch (Exception e) {
                BaasBoxLogger.warn("Error loading initial configuration: Section " + section + ", key: " + key
                        + ", value: " + value, e);
            }
        }
    }
    is.close();
    BaasBoxLogger.info("...done");
}

From source file:com.yfiton.notifiers.slack.SlackNotifier.java

@Override
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration)
        throws NotificationException {
    String teamId = accessTokenData.get("teamId");
    configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId);

    SubnodeConfiguration section = configuration.getSection(teamId);

    section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());
    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        section.setProperty(entry.getKey(), entry.getValue());
    }/*from ww  w  .  j  a v  a 2s.c  o  m*/

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}

From source file:eu.itesla_project.dymola.DymolaAdaptersMatParamsWriter.java

public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration) {
    if (configuration == null) {
        throw new RuntimeException("null config");
    }/*from  w  ww. ja  v  a2  s .  c  om*/
    this.configuration = configuration;
    //this below will simply log parameters ..
    for (String section : configuration.getSections()) {
        SubnodeConfiguration node = configuration.getSection(section);
        List<String> paramsSummary = StreamSupport
                .stream(Spliterators.spliteratorUnknownSize(node.getKeys(), Spliterator.ORDERED), false)
                .map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList());
        LOGGER.info("index {}: {}", section, paramsSummary);
    }
}

From source file:com.yfiton.core.Yfiton.java

private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration,
        Notifier notifier) {//from  www .java 2s. c o  m
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}