Example usage for org.apache.commons.configuration PropertiesConfigurationLayout getKeys

List of usage examples for org.apache.commons.configuration PropertiesConfigurationLayout getKeys

Introduction

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

Prototype

public Set getKeys() 

Source Link

Document

Returns a set with all property keys managed by this object.

Usage

From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java

/**
 *
 *
 * @param reader/*from  w  w w  .j a  v  a 2s  . com*/
 * @return
 */
public StructuredLogicalConfigServiceContent parseConfigContent(Reader reader)
        throws InvalidConfigServiceException {
    List<ConfigEntry> parsedEntries = new ArrayList<ConfigEntry>();
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();

    try {
        propertiesConfiguration.load(reader);
    } catch (ConfigurationException e) {
        InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException(
                "Invalid config content. Caught:" + e, e);
        throw invalidConfigServiceException;
    }
    PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout();
    String headerComment = layout.getHeaderComment();

    Set<String> keys = layout.getKeys();
    Set<String> duplicates = new HashSet<String>();
    for (String key : keys) {
        String comment = layout.getComment(key);
        if (comment != null) {
            comment = escapesPoundsInComments(comment);
        }
        if (!layout.isSingleLine(key)) {
            //reject the duplicate key
            duplicates.add(key);
        } else {
            String value = propertiesConfiguration.getString(key);
            parsedEntries.add(new ConfigEntry(key, value, comment));
        }
    }

    if (duplicates.size() > 0) {
        InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException(
                "Collisions! " + duplicates);
        invalidConfigServiceException.setType(ErrorType.DUPLICATE_KEYS);
        invalidConfigServiceException.getDuplicateKeys().addAll(duplicates);
        throw invalidConfigServiceException;
    }

    List<ConfigEntry> configEntries = parsedEntries;
    StructuredLogicalConfigServiceContent structuredLogicalConfigServiceContent = new StructuredLogicalConfigServiceContent(
            headerComment, configEntries);
    return structuredLogicalConfigServiceContent;
}