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.tools.scribe.fb.FacebookClientTest.java

/**
 * Initialize the test.//ww w .  j a va2s  .  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));

    // Test if parameters are set
    final ConfigProperties properties = dispatcher.getCommon("facebook");

    // Create tokens & login
    client.login(properties.getConfigString("key"), properties.getConfigString("secret"),
            dispatcher.getDatas().resolve("test-tokens/facebook.token"),
            dispatcher.getVCodeFactory().create("[" + getClass().getName() + "] "));
}

From source file:com.referencelogic.xmlormupload.main.XmlormuploadMain.java

public void run() {
    try {/*from ww  w  .j ava  2s  . c  o  m*/
        XMLConfiguration config = new XMLConfiguration(configFileName);
        String sourceDir = config.getString("source.path");
        List allowedExtensions = config.getList("source.extensions");
        int poolSize = config.getInt("threadpool.size");

        String groovySourceDir = config.getString("domainclasses.path");
        List groovyAllowedExtensions = config.getList("domainclasses.extensions");

        if (isDebugging) {
            log.debug("Loaded configuration successfully. Reading groovy class list from: " + groovySourceDir
                    + " with allowed extensions " + groovyAllowedExtensions);
        }

        if (isDebugging) {
            log.debug("Loaded configuration successfully. Reading file list from: " + sourceDir
                    + " with allowed extensions " + allowedExtensions);
        }
        Iterator iter = FileUtils.iterateFiles(new File(sourceDir),
                (String[]) allowedExtensions.toArray(new String[allowedExtensions.size()]), true);
        if (poolSize < 1) {
            poolSize = 5;
        }

        exec = Executors.newFixedThreadPool(poolSize);

        GroovyClassLoader gcl = new GroovyClassLoader();

        ClassLoader ojcl = Thread.currentThread().getContextClassLoader();

        boolean allFilesResolved = false;
        while (!allFilesResolved) {
            Iterator groovyIter = FileUtils.iterateFiles(new File(groovySourceDir),
                    (String[]) groovyAllowedExtensions.toArray(new String[groovyAllowedExtensions.size()]),
                    true);

            allFilesResolved = true;

            while (groovyIter.hasNext()) {
                File groovyFile = (File) groovyIter.next();
                log.info("Trying to parse file " + groovyFile);
                try {
                    Class clazz = gcl.parseClass(groovyFile);
                } catch (IOException ioe) {
                    log.error("Unable to read file " + groovyFile + " to parse class ", ioe);
                } catch (Exception e) {
                    log.error("Unable to parse file " + groovyFile + " ex:" + e);
                    allFilesResolved = false;
                }
            }

        }

        Thread.currentThread().setContextClassLoader(gcl);

        Configuration hibernateConfig = new Configuration();

        SessionFactory sf;
        if (!matchRegex) {
            sf = hibernateConfig.configure(new File("hibernate.config.xml")).buildSessionFactory();
        } else {
            sf = hibernateConfig.configure(new File("hibernate.update.config.xml")).buildSessionFactory();
        }

        log.info("Opened session");

        while (iter.hasNext()) {
            File file = (File) iter.next();
            String filePath = "";
            try {
                filePath = file.getCanonicalPath();
                log.debug("Canonical path being processed is: " + filePath);
            } catch (IOException ioe) {
                log.warn("Unable to get canonical path from file", ioe);
            }
            log.debug("Is matchRegex true? " + matchRegex);
            log.debug("Does filePath match regexStr?" + filePath.matches(matchRegexStr));
            if ((!matchRegex) || (matchRegex && filePath.matches(matchRegexStr))) {
                exec.execute(new Xmlormuploader(file, config, gcl, sf));
            }
        }

        exec.shutdown();
        try {
            while (!exec.isTerminated()) {
                exec.awaitTermination(30, TimeUnit.SECONDS);
            }
        } catch (InterruptedException ie) {
            // Do nothing, going to close database connection anyway        
        }

        sf.close();

    } catch (ConfigurationException cex) {
        log.fatal("Unable to load config file " + configFileName + " to determine configuration.", cex);
    }
}

From source file:com.vaushell.superpipes.tools.scribe.tumblr.TumblrClientTest.java

/**
 * Initialize the test.//from  www . j av  a2s .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));

    // Test if parameters are set
    final ConfigProperties properties = dispatcher.getCommon("tumblr");

    blogname = properties.getConfigString("blogname");

    // Create tokens & login
    client.login(properties.getConfigString("key"), properties.getConfigString("secret"),
            dispatcher.getDatas().resolve("test-tokens/tumblr.token"),
            dispatcher.getVCodeFactory().create("[" + getClass().getName() + "] "));
}

From source file:com.dfki.av.sudplan.Configuration.java

/**
 * Initialize the {@link XMLConfiguration} for the application.
 *
 * @return the {@link #XML_CONFIG} to return.
 *//* w  w w.  j a v  a  2  s . c o m*/
