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

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

Introduction

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

Prototype

public HierarchicalINIConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Create and load the ini configuration from the given url.

Usage

From source file:it.jnrpe.server.IniJNRPEConfiguration.java

@Override
public void load(final File confFile) throws ConfigurationException {
    // Parse an ini file
    ServerSection serverConf = getServerSection();
    CommandsSection commandSection = getCommandSection();
    try {/*from  w w w .  jav a  2  s . c o m*/
        HierarchicalINIConfiguration confParser = new HierarchicalINIConfiguration(confFile);

        List<Object> vBindAddresses = confParser.getList("server.bind-address");
        if (vBindAddresses != null) {
            for (Object address : vBindAddresses) {
                serverConf.addBindAddress((String) address);
            }
        }

        // Defaults accept params
        String sAcceptParams = confParser.getString("server.accept-params", "true");
        serverConf.setAcceptParams(
                "true".equalsIgnoreCase(sAcceptParams) || "yes".equalsIgnoreCase(sAcceptParams));
        serverConf.setPluginPath(confParser.getString("server.plugin-path", "."));

        serverConf.setBackLogSize(confParser.getInt("server.backlog-size", ServerSection.DEFAULT_BACKLOG));

        // TODO : move this to publicly accessible constants
        serverConf.setReadTimeout(confParser.getInteger("server.read-timeout", 10));
        // TODO : move this to publicly accessible constants
        serverConf.setWriteTimeout(confParser.getInteger("server.write-timeout", 60));

        List<Object> vAllowedAddresses = confParser.getList("server.allow-address");
        if (vAllowedAddresses != null) {
            for (Object address : vAllowedAddresses) {
                serverConf.addAllowedAddress((String) address);
            }
        }

        SubnodeConfiguration sc = confParser.getSection("commands");

        if (sc != null) {
            for (Iterator<String> it = sc.getKeys(); it.hasNext();) {
                String sCommandName = it.next();

                String sCommandLine = org.apache.commons.lang.StringUtils.join(sc.getStringArray(sCommandName),
                        ",");
                // first element of the command line is the plugin name

                String[] vElements = StringUtils.split(sCommandLine, false);
                String sPluginName = vElements[0];

                // Rebuilding the commandline
                StringBuilder cmdLine = new StringBuilder();

                for (int i = 1; i < vElements.length; i++) {
                    cmdLine.append(quoteAndEscape(vElements[i])).append(' ');
                }

                commandSection.addCommand(sCommandName, sPluginName, cmdLine.toString());
            }
        }
    } catch (org.apache.commons.configuration.ConfigurationException e) {
        throw new ConfigurationException(e);
    }

}

From source file:info.pancancer.arch3.utils.Utilities.java

public static HierarchicalINIConfiguration parseConfig(String path) {
    try {//ww  w. ja  va  2s .  c o m
        HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(path);
        return config;
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }
}

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

/**
 * This method parses a repository configuration from the file at the given
 * absolute path./*  w w w . ja v a 2s . c  o  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.yfiton.core.YfitonBuilder.java

public Yfiton build() throws ConversionException, ConfigurationException {
    Notifier notifier = this.notifier;

    if (notifier == null) {
        notifier = resolve(this.notifierKey);
    }// w w w.  j  a  v  a2 s . c  o m

    if (configurationFile == null) {
        try {
            configurationFile = Configuration.getNotifierConfigurationFilePath(notifier.getKey());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    HierarchicalINIConfiguration hierarchicalConfiguration = new HierarchicalINIConfiguration(
            configurationFile.toFile());

    return new Yfiton(notifier, hierarchicalConfiguration, displayStackTraces);
}

From source file:io.dockstore.common.FileProvisioning.java

/**
 * Constructor/*from  www . j  a  va2  s.c  o  m*/
 */
