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

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

Introduction

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

Prototype

boolean containsKey(String key);

Source Link

Document

Check if the configuration contains the specified key.

Usage

From source file:gda.jython.authoriser.FileAuthoriser.java

/**
 * Removes an entry from the file//w  w w . j  a v a  2s  . c  om
 * 
 * @param username
 */
public void deleteEntry(String username) {
    try {
        FileConfiguration configFile = openConfigFile();
        if (configFile.containsKey(username)) {
            configFile.clearProperty(username);
            configFile.save();
        }
    } catch (Exception e) {
        logger.error("Exception while trying to delete an entry from file" + e.getMessage());
    }
}

From source file:gda.jython.authoriser.FileAuthoriser.java

/**
 * Adds an entry to the file/*  ww  w.  j a  va  2  s  .c o m*/
 * 
 * @param username
 * @param newLevel
 * @param isStaff
 */
public void addEntry(String username, int newLevel, boolean isStaff) {
    try {
        FileConfiguration configFile = openConfigFile();
        if (!configFile.containsKey(username)) {
            configFile.setProperty(username, newLevel);
            configFile.save();
        }
        if (isStaff) {
            FileConfiguration configFile2 = openStaffFile();
            if (!configFile2.containsKey(username)) {
                configFile2.setProperty(username, newLevel);
                configFile2.save();
            }
        }
    } catch (Exception e) {
        logger.error("Exception while trying to write new entry to file of list of user authorisation levels:"
                + e.getMessage());
    }
}

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

@Test
public void shouldPersistDisabledExtensions() {
    // Given/*from w w  w.  j a va  2s.  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)));
}