Example usage for org.apache.commons.configuration2 PropertiesConfigurationLayout PropertiesConfigurationLayout

List of usage examples for org.apache.commons.configuration2 PropertiesConfigurationLayout PropertiesConfigurationLayout

Introduction

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

Prototype

public PropertiesConfigurationLayout() 

Source Link

Document

Creates a new, empty instance of PropertiesConfigurationLayout .

Usage

From source file:com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl.java

@Override
public void scrubRegistrationProperties() {
    if (!exist()) {
        return;//from w  w  w.  j a va  2s  .co  m
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
        layout.setLineSeparator("\n");
        layout.load(config, reader());
        try (FileWriter out = new FileWriter(this.configFile)) {
            layout.save(config, out);
        }
        loadProperties();
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}

From source file:com.haulmont.mp2xls.writer.LocalizationBatchFileWriter.java

/**
 * Writing all changed properties to the passed file. Using apache commons-configuration to write properties,
 * because it preserves the original file format unlike the java.util.Properties class.
 *
 * @param messagesFile - messages file//from w ww.ja va  2  s  . co  m
 * @param diffs - differences
 */
protected void mergeLocalizationProperties(File messagesFile, Collection<LocalizationLog> diffs) {
    if (diffs == null || diffs.isEmpty())
        return;
    try {
        Parameters parameters = new Parameters();
        FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                PropertiesConfiguration.class)
                        .configure(parameters.properties().setFile(messagesFile).setEncoding("UTF-8")
                                .setIOFactory(new MessagePropertiesIOFactory())
                                .setLayout(new PropertiesConfigurationLayout()));

        Configuration configuration = builder.getConfiguration();
        for (LocalizationLog diff : diffs) {
            if (LocalizationLog.Type.CHANGED.equals(diff.getType())) {
                configuration.setProperty(diff.getParameterName(), diff.getExcelValue());
            }
        }
        builder.save();
    } catch (Exception e) {
        throw new RuntimeException("Exception during properties file merging", e);
    }
}