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

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

Introduction

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

Prototype

public void setHeaderComment(String comment) 

Source Link

Document

Sets the header comment for the represented properties file.

Usage

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

public void dumpConfigContent(StructuredLogicalConfigServiceContent content, Writer writer)
        throws InvalidConfigServiceException {
    try {//from  ww  w. j  a v a2 s .  c  om
        ValidatorUtil.validate(content);
    } catch (TechnicalException e) {
        throw new InvalidConfigServiceException("Invalid structured content:" + e, e);
    }
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout();
    layout.setLineSeparator("\n");
    String headerComment = content.getHeaderComment();
    if (headerComment != null) {
        layout.setHeaderComment(headerComment);
    }
    for (ConfigEntry configEntry : content.configEntries) {
        String key = configEntry.getKey();
        propertiesConfiguration.addProperty(key, configEntry.getValue());
        String comment = configEntry.getComment();
        layout.setSeparator(key, "=");
        if (comment != null) {
            layout.setComment(key, comment);
        }
    }
    try {
        propertiesConfiguration.save(writer);
    } catch (ConfigurationException e) {
        throw new InvalidConfigServiceException("Invalid structured content or output:" + e, e);
    }
}