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

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

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string 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 w  w .j a v a 2  s  .co 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:net.sourceforge.jukebox.model.Settings.java

/**
 * Load the contents of the configuration file.
 * @param configuration Configuration file
 */// w  w w.  ja va 2  s.  c  o m
public final void load(final FileConfiguration configuration) {
    this.contentFolder = configuration.getString(CONTENT_FOLDER);
    this.playerUrl = configuration.getString(PLAYER_URL);
    this.modifiedDays = configuration.getInt(MODIFIED_DAYS, DEFAULT_MODIFIED_DAYS);
}

From source file:gda.data.metadata.PersistantMetadataEntry.java

synchronized private FileConfiguration openConfig() throws ConfigurationException, IOException {
    // if (config == null) {
    FileConfiguration config = LocalParameters.getXMLConfiguration("persistantMetadata");
    config.reload();/* w ww  . j a v  a  2 s .  co m*/
    if (config.getString(getName()) == null) {
        logger.warn("No saved entry found for PersistantMetadataEntry named: '" + getName()
                + "'. Setting it to: '" + getDefaultValue() + "'");
        // setValue(getDefaultValue());
        config.setProperty(getName(), getDefaultValue());
        config.save();
        notifyIObservers(this, getDefaultValue());
    }
    // }
    return config;
}

From source file:net.sourceforge.jukebox.model.Profile.java

/**
 * Load the contents of the configuration file.
 * @param configuration Configuration file
 *///from  ww  w .j a  v a 2  s. c  o m
public final void load(final FileConfiguration configuration) {
    String value = configuration.getString(ADMIN_USERNAME);
    int passwordLength = value.indexOf(',');
    this.oldPassword = value.substring(0, passwordLength);
    this.userInfo = value.substring(passwordLength + 1);
}

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

private Map<String, Object> getOptionValuesFromConfig(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, true, true);
    Map<String, Object> options = new HashMap<String, Object>();
    Integer index = 0;//from  w  w w .  j  ava 2  s .c o  m
    while (true) {
        String tag = "options.option(" + index + ").";
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            Object option = config.getProperty(tag + propValue);
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option.", ex);
        }
    }
    return options;
}

From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java

/**
 * Builds a configuration map from the given {@link FileConfiguration}. It is
 * assumed that the configuration contains of key with maximum nesting of
 * two levels. Each "topic" of parameters, i.e. parameters with the same
 * prefix, is stored in a map entry. The sub-keys configurations below the
 * topic parent represent the value to the key in form of a list of
 * key-value elements ({@link ConfigEntry}). If there is no nesting for a
 * configuration key the map key will be the original configuration key, the
 * value will be a {@link ConfigEntry} with again the property key as key
 * and the single value./*from  ww w. ja v a2s. co  m*/
 * 
 * @param config
 *            The configuration to process
 * @return The configuration map
 */
private SortedMap<String, List<ConfigEntry>> buildConfigurationMap(final FileConfiguration config) {

    SortedMap<String, List<ConfigEntry>> map = new TreeMap<String, List<ConfigEntry>>();

    Iterator<?> iter = config.getKeys();
    while (iter.hasNext()) {

        String key = iter.next().toString();
        // skip all attributes in our case these are the XML attributes
        if (!key.startsWith("[@")) {

            String[] parts = key.split("\\.");
            String value = config.getString(key);

            if (parts.length == 2) {

                String topic = parts[0];
                String subKey = parts[1];

                List<ConfigEntry> subKeysAndValues = map.get(topic);
                if (subKeysAndValues == null) {
                    subKeysAndValues = new ArrayList<ConfigEntry>();
                    map.put(topic, subKeysAndValues);
                }

                subKeysAndValues.add(new ConfigEntry(key, subKey, value));
            } else if (parts.length == 1) {

                map.put(key, Arrays.asList(new ConfigEntry(key, key, value)));
            } else {
                throw new IllegalStateException(
                        "Unexpected format of OpenLR properties. Nesting level was assumed to be at most 2 but was "
                                + parts.length);
            }
        }
    }
    return map;
}

From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java

/**
 * Sets the values in the input form according to the given configuration.
 * /*from w  w  w .  ja va  2 s.  c om*/
 * @param config
 *            The configuration that provides the values to display
 */
void setValues(final FileConfiguration config) {
    for (Map.Entry<String, JTextComponent> entry : optionsTextFields.entrySet()) {

        JTextComponent textComponent = entry.getValue();
        textComponent.setText(config.getString(entry.getKey()));
    }
}

From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java

/**
 * Creates a list of {@link AccessControlRule}s loaded from the
 * {@link FileConfiguration}./*from  w w w  .  j  a v  a2  s.  co  m*/
 * 
 * @param config
 *            The ACL FileConfiguration object
 * @return A {@link List} of {@link AccessControlRule}s
 */