public FileProvisioning(String configFile) {
    // do not forward stdout and stderr
    stdoutStream = Optional.absent();
    stderrStream = Optional.absent();

    try {
        this.config = new HierarchicalINIConfiguration(configFile);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:ee.ria.xroad.confproxy.ConfProxyProperties.java

/**
 * Constructs the configuration for the given
 * configuration proxy instance id./* w  w w.  j  av  a2  s.c o  m*/
 * @param name the if of the configuration proxy instance
 * @throws ConfigurationException if the configuration could not be loaded
 */
public ConfProxyProperties(final String name) throws ConfigurationException {
    this.instance = name;
    String confDir = SystemProperties.getConfigurationProxyConfPath();
    File configFile = Paths.get(confDir, instance, CONF_INI).toFile();
    if (!configFile.exists()) {
        throw new ConfigurationException("'" + CONF_INI + "' does not exist.");
    }
    try {
        config = new HierarchicalINIConfiguration(configFile);
    } catch (ConfigurationException e) {
        log.error("Failed to load '{}': {}", configFile, e.getMessage());
        throw e;
    }
}

From source file:com.strandls.alchemy.inject.AlchemyModuleFilterConfiguration.java

/**
 * @return configuration read from the config file.
 *//*w  w  w  .  jav  a  2s  . c  om*/
private Configuration readConfiguration() {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new HierarchicalINIConfiguration(MODULE_CONFIGURATION_NAME));
    } catch (final ConfigurationException e) {
        // ignore if the configuration file is missing. This means no
        // filtering intended.
        log.warn("Error loading configuration file {}", e);
    }
    return config;
}

From source file:edu.stolaf.cs.wmrserver.JobServiceHandler.java

public JobServiceHandler(Configuration conf) throws IOException {
    _homeDir = getHome(conf);/*  w  ww. ja v a 2s . c  o m*/
    _tempDir = getTempDir(conf);
    _langSupportDir = new File(conf.get("wmr.lang.support.dir", "lang-support"));
    _enforceInputContainment = conf.getBoolean("wmr.input.containment.enforce", false);
    _disallowLocalInput = conf.getBoolean("wmr.input.disallow.local", true);
    _outputPageSize = getOutputPageSize(conf);
    _quotaEnabled = conf.getBoolean("wmr.quota.enable", true) && conf.getBoolean("wmr.quota.user.enable", true);
    _quotaAttempts = conf.getInt("wmr.quota.user.attempts", 20);
    _quotaDuration = conf.getInt("wmr.quota.user.duration", 10);

    // Resolve relative lang support dir
    if (!_langSupportDir.isAbsolute())
        _langSupportDir = new File(System.getProperty("wmr.home.dir"), _langSupportDir.toString());

    // Load language configuration
    File wmrConfFile = new File(_langSupportDir, LANG_CONF_FILE);
    if (!wmrConfFile.exists())
        throw new IOException("Language configuration could not be found: " + wmrConfFile.toString());
    try {
        _languageConf = new HierarchicalINIConfiguration(wmrConfFile);
    } catch (ConfigurationException ex) {
        throw new IOException("The language configuration could not be loaded.", ex);
    }

    _hadoopEngine = new HadoopEngine(conf);
    _testJobEngine = new TestJobEngine(conf);
}

From source file:edu.cwru.sepia.Main.java

private static HierarchicalConfiguration getConfiguration(String filename) throws ConfigurationException {
    HierarchicalConfiguration configuration = null;
    try {//www .j a v  a2s . c  om
        configuration = new XMLConfiguration(new File(filename));
    } catch (Exception ex) {
    }
    if (configuration == null || configuration.isEmpty()) {
        try {
            configuration = new HierarchicalINIConfiguration(new File(filename));
        } catch (Exception ex) {
        }
    }
    if (configuration == null)
        throw new ConfigurationException("Unable to load configuration file as XML, or INI.");
    return configuration;
}

From source file:fr.in2p3.cc.storage.treqs.tools.Configurator.java

/**
 * Constructor of the configurator where it defines the name of the
 * configuration file.//from w ww.j  av  a2 s .c om
 *
 * @throws ProblematicConfiguationFileException
 *             If there is a problem reading the configuration file.
 */
private Configurator() throws ProblematicConfiguationFileException {
    LOGGER.trace("> Create instance");

    this.properties = new CompositeConfiguration();
    String name = null;
    this.properties.addConfiguration(new SystemConfiguration());
    try {
        name = System.getProperty(Constants.CONFIGURATION_FILE);
        if (name == null) {
            name = DefaultProperties.CONFIGURATION_PROPERTIES;
            LOGGER.debug("No given file in System property");
        }
        // TODO v2.0 Try to show the complete path of the configuration
        // file to use in a logger. This permits to know which is being used
        this.properties.addConfiguration(new HierarchicalINIConfiguration(name));
    } catch (final ConfigurationException e) {
        throw new ProblematicConfiguationFileException(name, e);
    }

    LOGGER.trace("< Create instance");
}