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

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

Introduction

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

Prototype

public String getHeaderComment() 

Source Link

Document

Returns the header comment of the represented properties file.

Usage

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

/**
 *
 *
 * @param reader/*from  ww w. ja v  a2s. c o  m*/
 * @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;
}