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:ro.nextreports.server.web.ApplicationLoaderListener.java

private void config() {

    LOG.info("NextReports Server " + ReleaseInfo.getVersion() + " starting ... ");

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {/*from ww  w. ja v  a  2 s  .c  o m*/
        config.addConfiguration(new PropertiesConfiguration(getClass().getResource("/nextserver.properties")));
    } catch (ConfigurationException e) {
        // TODO
        e.printStackTrace();
    }

    File defaultNextServerHomeFolder = new File(System.getProperty("user.home"), ".nextserver");
    String defaultNextServerHome = defaultNextServerHomeFolder.getPath();
    String nextServerHome = config.getString("nextserver.home", defaultNextServerHome);
    LOG.info("nextserver.home = " + nextServerHome);

    String demo = System.getProperty("DEMO");
    LOG.info("DEMO=" + demo);
    boolean installWithDemo = Boolean.valueOf(demo);

    File nextServerHomeFolder = new File(nextServerHome);
    if (!nextServerHomeFolder.exists()) {
        try {
            if (installWithDemo) {
                deployDemoData(nextServerHome);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Create nextserver home folder: '" + nextServerHomeFolder + "'");
                }
                FileUtils.forceMkdir(nextServerHomeFolder);
            }
        } catch (IOException e) {
            // TODO
            e.printStackTrace();
        }
    }

    System.setProperty("nextserver.home", nextServerHome);

    //      File defaultJaspersHomeFolder = new File(nextServerHome, "jaspers");
    //      String defaultJaspersHome = defaultJaspersHomeFolder.getPath();
    //      String jaspersHome = config.getString("jaspers.home", defaultJaspersHome);
    //      System.setProperty("jaspers.home", jaspersHome);
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("jaspers.home = " + jaspersHome);         
    //      }      

    // indexing.file
    ClassPathResource classPathResource = new ClassPathResource("indexing.xml");
    String indexingFile = null;
    try {
        indexingFile = classPathResource.getFile().getAbsolutePath();
    } catch (IOException e) {
        // TODO
        e.printStackTrace();
    }
    System.setProperty("indexing.file", indexingFile);
    if (LOG.isDebugEnabled()) {
        LOG.debug("indexing.file = " + indexingFile);
    }

    //      String baseUrl = config.getString("nextserver.baseUrl");
    //      String reportsUrl = config.getString("reports.url");
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("nextserver.baseUrl = " + baseUrl);
    //         LOG.debug("reports.url = " + reportsUrl);
    //      }
}

From source file:sg.sfd2015.demo.utils.Config.java

synchronized private static void init() {
    String environment = System.getProperty("appenv") == null ? "development" : System.getProperty("appenv");
    String path = System.getProperty("appconfig");
    String pathFile = path + File.separator + environment + ".app.ini";

    System.out.println("pathFile:" + pathFile);
    // init configuration
    config = new CompositeConfiguration();
    _hashConfig = new ConcurrentHashMap<String, String>();
    try {/*w w  w . j  a v a 2s  .com*/
        config.addConfiguration(new HierarchicalINIConfiguration(pathFile));
    } catch (ConfigurationException ex) {
        logger_.error("Can't load configuration file", ex);
        System.err.println("Bad configuration; unable to start server");
        System.exit(1);
    }
}

From source file:tw.com.mt.DocAPIDemo.java

/**
 * Default constructor./* w w w  .j  a v a 2  s  .  c  o  m*/
 */
public DocAPIDemo() {
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(propertyFile));
        this.projObjKey = config.getInt("projObjKey");
        this.parentObjKey = config.getInt("parentObjKey");
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:tw.com.mt.ObsAPIDemo.java

/**
 * Default constructor.//  www .  jav a 2s  . c om
 */
public ObsAPIDemo() {
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(propertyFile));
        this.parentObjKey = config.getInt("parentObjKey");
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:tw.com.mt.TaskAPIDemo.java

/**
 * Default constructor./*from   ww  w. ja va2  s  .  co  m*/
 */
public TaskAPIDemo() {
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(propertyFile));
        this.projObjKey = config.getInt("projObjKey");
        this.parentObjKey = config.getInt("parentObjKey");
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:tw.com.mt.TopicAPIDemo.java

/**
 * Default constructor.// w  ww  .  ja v  a 2s. co  m
 */
public TopicAPIDemo() {
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(propertyFile));
        this.projObjKey = config.getInt("projObjKey");
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:uk.co.gidley.jmxmonitor.RegistryManager.java

private static CompositeConfiguration readConfiguration(String configurationFile)
        throws InitialisationException {
    // Read configuration file
    CompositeConfiguration config = new CompositeConfiguration();
    config.setThrowExceptionOnMissing(true);
    try {/*from   w ww . j ava  2s.  co m*/
        config.addConfiguration(new PropertiesConfiguration(configurationFile));
    } catch (ConfigurationException e) {
        logger.error("{}", e);
        throw new InitialisationException(e);
    }
    return config;
}

