Example usage for org.apache.commons.configuration2 PropertiesConfiguration getInt

List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration2 PropertiesConfiguration getInt.

Prototype

@Override
    public int getInt(final String key) 

Source Link

Usage

From source file:com.smartmarmot.dbforbix.config.Config.java

/**
 * Reads the configuration from a properties file
 * //w w  w . ja va  2  s .  co m
 * @throws IOException
 */
public void readFileConfig() throws IOException, NullPointerException {
    LOG.debug("Parsing config file: " + configFile);
    calculateFileConfigHash();
    try (FileReader reader = new FileReader(configFile)) {
        PropertiesConfiguration pcfg = new PropertiesConfiguration();
        pcfg.read(reader);
        if (pcfg.containsKey(SET_PERSISTENCETYPE))
            persistenceType = pcfg.getString(SET_PERSISTENCETYPE);
        if (pcfg.containsKey(SET_PERSISTENCEDIR))
            persistenceDir = pcfg.getString(SET_PERSISTENCEDIR);
        if (pcfg.containsKey(SET_UPDATECONFIG))
            setUpdateConfigTimeout(pcfg.getInt(SET_UPDATECONFIG));
        if (pcfg.containsKey(SET_POOL_MAXACTIVE))
            maxActive = pcfg.getInt(SET_POOL_MAXACTIVE);
        if (pcfg.containsKey(SET_POOL_MAXIDLE))
            maxIdle = pcfg.getInt(SET_POOL_MAXIDLE);
        if (pcfg.containsKey(SET_LOGIN_TIMEOUT))
            loginTimeout = Integer.parseInt(pcfg.getString(SET_LOGIN_TIMEOUT));
        Iterator<?> it;
        it = pcfg.getKeys(GLOBAL_ZBXSRV);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigZSRV(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }
        it = pcfg.getKeys(GLOBAL_DB);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigDB(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }

    } catch (ConfigurationException e) {
        throw new IOException("Error in configuration: " + e.getLocalizedMessage(), e);
    }
}

From source file:com.sikulix.core.SX.java

private static void setOptions(PropertiesConfiguration someOptions) {
    if (isNull(someOptions) || someOptions.size() == 0) {
        return;//from  ww w.ja  va  2 s.c  om
    }
    Iterator<String> allKeys = someOptions.getKeys();
    List<String> sxSettings = new ArrayList<>();
    while (allKeys.hasNext()) {
        String key = allKeys.next();
        if (key.startsWith("Settings.")) {
            sxSettings.add(key);
            continue;
        }
        trace("!setOptions: %s = %s", key, someOptions.getProperty(key));
    }
    if (sxSettings.size() > 0) {
        Class cClass = null;
        try {
            cClass = Class.forName("org.sikuli.basics.Settings");
        } catch (ClassNotFoundException e) {
            error("!setOptions: %s", cClass);
        }
        if (!isNull(cClass)) {
            for (String sKey : sxSettings) {
                String sAttr = sKey.substring("Settings.".length());
                Field cField = null;
                Class ccField = null;
                try {
                    cField = cClass.getField(sAttr);
                    ccField = cField.getType();
                    if (ccField.getName() == "boolean") {
                        cField.setBoolean(null, someOptions.getBoolean(sKey));
                    } else if (ccField.getName() == "int") {
                        cField.setInt(null, someOptions.getInt(sKey));
                    } else if (ccField.getName() == "float") {
                        cField.setFloat(null, someOptions.getFloat(sKey));
                    } else if (ccField.getName() == "double") {
                        cField.setDouble(null, someOptions.getDouble(sKey));
                    } else if (ccField.getName() == "String") {
                        cField.set(null, someOptions.getString(sKey));
                    }
                    trace("!setOptions: %s = %s", sAttr, someOptions.getProperty(sKey));
                    someOptions.clearProperty(sKey);
                } catch (Exception ex) {
                    error("!setOptions: %s = %s", sKey, sxOptions.getProperty(sKey));
                }
            }
        }
    }
}