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

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

Introduction

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

Prototype

public Object getProperty(String key) 

Source Link

Usage

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

private void copyProperty(XMLConfiguration fromConfig, XMLConfiguration toConfig, String key) {
    toConfig.setProperty(key, fromConfig.getProperty(key));
}

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

private void upgradeFrom1_4_1(XMLConfiguration config) {
    // As the POST_FORM option for the spider has been updated from int to boolean, keep
    // compatibility for old versions
    if (!config.getProperty("spider.postform").toString().equals("0")) {
        config.setProperty("spider.postform", "true");
        config.setProperty("spider.processform", "true");
    } else {/*from   w w  w  .j  a v  a  2  s  .  com*/
        config.setProperty("spider.postform", "false");
        config.setProperty("spider.processform", "false");
    }

    // Move the old session tokens to the new "httpsessions" hierarchy and 
    // delete the old "session" hierarchy as it's no longer used/needed.
    String[] tokens = config.getStringArray("session.tokens");
    for (int i = 0; i < tokens.length; ++i) {
        String elementBaseKey = "httpsessions.tokens.token(" + i + ").";

        config.setProperty(elementBaseKey + "name", tokens[i]);
        config.setProperty(elementBaseKey + "enabled", Boolean.TRUE);
    }
    config.clearTree("session");

    // Update the anti CSRF tokens elements/hierarchy.
    tokens = config.getStringArray("anticsrf.tokens");
    config.clearTree("anticsrf.tokens");
    for (int i = 0; i < tokens.length; ++i) {
        String elementBaseKey = "anticsrf.tokens.token(" + i + ").";

        config.setProperty(elementBaseKey + "name", tokens[i]);
        config.setProperty(elementBaseKey + "enabled", Boolean.TRUE);
    }

    // Update the invoke applications elements/hierarchy.
    List<Object[]> oldData = new ArrayList<>();
    for (int i = 0;; i++) {
        String baseKey = "invoke.A" + i + ".";
        String host = config.getString(baseKey + "name");
        if (host == null || "".equals(host)) {
            break;
        }

        Object[] data = new Object[6];
        data[0] = host;
        data[1] = config.getString(baseKey + "directory", "");
        data[2] = config.getString(baseKey + "command");
        data[3] = config.getString(baseKey + "parameters");
        data[4] = Boolean.valueOf(config.getBoolean(baseKey + "output", true));
        data[5] = Boolean.valueOf(config.getBoolean(baseKey + "note", false));
        oldData.add(data);
    }
    config.clearTree("invoke.A");
    for (int i = 0, size = oldData.size(); i < size; ++i) {
        String elementBaseKey = "invoke.apps.app(" + i + ").";
        Object[] data = oldData.get(i);

        config.setProperty(elementBaseKey + "name", data[0]);
        config.setProperty(elementBaseKey + "directory", data[1]);
        config.setProperty(elementBaseKey + "command", data[2]);
        config.setProperty(elementBaseKey + "parameters", data[3]);
        config.setProperty(elementBaseKey + "output", data[4]);
        config.setProperty(elementBaseKey + "note", data[5]);
        config.setProperty(elementBaseKey + "enabled", Boolean.TRUE);
    }

    // Update the authentication elements/hierarchy.
    oldData = new ArrayList<>();
    for (int i = 0;; i++) {
        String baseKey = "connection.auth.A" + i + ".";
        String host = config.getString(baseKey + "hostName");
        if (host == null || "".equals(host)) {
            break;
        }

        Object[] data = new Object[5];
        data[0] = host;
        data[1] = Integer.valueOf(config.getString(baseKey + "port", "80"));
        data[2] = config.getString(baseKey + "userName");
        data[3] = config.getString(baseKey + "password");
        data[4] = config.getString(baseKey + "realm");
        oldData.add(data);
    }
    config.clearTree("connection.auth.A");
    for (int i = 0, size = oldData.size(); i < size; ++i) {
        String elementBaseKey = "connection.auths.auth(" + i + ").";
        Object[] data = oldData.get(i);

        config.setProperty(elementBaseKey + "name", "Auth " + i);
        config.setProperty(elementBaseKey + "hostName", data[0]);
        config.setProperty(elementBaseKey + "port", data[1]);
        config.setProperty(elementBaseKey + "userName", data[2]);
        config.setProperty(elementBaseKey + "password", data[3]);
        config.setProperty(elementBaseKey + "realm", data[4]);
        config.setProperty(elementBaseKey + "enabled", Boolean.TRUE);
    }

    // Update the passive scan elements/hierarchy.
    String[] names = config.getStringArray("pscans.names");
    oldData = new ArrayList<>();
    for (String pscanName : names) {
        String baseKey = "pscans." + pscanName + ".";

        Object[] data = new Object[8];
        data[0] = pscanName;
        data[1] = config.getString(baseKey + "type");
        data[2] = config.getString(baseKey + "config");
        data[3] = config.getString(baseKey + "reqUrlRegex");
        data[4] = config.getString(baseKey + "reqHeadRegex");
        data[5] = config.getString(baseKey + "resHeadRegex");
        data[6] = config.getString(baseKey + "resBodyRegex");
        data[7] = Boolean.valueOf(config.getBoolean(baseKey + "enabled"));
        oldData.add(data);
    }
    config.clearTree("pscans.names");
    for (String pscanName : names) {
        config.clearTree("pscans." + pscanName);
    }
    for (int i = 0, size = oldData.size(); i < size; ++i) {
        String elementBaseKey = "pscans.autoTagScanners.scanner(" + i + ").";
        Object[] data = oldData.get(i);

        config.setProperty(elementBaseKey + "name", data[0]);
        config.setProperty(elementBaseKey + "type", data[1]);
        config.setProperty(elementBaseKey + "config", data[2]);
        config.setProperty(elementBaseKey + "reqUrlRegex", data[3]);
        config.setProperty(elementBaseKey + "reqHeadRegex", data[4]);
        config.setProperty(elementBaseKey + "resHeadRegex", data[5]);
        config.setProperty(elementBaseKey + "resBodyRegex", data[6]);
        config.setProperty(elementBaseKey + "enabled", data[7]);
    }
}

