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

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

Introduction

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

Prototype

public Iterator getKeys(String prefix) 

Source Link

Usage

From source file:net.sf.tweety.cli.plugins.CliMain.java

/**
 * This method is meant to load the tweety plugin pathes on startup
 * //from w w w  . j a va  2 s  .c om
 * @return an object with one or more pluginpathes
 * @throws ConfigurationException
 */
public static Map<String, String> configCLI() throws ConfigurationException, FileNotFoundException {

    System.out.println("Initialize CLI...");

    // TODO : exception handling for empty/erroneous configuration
    Map<String, String> loadablePlugins = new HashMap<String, String>();

    XMLConfiguration tweetyXmlConfig = new XMLConfiguration();
    File in = new File(TWEETY_CLI_DEFAULT_CONFIG);
    try {
        System.out.print("Loading Configuration...");
        String inPath = in.getAbsolutePath();
        tweetyXmlConfig
                .setBasePath(inPath.substring(0, inPath.length() - TWEETY_CLI_DEFAULT_CONFIG.length() - 1));
        tweetyXmlConfig.load(in);
        System.out.print("success.\n");
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    // map ueber "plugins.plugin" mit keys ()
    // TODO: Verhalten bei leeren Feldern pruefen
    // TODO: Verhalten bei einem einzelnen Eintrag prfen
    Iterator<String> it = tweetyXmlConfig.getKeys("plugin");

    // // TODO fix the casts!
    // if (it.hasNext()) {
    //
    // String pluginPath = (String) tweetyXmlConfig.getProperty(it.next()
    // .toString());
    //
    // String pluginName = (String) tweetyXmlConfig.getProperty(it.next()
    // .toString());
    //
    // // for (int i = 0; i < pluginPath.size(); i++) {
    // // System.out.println(pluginName.get(i) + pluginPath.get(i));
    // loadablePlugins.put(pluginName, pluginPath);
    // }
    // }
    System.out.print("Getting Plugins...");
    // TODO fix the casts!
    if (it.hasNext()) {
        @SuppressWarnings("unchecked")
        ArrayList<String> pluginPath = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next());
        @SuppressWarnings("unchecked")
        ArrayList<String> pluginName = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next());

        for (int i = 0; i < pluginPath.size(); i++) {
            // System.out.println(pluginName.get(i) + pluginPath.get(i));
            loadablePlugins.put(pluginName.get(i), pluginPath.get(i));
        }
    }
    System.out.print("done.\n");
    System.out.println("CLI initialized");
    return loadablePlugins;
}

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

private void copyAllProperties(XMLConfiguration fromConfig, XMLConfiguration toConfig, String prefix) {
    Iterator<String> iter = fromConfig.getKeys(prefix);
    while (iter.hasNext()) {
        String key = iter.next();
        copyProperty(fromConfig, toConfig, key);
    }/*from   w w w.j  ava2 s .c  o  m*/
}