Example usage for org.apache.commons.configuration XMLConfiguration clear

List of usage examples for org.apache.commons.configuration XMLConfiguration clear

Introduction

In this page you can find the example usage for org.apache.commons.configuration XMLConfiguration clear.

Prototype

public void clear() 

Source Link

Document

Removes all properties from this configuration.

Usage

From source file:elaborate.editor.config.Configuration.java

public XMLConfiguration load(Reader reader) {
    try {/* w w w .  ja v  a2 s. c o m*/
        messages = Maps.newTreeMap();
        AbstractConfiguration.setDefaultListDelimiter(',');
        XMLConfiguration config = new XMLConfiguration();
        config.clear();
        config.load(reader);
        processConfiguration(config);
        xmlConfig = config;
        return config;
    } catch (ConfigurationException e) {
        throw new RuntimeException("Failed to load configuration", e);
    }
}

From source file:com.qmetry.qaf.automation.util.PropertyUtil.java

private boolean loadFile(File file) {
    try {/*  www.  j a  v a2 s .c  o m*/
        if (file.getName().endsWith("xml") || file.getName().contains(".xml.")) {
            super.load(new FileInputStream(file));
            XMLConfiguration xmlConfiguration = new XMLConfiguration(file);
            copy(xmlConfiguration);
            xmlConfiguration.clear();
        } else {
            PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            propertiesConfiguration
                    .setEncoding(getString(ApplicationProperties.LOCALE_CHAR_ENCODING.key, "UTF-8"));
            propertiesConfiguration.load(new FileInputStream(file));
            copy(propertiesConfiguration);
            propertiesConfiguration.clear();
            // super.load(new FileInputStream(file));
        }
        return true;
    } catch (ConfigurationException e) {
        logger.error(e.getMessage());
    } catch (FileNotFoundException e) {
        logger.error(e.getMessage());
    }

    return false;
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests saving to a stream.//from  ww w  .ja  v  a 2  s. co  m
 */
@Test
public void testSaveToStream() throws Exception {
    assertNull(conf.getEncoding());
    conf.setEncoding("UTF8");
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(testSaveConf);
        conf.save(out);
    } finally {
        if (out != null) {
            out.close();
        }
    }

    XMLConfiguration checkConfig = new XMLConfiguration();
    checkConfig.setFile(testSaveConf);
    checkSavedConfig(checkConfig);

    try {
        out = new FileOutputStream(testSaveConf);
        conf.save(out, "UTF8");
    } finally {
        if (out != null) {
            out.close();
        }
    }

    checkConfig.clear();
    checkSavedConfig(checkConfig);
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests the copy constructor./*from  w  w  w.  j  av  a  2s.  co  m*/
 */
@Test
public void testInitCopy() throws ConfigurationException {
    XMLConfiguration copy = new XMLConfiguration(conf);
    assertEquals("value", copy.getProperty("element"));
    assertNull("Document was copied, too", copy.getDocument());
    ConfigurationNode root = copy.getRootNode();
    for (ConfigurationNode node : root.getChildren()) {
        assertNull("Reference was not cleared", node.getReference());
    }

    removeTestFile();
    copy.setFile(testSaveConf);
    copy.save();
    copy.clear();
    checkSavedConfig(copy);
}