static private List createACLAccessControlRules(FileConfiguration config) {
    List accessControlRules = new LinkedList();
    // list all rules
    int i = 0;
    while (true) {
        String rulePrefix = "AccessControlRule(" + i + ")";
        i++;
        // get the name and id of the rule
        String ruleGroup = config.getString(rulePrefix + "[@group]");
        if (ruleGroup == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(rulePrefix + ": no more rules");
            }
            // no more ACL rule to read, exit while loop
            break;
        }
        int ruleId = config.getInt(rulePrefix + "[@id]");
        // create an empty rule
        AccessControlRule rule = new AccessControlRule(ruleId, ruleGroup);
        // get the attributes name-value for the rule
        List attributeNames = config.getList(rulePrefix + ".Attribute[@name]");
        if (attributeNames.isEmpty()) {
            LOG.error(rulePrefix + ": no attribute in rule, skipping...");
            // error, skipping
            continue;
        }
        AttributeDefinitions attributeDefinitions = AttributeDefinitionsFactory.getInstance();
        List attributeValues = config.getList(rulePrefix + ".Attribute");
        for (int j = 0; j < attributeNames.size(); j++) {
            String name = (String) attributeNames.get(j);
            String value = (String) attributeValues.get(j);
            Attribute attribute = attributeDefinitions.createAttribute(name, value);
            // add attribute to the rule
            rule.addAttribute(attribute);
        }
        // add the rule to the list
        if (LOG.isDebugEnabled()) {
            LOG.debug("adding rule in ACL: " + rule);
        }
        accessControlRules.add(rule);

    } // while

    return accessControlRules;
}

From source file:org.glite.slcs.group.impl.XMLFileGroupManager.java

/**
 * Creates the list of groups defined in the FileConfiguration.
 * //www .j ava 2 s .  com
 * @param config
 *            The FileConfiguration object.
 * @return The list of {@link Group}s.
 */
static private List createGroups(FileConfiguration config) {
    // get the attribute definition helper for the attribute display name
    SLCSServerConfiguration slcsConfig = SLCSServerConfiguration.getInstance();
    AttributeDefinitions attributeDefinitions = slcsConfig.getAttributeDefinitions();

    // create an empty groups list
    List groups = new LinkedList();
    // list all groups
    int i = 0;
    boolean moreGroup = true;
    while (moreGroup) {
        String groupPrefix = "Group(" + i + ")";
        i++;
        // get the name of the group
        String groupName = config.getString(groupPrefix + "[@name]");
        if (groupName != null) {
            // create an empty named group
            Group group = new Group(groupName);
            // list all members of this group
            int j = 0;
            boolean moreMember = true;
            while (moreMember) {
                String memberPrefix = groupPrefix + ".GroupMember(" + j + ")";
                j++;
                // get the attributes name and value for the group member
                List attributeNames = config.getList(memberPrefix + ".Attribute[@name]");
                if (!attributeNames.isEmpty()) {
                    // create an empty member
                    GroupMember member = new GroupMember();
                    List memberAttributes = new ArrayList();
                    // list and add the membership attributes
                    List attributeValues = config.getList(memberPrefix + ".Attribute");
                    for (int k = 0; k < attributeNames.size(); k++) {
                        String name = (String) attributeNames.get(k);
                        String value = (String) attributeValues.get(k);
                        Attribute attribute = attributeDefinitions.createAttribute(name, value);
                        // add attribute to the group membership attributes
                        // list
                        memberAttributes.add(attribute);
                    }
                    // set the membership attributes list
                    member.setAttributes(memberAttributes);
                    // and add the member to the group
                    group.addGroupMember(member);
                } else {
                    moreMember = false;
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(memberPrefix + ": no more group members");
                    }
                }
            } // while all members

            // get all constrained attributes for the group ACL rules
            String constraintPrefix = groupPrefix + ".AccessControlRuleConstraint";
            // get the attributes name and value for the group ACL rule
            // constraint
            List attributeNames = config.getList(constraintPrefix + ".Attribute[@name]");
            if (!attributeNames.isEmpty()) {
                List constrainedAttributes = new ArrayList();
                // list and add the ACL rule attributes constraints
                List attributeValues = config.getList(constraintPrefix + ".Attribute");
                for (int k = 0; k < attributeNames.size(); k++) {
                    String name = (String) attributeNames.get(k);
                    String value = (String) attributeValues.get(k);
                    Attribute attribute = attributeDefinitions.createAttribute(name, value);
                    // add attribute constraint list
                    attribute.setConstrained(true);
                    constrainedAttributes.add(attribute);
                }
                // set the group ACL rule constraint
                group.setRuleAttributesConstraint(constrainedAttributes);
            }

            // add the group to the groups list
            // TODO: check for group without members
            groups.add(group);

        } else {
            moreGroup = false;
            if (LOG.isDebugEnabled()) {
                LOG.debug(groupPrefix + ": no more groups");
            }
        }

    } // while all groups

    return groups;
}

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

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