From source file:umich.ms.batmass.gui.viewers.map2d.options.Map2DOptions.java

/**
 * The combined config = current user config + defaults for non-specified properties.
 * TODO: instead of re-reading user config every time, it would be better
 *       to set up Commons Configuration listeners on the userfile.
 * @return even if reading user config fails, will return default config
 *//*  w  ww  . j av a  2  s. c  om*/
public CompositeConfiguration getConfig() {

    // try loading user config
    FileConfiguration userConfig = null;
    try {
        userConfig = BmConfig.forClass(BaseMap2D.class);
    } catch (ConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    // the order of adding configurations to combined configuration is important
    // whoever is added first "shadows" the same key in all subsequently added
    // configuraions. Thus, add the DEFAULTs at the very end
    if (userConfig != null) {
        compositeConfig.addConfiguration(userConfig);
    }
    compositeConfig.addConfiguration(defaultConfig);

    return compositeConfig;
}

From source file:umich.ms.batmass.gui.viewers.map2d.options.Map2DOptionsPanel.java

Map2DOptionsPanel(Map2DOptionsOptionsPanelController controller) {
    this.controller = controller;
    this.config = new CompositeConfiguration();
    initComponents();// www.  ja  v  a 2s .  c  o m
    colorList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (colorList.getSelectedValuesList().size() > 0) {
                btnChangeColor.setEnabled(true);
                btnMoveColorUp.setEnabled(true);
                btnMoveDown.setEnabled(true);
                btnRemoveColor.setEnabled(true);
            } else {
                btnChangeColor.setEnabled(false);
                btnMoveColorUp.setEnabled(false);
                btnMoveDown.setEnabled(false);
                btnRemoveColor.setEnabled(false);
            }
        }
    });
}

From source file:velo.common.SysConf.java

/**
 * Returns a Configuration object for managing system configuration properties
 * @return Configuration object//from w w  w.j a  va 2s  .  co  m
 */
public static Configuration getSysConf() {
    if (staticConfig == null) {
        try {
            System.out.println("(!)Factoring Global Configuration Object...");
            //URL iniConf = SysConf.class.getClassLoader().getResource(veloINIConfFileName);
            //URL xmlConf = SysConf.class.getClassLoader().getResource(veloXMLConfFileName);

            //String xmlConfFile = System.getProperty("veloSysDir") + "/conf/" + veloXMLConfFileName;
            //String iniConfFile = System.getProperty("veloSysDir") + "/conf/" + veloINIConfFileName;

            /*
            if ( (iniConf == null) || (xmlConf == null) ) {
                System.err.println("Could not load configuration files, dying...");
                return null;
            }
             */

            //01-jul-07(Asaf), Removed root conf, it is just another file that is accessible by the user and is not neccessary
            //Only got two conf files, added them by code
            //factory = new ConfigurationFactory(sysconf.getFile());
            //Configuration config = factory.getConfiguration();

            CompositeConfiguration config = new CompositeConfiguration();
            config.setDelimiterParsingDisabled(true);
            config.setListDelimiter("|".charAt(0));
            config.setDelimiter("|".charAt(0));

            //for tests
            //config.addConfiguration(new PropertiesConfiguration("c:/temp/velo/velo_sys/conf/velo_config.ini"));
            //config.addConfiguration(new XMLConfiguration("c:/temp/velo/velo_sys/conf/velo_config.xml"));

            String iniConfFile = getVeloINIConfFileName();
            String xmlConfFile = getVeloXMLConfFileName();
            String xmlConfExtFile = getVeloExtXMLConfFileName();

            config.addConfiguration(new PropertiesConfiguration(iniConfFile));
            XMLConfiguration xmlConf = new XMLConfiguration(xmlConfFile);
            XMLConfiguration xmlExtConf = new XMLConfiguration(xmlConfExtFile);
            xmlConf.setDelimiterParsingDisabled(true);
            xmlConf.setListDelimiter("|".charAt(0));
            xmlConf.setDelimiter("|".charAt(0));

            xmlExtConf.setDelimiterParsingDisabled(true);
            xmlExtConf.setListDelimiter("|".charAt(0));
            xmlExtConf.setDelimiter("|".charAt(0));

            config.addConfiguration(xmlConf);
            config.addConfiguration(xmlExtConf);

            //TODO: Fix this for JBOSS
            //config.addConfiguration(new PropertiesConfiguration(iniConf.getFile()));
            //config.addConfiguration(new XMLConfiguration(xmlConf.getFile()));

            return config;
        } catch (ConfigurationException ce) {
            System.out.println("Could not read ROOT configuration file due to: " + ce.getMessage());
            return null;
        }
    }

    return staticConfig;

}