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

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

Introduction

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

Prototype

public void clearProperty(String key) 

Source Link

Usage

From source file:com.oltpbenchmark.util.ResultUploader.java

public void writeBenchmarkConf(PrintStream os) throws ConfigurationException {
    XMLConfiguration outputConf = (XMLConfiguration) expConf.clone();
    for (String key : IGNORE_CONF) {
        outputConf.clearProperty(key);
    }/*from  w ww .  ja  v a  2  s  .com*/
    outputConf.save(os);
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * Author: David Welker//  www  .  j  a  v  a  2 s .c  o  m
 *
 * This method applies unrun add directives to the configuration.
 * @param addXml
 * @param xmlconfig
 */
private boolean applyAddDirectives(Module module, File addXml, XMLConfiguration xmlconfig)
        throws ConfigurationException {
    String addXmlFilename = addXml.getName();
    String addedXmlFilename = addXmlFilename.substring(0, addXmlFilename.length() - 4) + "ed.xml";

    File addedXml = new File(DotKeplerManager.getInstance().getModuleConfigurationDirectory(module.getName()),
            addedXmlFilename);

    Iterator i;

    XMLConfiguration addXmlConfig = new XMLConfiguration();
    addXmlConfig.setDelimiterParsingDisabled(true);
    addXmlConfig.load(addXml);

    XMLConfiguration addedXmlConfig = new XMLConfiguration();
    addedXmlConfig.setDelimiterParsingDisabled(true);
    if (addedXml.exists())
        addedXmlConfig.load(addedXml);

    i = addXmlConfig.getKeys();
    if (!i.hasNext())
        return false;

    List<String> firstParts = new ArrayList<String>();
    while (i.hasNext()) {
        String key = (String) i.next();
        if (key.contains(".")) {
            String candidate = key.substring(0, key.indexOf('.'));
            if (!firstParts.contains(candidate))
                firstParts.add(candidate);
        }
    }

    for (String firstPart : firstParts) {

        int maxAddIndex = addXmlConfig.getMaxIndex(firstPart);
        int maxAddedIndex = addedXmlConfig.getMaxIndex(firstPart);
        int addIndex = xmlconfig.getMaxIndex(firstPart) + 1;

        List<String> removeKeys = new ArrayList<String>();
        for (int j = 0; j <= maxAddIndex; j++) {
            List<String> addKeys = new ArrayList<String>();
            Iterator x1 = addXmlConfig.getKeys(firstPart + "(" + j + ")");
            while (x1.hasNext()) {
                String key = (String) x1.next();
                addKeys.add(key);
            }
            for (int k = 0; k <= maxAddedIndex; k++) {
                List<String> addedKeys = new ArrayList<String>();
                Iterator x2 = addedXmlConfig.getKeys(firstPart + "(" + k + ")");
                while (x2.hasNext()) {
                    String key = (String) x2.next();
                    addedKeys.add(key);
                }

                if (addMatch(addKeys, addedKeys, addXmlConfig, addedXmlConfig)) {
                    for (String addKey : addKeys)
                        removeKeys.add(addKey);
                }
            }
        }
        for (int j = removeKeys.size() - 1; j >= 0; j--) {
            String removeKey = removeKeys.get(j);
            addXmlConfig.clearProperty(removeKey);
        }

        for (int j = 0; j <= maxAddIndex; j++) {
            String addXMLKey = firstPart + "(" + j + ")";
            i = addXmlConfig.getKeys(addXMLKey);
            while (i.hasNext()) {
                String addXmlConfigKey = (String) i.next();
                String lastPart = addXmlConfigKey.substring(addXmlConfigKey.indexOf('.') + 1,
                        addXmlConfigKey.length());
                String originalXmlConfigKey = firstPart + "(" + (addIndex + j) + ")." + lastPart;
                String addedXmlConfigKey = firstPart + "(" + (maxAddedIndex + 1 + j) + ")." + lastPart;
                xmlconfig.addProperty(originalXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey));
                addedXmlConfig.addProperty(addedXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey));
            }
        }
    }

    List<String> addedKeys = new ArrayList<String>();
    i = addedXmlConfig.getKeys();
    while (i.hasNext())
        addedKeys.add((String) i.next());

    i = addXmlConfig.getKeys();
    while (i.hasNext()) {
        String addKey = (String) i.next();
        if (addKey.contains("."))
            continue;
        Object value = addXmlConfig.getProperty(addKey);
        if (addedKeys.contains(addKey)) {
            if (addedXmlConfig.getProperty(addKey).equals(value))
                continue;
        }

        xmlconfig.addProperty(addKey, value);
        addedXmlConfig.addProperty(addKey, value);
    }

    addedXmlConfig.save(addedXml);
    return true;

}

From source file:org.kepler.configuration.ConfigurationTest.java

