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(URL url) throws ConfigurationException 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:com.vaushell.superpipes.dispatch.ErrorMailerTest.java

/**
 * Initialize the test.//from   w  w w . j av  a 2  s  .  c o  m
 *
 * @throws Exception
 */
@BeforeClass
public void setUp() throws Exception {
    // My config
    String conf = System.getProperty("conf");
    if (conf == null) {
        conf = "conf-local/test/configuration.xml";
    }

    String datas = System.getProperty("datas");
    if (datas == null) {
        datas = "conf-local/test/datas";
    }

    final XMLConfiguration config = new XMLConfiguration(conf);

    final Path pDatas = Paths.get(datas);
    dispatcher.init(config, pDatas, new VC_FileFactory(pDatas));
}

From source file:com.sinfonier.util.XMLProperties.java

/**
 * Simple XMLProperties Constructor//from   ww  w.j a v a2 s .  com
 * 
 * @param xmlPath Path to XML file
 * @param type ComponentType
 */
public XMLProperties(ComponentType type, String xmlPath) {
    this.componentType = type;
    try {
        xml = new XMLConfiguration(xmlPath);
        xml.setDefaultListDelimiter((char) 0);
        xml.setExpressionEngine(new XPathExpressionEngine());
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:de.unigoettingen.sub.commons.contentlib.servlet.model.ContentServerConfiguration.java

/************************************************************************************
 * get singleton object// w  w  w. java2 s .c om
 ************************************************************************************/
synchronized public static ContentServerConfiguration getInstance() {
    if (instance == null) {
        instance = new ContentServerConfiguration();
        try {
            File file = new File(Util.getBaseFolderAsFile(), "contentServerConfig.xml");
            instance.config = new XMLConfiguration(file);
            instance.config.setReloadingStrategy(new FileChangedReloadingStrategy());
        } catch (ConfigurationException e) {
            LOGGER.error("ConfigurationException occured", e);
            instance.config = new XMLConfiguration();
        }
    }
    return instance;
}

From source file:it.imtech.bookimporter.BookUtilityTest.java

/**
 * Test of getOrderedLanguages method, of class BookUtility.
 *//* w w w . j  a  v a  2s . c  o m*/
public void testGetOrderedLanguages() {
    System.out.println("Test Ordering configuration languages: method -> getOrderedLanguages");
    TreeMap<String, String> en = new TreeMap<String, String>();
    en.put("English", "en");
    en.put("German", "de");
    en.put("Italian", "it");

    TreeMap<String, String> it = new TreeMap<String, String>();
    it.put("Inglese", "en");
    it.put("Italiano", "it");
    it.put("Tedesco", "de");

    TreeMap<String, String> de = new TreeMap<String, String>();
    de.put("Deutsch", "de");
    de.put("English", "en");
    de.put("Italienisch", "it");

    try {
        CustomClassLoader loader = new CustomClassLoader();

        Locale locale = new Locale("en");
        ResourceBundle bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        XMLConfiguration config = new XMLConfiguration(new File(DEBUG_XML));
        TreeMap<String, String> result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(en, result);

        locale = new Locale("it");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(it, result);

        locale = new Locale("de");
        bundle = ResourceBundle.getBundle(RESOURCES, locale, loader);
        config = new XMLConfiguration(new File(DEBUG_XML));
        result = BookUtility.getOrderedLanguages(config, bundle);
        assertEquals(de, result);
    } catch (ConfigurationException e) {
        fail("Ordering Language Test failed: ConfigurationException:- " + e.getMessage());
    }
}

From source file:com.oltpbenchmark.multitenancy.schedule.Schedule.java

private HashMap<Integer, ScheduleEvents> parseEvents() {
    HashMap<Integer, ScheduleEvents> newMap = new HashMap<Integer, ScheduleEvents>();
    try {//from   w  w  w  .  j a va 2 s.  c  om
        // read config file
        XMLConfiguration xmlConfig = new XMLConfiguration(scenarioFile);
        xmlConfig.setExpressionEngine(new XPathExpressionEngine());

        // iterate over all defined events and parse configuration
        int size = xmlConfig
                .configurationsAt(ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY)
                .size();
        for (int i = 1; i < size + 1; i++) {
            SubnodeConfiguration event = xmlConfig.configurationAt(
                    ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY + "[" + i + "]");
            // create settings for a benchmark run
            BenchmarkSettings benchSettings = new BenchmarkSettings(event);

            // get schedule times
            long eventStart = 0, eventStop = -1, eventRepeat = -1;
            if (event.containsKey(ScenarioConfigElements.EVENT_START_KEY))
                eventStart = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_START_KEY));
            else
                LOG.debug("There is no start time defined for an event, it will be started immediately!");
            if (event.containsKey(ScenarioConfigElements.EVENT_REPEAT_KEY))
                eventRepeat = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_REPEAT_KEY));
            if (event.containsKey(ScenarioConfigElements.EVENT_STOP_KEY))
                eventStop = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_STOP_KEY));

            // validate schedule times
            if (eventRepeat > -1 && eventStop == -1 && duration == -1) {
                LOG.fatal(
                        "Infinitely event execution was defined: Repeated event without repeating end and scenario end");
                System.exit(-1);
            }
            if (eventRepeat == 0) {
                LOG.fatal("An Event cannot be repeated simoultaneously (avoid infinite loop)!");
                System.exit(-1);
            }
            if (eventStart > eventStop && eventStop != -1) {
                LOG.fatal("Event cannot be stopped until starting it!");
                System.exit(-1);
            }

            // get tenant IDs
            int firstTenantID = 1, tenantsPerExecution = 1, tenantIdIncement = 1;
            if (event.containsKey(ScenarioConfigElements.FIRST_TENANT_ID_KEY))
                firstTenantID = (event.getInt(ScenarioConfigElements.FIRST_TENANT_ID_KEY));
            if (event.containsKey(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY))
                tenantsPerExecution = (event.getInt(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY));
            if (event.containsKey(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY))
                tenantIdIncement = (event.getInt(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY));

            // validate tenant IDs
            if (tenantsPerExecution < 0) {
                LOG.fatal("Value '" + tenantsPerExecution + "' for tenants per executions is not valid!");
                System.exit(-1);
            }

            // execution times and assign to tenants
            if (duration != -1 && duration < eventStop)
                eventStop = duration;
            int exec = 0;
            long execTime = eventStart;
            while ((execTime <= eventStop) || (eventStop == -1 && exec == 0)) {
                // iterate over all tenants in this execution
                for (int j = 0; j < tenantsPerExecution; j++) {
                    int currentTenantID = firstTenantID + (exec * tenantsPerExecution * tenantIdIncement)
                            + (j * tenantIdIncement);
                    if (!newMap.containsKey(currentTenantID)) {
                        ScheduleEvents tenEvents = new ScheduleEvents();
                        tenEvents.addEvent(execTime, benchSettings);
                        newMap.put(currentTenantID, tenEvents);
                        tenantList.add(currentTenantID);
                    } else
                        newMap.get(currentTenantID).addEvent(execTime, benchSettings);
                }
                if (eventRepeat == -1)
                    break;
                execTime += eventRepeat;
                exec++;
            }
        }
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return newMap;
}

