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

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

Introduction

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

Prototype

public XMLConfiguration() 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:org.apereo.lap.services.configuration.ConfigurationService.java

private PipelineConfig buildPipelineConfig(Path path) throws IOException {
    XMLConfiguration xml = new XMLConfiguration();
    try (InputStream in = Files.newInputStream(path)) {
        try {/*from   w  ww .j a v a2  s .  c o  m*/
            xml.load(in);
        } catch (ConfigurationException ce) {
            throw new IOException(ce);
        }
    }
    PipelineConfig cfg = PipelineConfig.makeConfigFromXML(this, storage, xml);
    if (cfg.isValid()) {
        logger.info("Pipeline config ({}) loaded from: {}", cfg.getType(), path);
    } else {
        logger.warn("Invalid pipeline config file ({}): {}", cfg.getInvalidReasons(), path);
        cfg = null;
    }
    return cfg;
}

From source file:org.efaps.earchive.Shell.java

public static void main(final String[] _args) {

    final XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    for (final String arg : _args) {
        if (arg.startsWith("-")) {
            final int index = arg.indexOf('=');
            config.addProperty((index > 0) ? arg.substring(1, index) : arg.substring(1),
                    (index > 0) ? arg.substring(index + 1) : null);
        }//from www . j  a v a 2  s.com
    }
    final String configUrl = (String) config.getProperty("Dshell.parameter.configFile");
    final File file = new File(configUrl);
    if (configUrl != null) {
        final XMLConfiguration config2 = new XMLConfiguration();
        config2.setDelimiterParsingDisabled(true);
        try {
            config2.load(file);
        } catch (final ConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(config2.getString("type"));
        final String type = config2.getString("type");
        final String factory = config2.getString("factory");
        final String connection = config2.getString("connection");
        try {
            StartupDatabaseConnection.startup(type, factory, convertToMap(connection),
                    "org.objectweb.jotm.Current");
            reloadCache();
        } catch (final StartupException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final EFapsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        final SVNProxyServer server = SVNProxyServer.get();
        server.start();
    } else {
        //TODO fehler
    }

}

From source file:org.expretio.maven.plugins.capnp.CapnProtoMojo.java

private void doHandleNativesDependency() throws MojoExecutionException {
    String classifier;//from   ww w. ja va2 s .  c  o  m

    if (nativeDependencyClassifier.equals(AUTO_CLASSIFIER_DEFAULT)) {
        Table<String, String, String> indexTable = HashBasedTable.create();

        try {
            XMLConfiguration index = new XMLConfiguration();

            index.load(resolve(createNativesIndexArtifact()));

            for (HierarchicalConfiguration indexEntry : index.configurationsAt("entry")) {
                String osName = indexEntry.getString("os-name");
                String archNames = indexEntry.getString("arch-names");
                String mavenClassifier = indexEntry.getString("maven-classifier");

                for (String archName : Splitter.on(',').omitEmptyStrings().trimResults().split(archNames)) {
                    indexTable.put(osName.toUpperCase(), getCanonicalArchitecture(archName), mavenClassifier);
                }
            }

            classifier = indexTable.get(JavaPlatform.getCurrentOs().toString(),
                    getCanonicalArchitecture(JavaPlatform.getCurrentArch()));
        } catch (Exception e) {
            throw new NativesManagerException(e);
        }
    } else {
        classifier = nativeDependencyClassifier;
    }

    nativesManager.addResourceUrl(resolve(createNativesArtifact(classifier)));
}

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

/**
 * load the configuration for a single file in a module
 *//*from w ww .  ja  v  a  2 s.  c o  m*/
public RootConfigurationProperty loadConfiguration(Module m, File f, Locale l)
        throws ConfigurationManagerException {
    try {
        boolean loadfile = loadThisFile(f, l);
        //System.out.println("Should we load " + f.getName() +
        //" for locale " + l.toString() + " : " + loadfile);
        if (!loadfile) { //don't load this file if it's not of the correct locale
            return null;
        }

        f = ConfigurationManager.getOverwriteFile(m, f);

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

        FileInputStream stream = null;
        try {
            stream = new FileInputStream(f);
            xmlconfig.load(stream);
        } finally {
            if (stream != null) {
                stream.close();
            }
        }

        //David Welker: Adding configuration directives
        boolean mustSave = applyConfigurationDirectives(m, f, xmlconfig);

        RootConfigurationProperty cp = new RootConfigurationProperty(m, f);
        //set the default namespace
        ConfigurationNamespace namespace = new ConfigurationNamespace(ConfigurationManager
                .removeLocaleDesignator(ConfigurationManager.removeFileExtension(f.getName())));
        cp.setNamespace(namespace);

        ConfigurationNode rootCN = xmlconfig.getRootNode();

        //check to see if there is a namsepace element and use that if there is
        if (rootCN.getChild(0).getName().equals("namespace")) {
            String ns = (String) rootCN.getChild(0).getValue();
            namespace = new ConfigurationNamespace(ns);
            cp.setNamespace(namespace);
        }
        //create the config property
        ConfigurationProperty deserializedProp = getConfiguration(rootCN, m, namespace);

        cp.addProperty(deserializedProp);

        if (mustSave && configurationWriter != null)
            configurationWriter.writeConfiguration(cp);

        return cp;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ConfigurationManagerException(
                "Error loading configuration file " + f.getPath() + ": " + e.getMessage());
    }
}

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

/**
 * Author: David Welker/*from w  w w .  j  a  v a2  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();//from   ww w . java2s .  c  o 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 changeTest() throws Exception {

    System.out.println("ChangeTest");
    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  w  ww  . j  a  v  a2s.  c om*/

    File originalXml = new File(configDir, "original.xml");
    File changeXml = new File(configDirectivesDir, "change.xml");
    File changedXml = new File(configDirectivesDir, "changed.xml");

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

    Iterator i;

    i = originalXmlConfig.getKeys();

    System.out.println("Original.xml:");
    while (i.hasNext()) {
        String key = (String) i.next();
        System.out.println(key + " = " + originalXmlConfig.getProperty(key));
    }
    System.out.println();

    XMLConfiguration changeXmlConfig = new XMLConfiguration();
    changeXmlConfig.setDelimiterParsingDisabled(true);
    changeXmlConfig.load(changeXml);

    XMLConfiguration changedXmlConfig = new XMLConfiguration();
    changedXmlConfig.setDelimiterParsingDisabled(true);
    if (changedXml.exists())
        changedXmlConfig.load(changedXml);

    i = changeXmlConfig.getKeys();

    System.out.println("Change.xml:");
    while (i.hasNext()) {
        String key = (String) i.next();
        System.out.println(key + " = " + changeXmlConfig.getProperty(key));
    }
    System.out.println();

    i = changeXmlConfig.getKeys();
    while (i.hasNext()) {
        String key = (String) i.next();
        Object value = changeXmlConfig.getProperty(key);
        Object changed = changedXmlConfig.getProperty(key);
        if (changed == null || !value.equals(changed)) {
            originalXmlConfig.setProperty(key, value);
            changedXmlConfig.setProperty(key, value);
        }
    }

    i = originalXmlConfig.getKeys();

    System.out.println("New Config:");
    while (i.hasNext()) {
        String key = (String) i.next();
        System.out.println(key + " = " + originalXmlConfig.getProperty(key));
    }
    System.out.println();

    i = changedXmlConfig.getKeys();

    System.out.println("Changed.xml");
    while (i.hasNext()) {
        String key = (String) i.next();
        System.out.println(key + " = " + changedXmlConfig.getProperty(key));
    }
    System.out.println();

    changedXmlConfig.save(changedXml);
}

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  .ja  va  2  s . 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);
}