public static void addTest() throws Exception {
    System.out.println("AddTest");
    File configDir = Module.make("configuration-manager").getConfigurationsDir();
    File configDirectivesDir = new File(configDir.getParentFile(), "config-directives");
    System.out.println(configDir);
    System.out.println(configDirectivesDir);
    System.out.println();//  ww  w. j a va 2s  . co  m

    File originalXml = new File(configDir, "original.xml");
    File addXml = new File(configDirectivesDir, "add.xml");
    File addedXml = new File(configDirectivesDir, "added.xml");
    File newXml = new File(configDirectivesDir, "new.xml");

    XMLConfiguration xmlconfig = new XMLConfiguration();
    xmlconfig.setDelimiterParsingDisabled(true);
    xmlconfig.load(originalXml);

    Iterator i;

    XMLConfiguration addXmlConfig = new XMLConfiguration();
    addXmlConfig.setDelimiterParsingDisabled(true);
    addXmlConfig.load(addXml);

    XMLConfiguration addedXmlConfig = new XMLConfiguration();
    addedXmlConfig.setDelimiterParsingDisabled(true);
    if (addedXml.exists())
        addedXmlConfig.load(addedXml);

    i = addXmlConfig.getKeys();
    if (!i.hasNext())
        return;

    List<String> firstParts = new ArrayList<String>();
    while (i.hasNext()) {
        String key = (String) i.next();
        if (key.contains(".")) {
            String candidate = key.substring(0, key.indexOf('.'));
            if (!firstParts.contains(candidate))
                firstParts.add(candidate);
        }
    }

    for (String firstPart : firstParts) {
        System.out.println("firstPart = " + firstPart);
        int maxAddIndex = addXmlConfig.getMaxIndex(firstPart);
        int maxAddedIndex = addedXmlConfig.getMaxIndex(firstPart);
        int addIndex = xmlconfig.getMaxIndex(firstPart) + 1;

        List<String> removeKeys = new ArrayList<String>();
        for (int j = 0; j <= maxAddIndex; j++) {
            List<String> addKeys = new ArrayList<String>();
            Iterator x1 = addXmlConfig.getKeys(firstPart + "(" + j + ")");
            while (x1.hasNext()) {
                String key = (String) x1.next();
                addKeys.add(key);
            }
            for (int k = 0; k <= maxAddedIndex; k++) {
                List<String> addedKeys = new ArrayList<String>();
                Iterator x2 = addedXmlConfig.getKeys(firstPart + "(" + k + ")");
                while (x2.hasNext()) {
                    String key = (String) x2.next();
                    addedKeys.add(key);
                }

                if (addMatch(addKeys, addedKeys, addXmlConfig, addedXmlConfig)) {
                    for (String addKey : addKeys)
                        removeKeys.add(addKey);
                }
            }
        }
        for (int j = removeKeys.size() - 1; j >= 0; j--) {
            String removeKey = removeKeys.get(j);
            addXmlConfig.clearProperty(removeKey);
        }

        System.out.println("Adding config...");
        for (int j = 0; j <= maxAddIndex; j++) {
            String addXMLKey = firstPart + "(" + j + ")";
            i = addXmlConfig.getKeys(addXMLKey);
            while (i.hasNext()) {
                String addXmlConfigKey = (String) i.next();
                String lastPart = addXmlConfigKey.substring(addXmlConfigKey.indexOf('.') + 1,
                        addXmlConfigKey.length());
                String originalXmlConfigKey = firstPart + "(" + (addIndex + j) + ")." + lastPart;
                String addedXmlConfigKey = firstPart + "(" + (maxAddedIndex + 1 + j) + ")." + lastPart;
                xmlconfig.addProperty(originalXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey));
                addedXmlConfig.addProperty(addedXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey));
            }
        }
    }

    System.out.println("Simple adds...");
    List<String> addedKeys = new ArrayList<String>();
    i = addedXmlConfig.getKeys();
    while (i.hasNext())
        addedKeys.add((String) i.next());

    i = addXmlConfig.getKeys();
    while (i.hasNext()) {
        String addKey = (String) i.next();
        if (addKey.contains("."))
            continue;
        Object value = addXmlConfig.getProperty(addKey);
        if (addedKeys.contains(addKey)) {
            if (addedXmlConfig.getProperty(addKey).equals(value))
                continue;
        }

        xmlconfig.addProperty(addKey, value);
        addedXmlConfig.addProperty(addKey, value);
    }

    addedXmlConfig.save(addedXml);
    xmlconfig.save(newXml);
}

From source file:org.kepler.configuration.ConfigurationTest.java

public static void removeTest() throws Exception {

    System.out.println("RemoveTest");
    File configDir = Module.make("configuration-manager").getConfigurationsDir();
    File configDirectivesDir = new File(configDir.getParentFile(), "config-directives");
    System.out.println(configDir);
    System.out.println(configDirectivesDir);
    System.out.println();//from   www . j a  va 2s. c o  m

    File originalXml = new File(configDir, "original.xml");
    File removeXml = new File(configDirectivesDir, "remove.xml");
    File removedXml = new File(configDirectivesDir, "removed.xml");
    File newXml = new File(configDirectivesDir, "new.xml");

    XMLConfiguration originalXmlConfig = new XMLConfiguration();
    originalXmlConfig.setDelimiterParsingDisabled(true);
    originalXmlConfig.load(originalXml);

    Iterator i;

    XMLConfiguration removeXmlConfig = new XMLConfiguration();
    removeXmlConfig.setDelimiterParsingDisabled(true);
    removeXmlConfig.load(removeXml);

    XMLConfiguration removedXmlConfig = new XMLConfiguration();
    removedXmlConfig.setDelimiterParsingDisabled(true);
    if (removedXml.exists())
        removedXmlConfig.load(removedXml);

    i = removeXmlConfig.getKeys();
    while (i.hasNext()) {
        String key = (String) i.next();
        Object value = removeXmlConfig.getProperty(key);
        Object removed = removedXmlConfig.getProperty(key);
        if (removed == null || !value.equals(removed)) {
            originalXmlConfig.clearProperty(key);
            removedXmlConfig.setProperty(key, value);
        }
    }

    removedXmlConfig.save(removedXml);
    originalXmlConfig.save(newXml);
}

From source file:org.parosproxy.paros.Constant.java

private void upgradeFrom2_3_1(XMLConfiguration config) {
    // Remove old authentication options no longer used
    config.clearProperty("connection.confirmRemoveAuth");
    config.clearTree("options.auth");
}