From source file:com.jf.javafx.services.Database.java

@Override
protected void _initService() {
    try {/*  ww w  . ja  v  a2  s .c  o  m*/
        XMLConfiguration c = new XMLConfiguration(app.getConfig("database.properties"));
        c.configurationsAt("databases.database").stream().forEach((t) -> {
            infos.put(t.getString("jndiName"), new DBInfo(t.getString("jndiName"), t.getString("url"),
                    t.getString("username"), t.getString("password"), t.getString("dsProvider")));
        });
    } catch (ConfigurationException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        getDataSource("jdbc/sample").getConnection();
    } catch (SQLException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.vangent.hieos.hl7v2util.acceptor.config.AcceptorConfig.java

/**
 * /*  ww w .j  a  v  a2  s. c  om*/
 * @param configLocation
 * @throws HL7v2UtilException
 */
private void loadConfiguration(String configLocation) throws HL7v2UtilException {
    try {
        logger.info("Loading HL7v2Acceptor configuration from " + configLocation);
        XMLConfiguration xmlConfig = new XMLConfiguration(configLocation);

        this.loadMessageHandlerConfigs(xmlConfig);
        this.loadListenerConfigs(xmlConfig);
    } catch (ConfigurationException ex) {
        throw new HL7v2UtilException("HL7v2AcceptorConfig: Could not load configuration from " + configLocation
                + " " + ex.getMessage());
    }
}

From source file:com.norconex.collector.http.crawler.HttpCrawlerConfigLoader.java

public static HttpCrawlerConfig[] loadCrawlerConfigs(HierarchicalConfiguration xml) {
    try {//  w  w w  .ja  v  a2  s . c om
        XMLConfiguration defaults = ConfigurationUtil.getXmlAt(xml, "crawlerDefaults");
        HttpCrawlerConfig defaultConfig = new HttpCrawlerConfig();
        if (defaults != null) {
            loadCrawlerConfig(defaultConfig, defaults);
        }

        List<HierarchicalConfiguration> nodes = xml.configurationsAt("crawlers.crawler");
        List<HttpCrawlerConfig> configs = new ArrayList<HttpCrawlerConfig>();
        for (HierarchicalConfiguration node : nodes) {
            HttpCrawlerConfig config = (HttpCrawlerConfig) defaultConfig.clone();
            loadCrawlerConfig(config, new XMLConfiguration(node));
            configs.add(config);
        }
        return configs.toArray(new HttpCrawlerConfig[] {});
    } catch (Exception e) {
        throw new HttpCollectorException("Cannot load crawler configurations.", e);
    }
}

From source file:eu.leads.crawler.c4j.LeadsWP5DemoCrawlController.java

private void init() {
    InputStream input = null;/* w w  w .j av a 2s  .  c o  m*/
    try {
        input = new FileInputStream(parametersFile);
        // load a properties file
        properties.load(input);
        config = new XMLConfiguration("/leads/workm30/leads-query-processor/"
                + "nqe/system-plugins/adidas-processing-plugin/" + "adidas-processing-plugin-conf-test.xml");
        DataStoreSingleton.configureDataStore(config);
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:io.viewserver.server.XmlViewServerConfiguration.java

public XmlViewServerConfiguration(String configurationFile) {
    configuration = new CompositeConfiguration();
    try {/*from   w  ww .  ja  v  a 2s  .  c  o m*/
        configuration.addConfiguration(new XMLConfiguration(configurationFile));
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    configuration.addConfiguration(new SystemConfiguration());

    // TODO: get rid of the static variable
    Utils.Configuration = configuration;

    log.info("Using configuration file: {}", configurationFile);
}