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

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

Introduction

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

Prototype

public CompositeConfiguration() 

Source Link

Document

Creates an empty CompositeConfiguration object which can then be added some other Configuration files

Usage

From source file:org.ejbca.externalra.gui.ExternalRaGuiConfiguration.java

private static Configuration instance() {
    if (config == null) {
        try {//from   w ww .  ja v a2s  . c  om
            // Default values build into war file, this is last prio used if no of the other sources override this
            boolean allowexternal = Boolean.getBoolean(new PropertiesConfiguration(
                    ExternalRaGuiConfiguration.class.getResource("/" + PROPERTIES_FILENAME))
                            .getString(PROPERTY_CONFIGALLOWEXTERNAL, "false"));
            config = new CompositeConfiguration();
            PropertiesConfiguration pc;
            // Only add these config sources if we allow external configuration
            if (allowexternal) {
                // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
                config.addConfiguration(new SystemConfiguration());
                log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");
                // Override with file in "application server home directory"/conf, this is prio 2
                File f1 = new File("conf/" + PROPERTIES_FILENAME);
                pc = new PropertiesConfiguration(f1);
                pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                config.addConfiguration(pc);
                log.info("Added file to configuration source: " + f1.getAbsolutePath());
                // Override with file in "/etc/ejbca/conf/extra, this is prio 3
                File f2 = new File("/etc/ejbca/conf/extra/" + PROPERTIES_FILENAME);
                pc = new PropertiesConfiguration(f2);
                pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                config.addConfiguration(pc);
                log.info("Added file to configuration source: " + f2.getAbsolutePath());
            }
            // Default values build into war file, this is last prio used if no of the other sources override this
            URL url = ExternalRaGuiConfiguration.class.getResource("/" + PROPERTIES_FILENAME);
            pc = new PropertiesConfiguration(url);
            config.addConfiguration(pc);
            log.info("Added url to configuration source: " + url);
            log.info("Allow external re-configuration: " + allowexternal);
        } catch (ConfigurationException e) {
            log.error("Error intializing ExtRA Configuration: ", e);
        }
    }
    return config;
}

From source file:org.ejbca.extra.util.ExtraConfiguration.java

public static Configuration instance() {
    if (config == null) {
        try {//from  w  w  w.j av  a2  s.c o  m
            // Default values build into war file, this is last prio used if no of the other sources override this
            boolean allowexternal = Boolean.getBoolean(
                    new PropertiesConfiguration(ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME))
                            .getString(CONFIGALLOWEXTERNAL, "false"));

            config = new CompositeConfiguration();

            PropertiesConfiguration pc;
            // Only add these config sources if we allow external configuration
            if (allowexternal) {
                // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
                config.addConfiguration(new SystemConfiguration());
                log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");

                // Override with file in "application server home directory"/conf, this is prio 2
                File f1 = new File("conf/" + PROPERTY_FILENAME);
                pc = new PropertiesConfiguration(f1);
                pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                config.addConfiguration(pc);
                log.info("Added file to configuration source: " + f1.getAbsolutePath());

                // Override with file in "/etc/ejbca/conf/extra, this is prio 3
                File f2 = new File("/etc/ejbca/conf/extra/" + PROPERTY_FILENAME);
                pc = new PropertiesConfiguration(f2);
                pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                config.addConfiguration(pc);
                log.info("Added file to configuration source: " + f2.getAbsolutePath());
            }

            // Default values build into war file, this is last prio used if no of the other sources override this
            URL url = ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME);
            pc = new PropertiesConfiguration(url);
            config.addConfiguration(pc);
            log.info("Added url to configuration source: " + url);

            log.info("Allow external re-configuration: " + allowexternal);
            // Test
            log.debug("Using keystore path (1): " + config.getString(SCEPKEYSTOREPATH + ".1"));
            //log.debug("Using keystore pwd (1): "+config.getString(SCEPKEYSTOREPWD+".1"));
            //log.debug("Using authPwd: "+config.getString(SCEPAUTHPWD));
            log.debug("Using certificate profile: " + config.getString(SCEPCERTPROFILEKEY));
            log.debug("Using entity profile: " + config.getString(SCEPENTITYPROFILEKEY));
            log.debug("Using default CA: " + config.getString(SCEPDEFAULTCA));
            log.debug("Create or edit user: " + config.getBoolean(SCEPEDITUSER));
            log.debug("Mapping for CN=Scep CA,O=EJBCA Sample,C=SE: "
                    + config.getString("CN=Scep CA,O=EJBCA Sample,C=SE"));
        } catch (ConfigurationException e) {
            log.error("Error intializing ExtRA Configuration: ", e);
        }
    }
    return config;
}

From source file:org.ejbca.ui.cli.config.cmp.UploadFileCommand.java

@Override
public CommandResult execute(ParameterContainer parameters) {
    String filename = parameters.get(FILE_KEY);
    String alias = parameters.get(ALIAS_KEY);

    CompositeConfiguration config = null;
    File f = null;//from   w ww  . ja va 2  s .  com
    try {
        f = new File(filename);
        final PropertiesConfiguration pc = new PropertiesConfiguration(f);
        pc.setReloadingStrategy(new FileChangedReloadingStrategy());
        config = new CompositeConfiguration();
        config.addConfiguration(pc);
        log.info("Reading CMP configuration from file: " + f.getAbsolutePath());
    } catch (ConfigurationException e) {
        log.error("Failed to load configuration from file " + f.getAbsolutePath());
        return CommandResult.FUNCTIONAL_FAILURE;
    }
    readConfigurations(config, alias);
    return CommandResult.SUCCESS;

}

