Example usage for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder FileBasedConfigurationBuilder

List of usage examples for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder FileBasedConfigurationBuilder

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder FileBasedConfigurationBuilder.

Prototype

public FileBasedConfigurationBuilder(final Class<? extends T> resCls) 

Source Link

Document

Creates a new instance of FileBasedConfigurationBuilder which produces result objects of the specified class.

Usage

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricherTest.java

@Test
public void convert() throws Exception {
    XMLConfiguration configuration = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
            .configure(new Parameters().hierarchical()
                    .setFile(new File("./src/test/resources/DbEnvironmentXmlEnricher/system-config.xml")))
            .getConfiguration();//from  w w w . j av a2 s . c o m

    Map<String, Object> myMap = constructMap(configuration.getNodeModel().getNodeHandler().getRootNode());

    FixedYAMLConfiguration yamlConfiguration = new FixedYAMLConfiguration(configuration);
    StringWriter sw = new StringWriter();
    //        yamlConfiguration.write();
    DumperOptions dumperOptions = new DumperOptions();
    //        dumperOptions.setPrettyFlow(true);
    dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(dumperOptions);
    yaml.dump(myMap, sw);

    //        yamlConfiguration.dump(sw, new DumperOptions());
    System.out.println(sw.toString());
}

From source file:nl.imvertor.common.Configurator.java

/**
 * Return a XML configuration object for the file passed.
 * //from w w  w  . ja v a  2 s. c o m
 * Properties are accessible by xpath expressions.
 * 
 * @param configfile
 * @return
 * @throws ConfigurationException
 */
private XMLConfiguration load(File configfile) throws ConfiguratorException, ConfigurationException {
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<XMLConfiguration>(
            XMLConfiguration.class);
    XMLBuilderParameters p = params.xml();
    p.setFile(configfile);
    builder.configure(p);
    XMLConfiguration c = builder.getConfiguration();
    c.setExpressionEngine(new XPathExpressionEngine());
    return c;
}

From source file:nl.minvenj.pef.stream.LiveCapture.java

/**
 * Main function to start the tool for pseudonymization of packets.
 *
 * @param args command line tool arguments
 *//*from   ww  w . j a v  a  2  s . c o m*/
public static void main(String[] args) {
    String xmlConfigFile;
    if (args.length == 1) {
        xmlConfigFile = args[0];
    } else {
        xmlConfigFile = "configuration.xml";
    }
    // Test if the file exists.
    File configFile = new File(xmlConfigFile);
    if (!configFile.exists()) {
        System.out.println("Create the file configuration.xml with the settings for pseudonymization. "
                + "You can copy the configuration.proto.xml file as template.");
        // Exit the application.
        return;
    } else {
        System.out.println("Using " + xmlConfigFile + " as configuration file.");
    }
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(
            XMLConfiguration.class).configure(params.xml().setFileName(xmlConfigFile));
    try {
        XMLConfiguration config = builder.getConfiguration();
        // Check the configuration.
        String logFile = config.getString("log_file", "default_log.txt");
        initLogger(logFile);
        if (checkConfiguration(config)) {
            runPEF(config);
        }
    } catch (ConfigurationException cex) {
        // Loading of the configuration file failed
        cex.printStackTrace();
    } catch (IOException | SecurityException | IllegalArgumentException e) {
        // The logger could not be initialized.
        System.err.println("The logger could not be initialized " + e.getMessage());
    } catch (PEFException e) {
        System.err.println(e.getMessage());
    }
}

From source file:org.craftercms.engine.util.ConfigUtils.java

public static XMLConfiguration readXmlConfiguration(Resource resource, char listDelimiter,
        Map<String, Lookup> prefixLookups) throws ConfigurationException {
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(
            XMLConfiguration.class);

    try {/* w w w .  j  a  v  a  2s. c  o m*/
        XMLBuilderParameters xmlParams = params.xml().setURL(resource.getURL())
                .setListDelimiterHandler(new DefaultListDelimiterHandler(listDelimiter));

        if (MapUtils.isNotEmpty(prefixLookups)) {
            xmlParams = xmlParams.setPrefixLookups(prefixLookups);
        }

        builder.configure(xmlParams);
    } catch (IOException e) {
        throw new ConfigurationException("Unable to get URL of resource " + resource, e);
    }

    return builder.getConfiguration();
}

From source file:org.demoiselle.internal.implementation.ConfigurationLoader.java

private BasicConfigurationBuilder<? extends Configuration> createConfiguration() {
    BasicConfigurationBuilder<? extends Configuration> builder;

    switch (this.type) {
    case XML://from  w w w .j a v a  2  s . c o m
        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class);
        break;

    case SYSTEM:
        builder = new BasicConfigurationBuilder<>(SystemConfiguration.class);
        break;

    default:
        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class);
    }

    return builder;
}

From source file:org.jbb.lib.commons.PropertiesUtils.java

public static Configuration buildPropertiesConfiguration(URL url) {
    FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
            PropertiesConfiguration.class)
                    .configure(new Parameters().properties().setURL(url).setThrowExceptionOnMissing(true)
                            .setIncludesAllowed(false));
    try {/*from   w ww.  j  av a 2  s  .co  m*/
        return builder.getConfiguration();
    } catch (ConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.jbb.lib.properties.encrypt.PropertiesEncryptionIT.java

private void readPropertiesFile() throws ConfigurationException {
    String propertiesFilePath = jbbMetaData.jbbHomePath() + File.separator + "jbb-testbed.properties";
    FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
            PropertiesConfiguration.class).configure(
                    new Parameters().properties().setPath(propertiesFilePath).setIncludesAllowed(false));
    builder.setAutoSave(true);//w  w  w .j av a  2  s.com
    propFile = builder.getConfiguration();
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static PropertiesConfiguration getReferenceProperties(File propertyFile) {
    try {// w  w w. j a  v  a 2 s. c o  m
        ClassPathResource classPathResource = new ClassPathResource(propertyFile.getName());
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
                PropertiesConfiguration.class)
                        .configure(new Parameters().properties().setURL(classPathResource.getURL())
                                .setThrowExceptionOnMissing(true).setIncludesAllowed(false));
        return builder.getConfiguration();
    } catch (ConfigurationException | IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static PropertiesConfiguration getTargetPropertiesFromJbbPath(File propertyFile) {
    try {//from   w w w.ja  va  2  s  . co m
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
                PropertiesConfiguration.class).configure(
                        new Parameters().properties().setFile(propertyFile).setIncludesAllowed(false));
        builder.setAutoSave(true);
        return builder.getConfiguration();
    } catch (ConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.jbb.lib.properties.UpdateFilePropertyChangeListener.java

@Override
public void propertyChange(PropertyChangeEvent evt) {
    for (String propertyFile : propFiles) {
        try {//from  ww  w .  ja  v a  2 s .co m
            FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
                    PropertiesConfiguration.class).configure(
                            new Parameters().properties().setFileName(propertyFile).setIncludesAllowed(false));
            builder.setAutoSave(true);
            PropertiesConfiguration conf = builder.getConfiguration();
            evt.setPropagationId(propertyFile);
            conf.setProperty(evt.getPropertyName(), evt.getNewValue());
        } catch (ConfigurationException e) {
            throw new IllegalArgumentException(e);
        }
    }
}