Example usage for org.apache.commons.configuration FileConfiguration getBoolean

List of usage examples for org.apache.commons.configuration FileConfiguration getBoolean

Introduction

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

Prototype

boolean getBoolean(String key);

Source Link

Document

Get a boolean associated with the given configuration key.

Usage

From source file:gda.util.userOptions.UserOptions.java

public static UserOptions createFromTemplate(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, false, true);
    UserOptions options = new UserOptions();
    options.title = config.getString(propTitle);
    options.containsDefault = true;/*from w  ww. j  a  va  2  s . c  o m*/
    Integer index = 0;
    while (true) {
        String tag = "options.option(" + index + ").";
        Object description = null;
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            description = config.getProperty(tag + propDesc);
            Object type = config.getProperty(tag + propType);
            UserOption<? extends Object, ? extends Object> option;
            if (type != null && type.equals(typeBoolean)) {
                option = new UserOption<Object, Boolean>(description, config.getBoolean(tag + propDefValue));
            } else if (type != null && type.equals(typeString)) {
                option = new UserOption<Object, String>(description, config.getString(tag + propDefValue));
            } else if (type != null && type.equals(typeDouble)) {
                option = new UserOption<Object, Double>(description, config.getDouble(tag + propDefValue));
            } else if (type != null && type.equals(typeInteger)) {
                option = new UserOption<Object, Integer>(description, config.getInt(tag + propDefValue));
            } else {
                option = new UserOption<Object, Object>(description, config.getProperty(tag + propDefValue));
            }
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option " + index, ex);
        }
    }
    return options;
}

From source file:org.zaproxy.zap.extension.ext.ExtensionParamUnitTest.java

@Test
public void shouldPersistDisabledExtensions() {
    // Given// w w w . j a  v  a 2  s  .  co m
    ExtensionParam param = new ExtensionParam();
    FileConfiguration config = createTestConfig();
    param.load(config);
    Map<String, Boolean> states = extensionsState(true, false, true, false, true, true);
    // When
    param.setExtensionsState(states);
    // Then
    assertThat(config.getString("extensions.extension(0).name"), is(equalTo("Extension 2")));
    assertThat(config.getBoolean("extensions.extension(0).enabled"), is(equalTo(false)));
    assertThat(config.getString("extensions.extension(1).name"), is(equalTo("Extension 4")));
    assertThat(config.getBoolean("extensions.extension(1).enabled"), is(equalTo(false)));
    assertThat(config.containsKey("extensions.extension(2).name"), is(equalTo(false)));
    assertThat(config.containsKey("extensions.extension(2).enabled"), is(equalTo(false)));
}