private static XMLConfiguration initConfig() {
    log.debug("Init sudplan3D user home...");
    String userHomeDir = VisSettings.USER_HOME_DIR;

    log.info("Init sudplan3D configuration...");
    // Check whether the sudplan3D config file already exists.
    final File userConfigFile = new File(userHomeDir + "/config/sudplan3D.xml");
    if (!userConfigFile.exists()) {
        log.debug("No configuration file existing.");
        installConfigFile(userConfigFile, userHomeDir, userHomeDir);
    } else {
        log.debug("Configuration file existing. Checking version ...");
        if (!isConfigFileSupported(userConfigFile)) {
            log.debug("Configuration file not supported.");
            log.debug("Delete old configuration file.");
            boolean deleted = userConfigFile.delete();
            if (deleted) {
                installConfigFile(userConfigFile, userHomeDir, userHomeDir);
            } else {
                log.error("Could not delete file {}", userConfigFile.getAbsolutePath());
                log.warn("Using old configuration file.");
            }
        } else {
            log.debug("Configuration file supported.");
        }
    }

    XMLConfiguration xmlConfig = null;
    try {
        xmlConfig = new XMLConfiguration(userConfigFile);
        xmlConfig.setAutoSave(true);
        for (Iterator<String> it = xmlConfig.getKeys(); it.hasNext();) {
            String key = it.next();
            log.debug("{} : {}", key, xmlConfig.getString(key));
        }
    } catch (ConfigurationException ex) {
        log.error(ex.toString());
    }
    return xmlConfig;
}

From source file:com.vaushell.superpipes.nodes.fb.N_FB_PostTest.java

/**
 * Initialize the dispatcher before every test.
 *
 * @throws Exception/* w  w w  .ja  va2 s  .  com*/
 */
@BeforeMethod
public void loadDispatcher() 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 = new Dispatcher();
    dispatcher.init(config, pDatas, new VC_FileFactory(pDatas));
}

From source file:com.vaushell.superpipes.tools.scribe.twitter.TwitterClientTest.java

/**
 * Initialize the test./*from  w  w  w .j  av a 2  s .  c  om*/
 *
 * @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));

    final ConfigProperties properties = dispatcher.getCommon("twitter");

    // Create tokens & login for client 1
    client1.login(properties.getConfigString("key"), properties.getConfigString("secret"),
            dispatcher.getDatas().resolve("test-tokens/twitter.token"),
            dispatcher.getVCodeFactory().create("[" + getClass().getName() + "] "));

    // Create tokens & login for client 2
    client2.login(properties.getConfigString("key"), properties.getConfigString("secret"),
            dispatcher.getDatas().resolve("test-tokens/twitter2.token"),
            dispatcher.getVCodeFactory().create("[" + getClass().getName() + "] "));
}

From source file:fr.openfarm.jmx.utils.ProxyConfig.java

@Override
public void afterPropertiesSet() throws Exception {
    log.info("set Up Proxy Configuration");
    jmxAccess = new HashMap<String, JmxLoginPass>();
    String fileName = System.getProperty("configFilePath");
    if (System.getProperty("configFilePath") != null) {
        try {/* w w w. j a  v  a2 s . c  o  m*/
            XMLConfiguration xmlConfiguration = new XMLConfiguration(fileName);
            SubnodeConfiguration accessList = xmlConfiguration.configurationAt("accessList");
            List<HierarchicalConfiguration> loginPassConfs = accessList.configurationsAt("accessConf");
            for (HierarchicalConfiguration loginPassConf : loginPassConfs) {
                JmxLoginPass jmxLoginPass = new JmxLoginPass();
                jmxLoginPass.setLogin(loginPassConf.getString("login"));
                jmxLoginPass.setPassword(loginPassConf.getString("password"));
                jmxAccess.put(loginPassConf.getString("key"), jmxLoginPass);
            }
        } catch (Exception e) {
            log.error("Error while reading conf file : " + fileName, e);
        }
    } else {
        log.info("no configuration given to the jvm by param -DconfigFilePath");
    }

}

From source file:cirad.cgh.vcf2fasta.Vcf2fastaUI.java

private XMLConfiguration initConfig() {
    System.out.println("INIT");
    try {/*from   w  w  w .java2s  .  co m*/
        File base = this.getSession().getService().getBaseDirectory();
        File webinf = new File(base, "WEB-INF");
        File tmp = new File(base, "tmp");
        if (!tmp.exists())
            tmp.mkdirs();

        XMLConfiguration config = new XMLConfiguration(new File(webinf, "config.xml"));

        config.setProperty("base", base.getAbsolutePath());

        config.setExpressionEngine(new XPathExpressionEngine());

        return config;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:at.co.malli.relpm.data.SettingsProvider.java

/**
 * Sets up the object. This is only called one time when getInstance() is called the first time.
 *//*from www .jav  a 2s.  co m*/
public SettingsProvider() {
    try {
        defaults = new XMLConfiguration(defaultsFilename);
        user = new XMLConfiguration(userconfigFilename);
    } catch (ConfigurationException ex) {
        if (ex.getMessage().equals("Cannot locate configuration source " + userconfigFilename)) {
            logger.trace(userconfigFilename + " not found... Creating default...");
            createDefaultConfig();
        } else {
            logger.error(ex.getMessage());
            ExceptionDisplayer.showErrorMessage(ex);
        }
    }
    config.addConfiguration(user, true);
    config.addConfiguration(defaults, false);
}

From source file:co.turnus.generic.AbstractConfigurable.java

protected void loadConfiguration(File file) {
    try {/*from   w w  w .j  a v a  2s. c  om*/
        configuration = new XMLConfiguration(file);
    } catch (ConfigurationException e) {
        throw new TurnusRuntimeException("Error while loading the configuration to " + file.getAbsolutePath());
    }
}