From source file:org.xmlactions.action.config.ExecContext.java

private void addXmlConfiguration(XMLConfiguration config) {
    Iterator<String> iterator = config.getKeys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        // log.debug("key:" + key);
        this.put(key, config.getProperty(key));
    }/*from   w ww .j av  a2s .  com*/
}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

private static XMLConfiguration getConfiguration(String file) {
    XMLConfiguration commonConfiguration = new XMLConfiguration();
    File commonConfigurationFile = new File(file);
    // load common configuration
    if (commonConfigurationFile.exists()) {
        LOGGER.info("Loading common configuration from " + commonConfigurationFile.getAbsolutePath());
        try {// w  ww  . j  a  v a  2s.  com
            commonConfiguration.load(commonConfigurationFile);
        } catch (ConfigurationException e) {
            LOGGER.severe("Can't load configuration, creating new " + e.getMessage());
        }
    } else {
        LOGGER.info("Common configuration file do not exist");
    }
    // load user specific configuration
    if (!AllPluginables.USER_CONFIGURATION_DIRECTORY.exists()) {
        LOGGER.info("Creating user specific OtrosLogViewer configuration directory "
                + AllPluginables.USER_CONFIGURATION_DIRECTORY.getAbsolutePath());
        AllPluginables.USER_CONFIGURATION_DIRECTORY.mkdirs();
        AllPluginables.USER_FILTER.mkdirs();
        AllPluginables.USER_LOG_IMPORTERS.mkdirs();
        AllPluginables.USER_MARKERS.mkdirs();
        AllPluginables.USER_MESSAGE_FORMATTER_COLORZIERS.mkdirs();
    }
    XMLConfiguration userConfiguration = new XMLConfiguration();
    File userConfigurationFile = new File(AllPluginables.USER_CONFIGURATION_DIRECTORY + File.separator + file);
    userConfiguration.setFile(userConfigurationFile);
    if (userConfigurationFile.exists()) {
        try {
            userConfiguration.load();
        } catch (ConfigurationException e) {
            LOGGER.severe(String.format("Can't load user configuration from %s: %s",
                    userConfigurationFile.getAbsolutePath(), e.getMessage()));
        }
    }
    Iterator<?> keys = commonConfiguration.getKeys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        if (!userConfiguration.containsKey(key)) {
            userConfiguration.setProperty(key, commonConfiguration.getProperty(key));
        }
    }
    userConfiguration.setAutoSave(true);
    return userConfiguration;
}