From source file:org.ejbca.ui.cli.config.scep.UploadFileCommand.java

@Override
public CommandResult execute(ParameterContainer parameters) {
    String filename = parameters.get(FILE_KEY);
    String alias = parameters.get(ALIAS_KEY);

    CompositeConfiguration config = null;
    File f = null;/*from  ww w.  j a  va2 s.co  m*/
    try {
        f = new File(filename);
        final PropertiesConfiguration pc = new PropertiesConfiguration(f);
        pc.setReloadingStrategy(new FileChangedReloadingStrategy());
        config = new CompositeConfiguration();
        config.addConfiguration(pc);
        log.info("Reading SCEP configuration from file: " + f.getAbsolutePath());
    } catch (ConfigurationException e) {
        log.error("Failed to load configuration from file " + f.getAbsolutePath());
        return CommandResult.FUNCTIONAL_FAILURE;
    }
    readConfigurations(config, alias);
    return CommandResult.SUCCESS;

}

From source file:org.eurocarbdb.dataaccess.Eurocarb.java

static void initConfig() {
    //if ( config == null )
    config = new CompositeConfiguration();

    try {/*from  w w w . ja va2s.c o  m*/
        // log.info("adding configuration: " + EUROCARB_OVERRIDES_CONF );
        // config.addConfiguration( 
        //     new PropertiesConfiguration( EUROCARB_OVERRIDES_CONF ) );
        // log.info( "configured properties for core-api: \n" 
        //     + ConfigurationUtils.toString( config ) );

        log.info("adding core-api configuration: " + EUROCARB_CONF);
        config.addConfiguration(new PropertiesConfiguration(EUROCARB_CONF));
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }

    if (log.isInfoEnabled()) {
        log.info(CR + repeat('=', 20) + " configured eurocarb core-api properties " + repeat('=', 20) + CR
                + ConfigurationUtils.toString(config) + CR + repeat('=', 80));
    }

}

From source file:org.ff4j.commonsconf.CommonsConfigWithPropertyStoreTest.java

@Before
public void initCommonsConfWithFF4j() throws ConfigurationException {
    // init configuration
    ff4jConf = new FF4jConfiguration(new InMemoryPropertyStore("ff4j-properties.xml"));
    // composite/*from  w  w  w.  j av a  2  s .c o  m*/
    config = new CompositeConfiguration();
    config.setThrowExceptionOnMissing(true);
    config.addConfiguration(ff4jConf);
}

From source file:org.fitting.FittingConfiguration.java

/**
 * Create a new instance.//from w  w  w. j ava 2s  .c  o  m
 * Private to prevent external instantiation.
 */
private FittingConfiguration() {
    configuration = new CompositeConfiguration();
    loadProperties();
    loadDefaults();
}

From source file:org.freeeed.main.ParameterProcessing.java

/**
 * Custom configuration / processing parameters
 *
 * @param customParametersFile file path of properties file
 * @return/*  w  ww  . java 2s.c om*/
 */
public static Configuration collectProcessingParameters(String customParametersFile) {

    // apache.commons configuration class
    CompositeConfiguration cc = new CompositeConfiguration();

    try {
        // custom parameter file is first priority
        if (customParametersFile != null) {
            // read file
            Configuration customProperties = new FreeEedConfiguration(customParametersFile);
            // add to configuration
            cc.addConfiguration(customProperties);
        }

        // default parameter file is last priority

        // read file
        Configuration defaults = new FreeEedConfiguration(DEFAULT_PARAMETER_FILE);
        // add to configuration
        cc.addConfiguration(defaults);

        // set project file name
        cc.setProperty(PROJECT_FILE_NAME, customParametersFile);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        // follow the "fail-fast" design pattern
        System.exit(0);
    }
    return cc;
}

From source file:org.freeeed.main.ParameterProcessing.java

/**
 * Default configuration / processing parameters
 *
 * @return/*  w w w. ja  v a  2 s . co m*/
 */
public static Configuration setDefaultParameters() {
    CompositeConfiguration cc = new CompositeConfiguration();
    try {
        Configuration defaults = new FreeEedConfiguration(DEFAULT_PARAMETER_FILE);
        cc.addConfiguration(defaults);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        // follow the "fail-fast" design pattern
        System.exit(0);
    }
    return cc;
}

From source file:org.freemedsoftware.shim.Configuration.java

/**
 * Load configuration from both template and override properties files.
 *//* www.ja va2s . com*/
public static void loadConfiguration() {
    log.trace("Entered loadConfiguration");
    if (servletContext == null) {
        log.error("servletContext not set!");
    }
    if (compositeConfiguration == null) {
        log.info("Configuration object not present, instantiating");
        compositeConfiguration = new CompositeConfiguration();

        PropertiesConfiguration defaults = null;
        try {
            defaults = new PropertiesConfiguration(
                    servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
            log.info("Loading default configuration from "
                    + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
        } catch (ConfigurationException e) {
            log.error("Could not load default configuration from "
                    + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG));
            // e.printStackTrace();
        }
        if (OVERRIDE_CONFIG != null) {
            PropertiesConfiguration overrides = null;
            try {
                overrides = new PropertiesConfiguration();
                overrides.setFile(new File(OVERRIDE_CONFIG));
                overrides.setReloadingStrategy(new FileChangedReloadingStrategy());
                overrides.load();
            } catch (ConfigurationException e) {
                log.info("Could not load overrides", e);
            }
            compositeConfiguration.addConfiguration(overrides);
        }
        // Afterwards, add defaults so they're read second.
        compositeConfiguration.addConfiguration(defaults);
    }
}