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.discursive.jccook.configuration.XmlConfigurationExample.java

public static void main(String[] args) throws Exception {
    String resource = "com/discursive/jccook/configuration/global.xml";
    Configuration config = new XMLConfiguration(resource);
    /* /*from ww w .  ja  v  a2s.  c o  m*/
     * ========================================================================
     * 
     * Copyright 2005 Tim O'Brien.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     * 
     *   http://www.apache.org/licenses/LICENSE-2.0
     * 
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * 
     * ========================================================================
     */

    List startCriteria = config.getList("start-criteria.criteria");
    int horsepower = config.getInt("horsepower");
}

From source file:com.vaushell.sampleexec.App.java

/**
 * Main method.//from   w  ww  .  j  ava  2s .  com
 *
 * @param args Command line arguments
 * @throws ConfigurationException
 */
public static void main(final String... args) throws ConfigurationException {
    // My config
    final XMLConfiguration config;
    if (args.length > 0) {
        config = new XMLConfiguration(args[0]);
    } else {
        config = new XMLConfiguration("conf/configuration.xml");
    }

    // Declare
    final MyExemple ex = new MyExemple();

    // Init
    ex.init(config);

    // Show first page
    ex.showFirstPage();

}

From source file:fm.last.irccat.IRCCat.java

public static void main(String[] args) throws Exception {
    try {//from   ww w.  j  a va 2s  .  c o  m
        if (args.length == 0) {
            System.out.println("first param should be config file");
            System.exit(-1);
        }
        XMLConfiguration c = null;
        try {
            c = new XMLConfiguration(args[0]);
        } catch (ConfigurationException cex) {
            System.err.println("Configuration error, check config file");
            cex.printStackTrace();
            System.exit(1);
        }

        IRCCat bot = new IRCCat(c);

        // listen for stuff and send it to irc:
        ServerSocket serverSocket = null;
        InetAddress inet = null;
        try {
            if (bot.getCatIP() != null)
                inet = InetAddress.getByName(bot.getCatIP());
        } catch (UnknownHostException ex) {
            System.out.println("Could not resolve config cat.ip, fix your config");
            ex.printStackTrace();
            System.exit(2);
        }

        try {
            serverSocket = new ServerSocket(bot.getCatPort(), 0, inet);
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + bot.getCatPort());
            System.exit(1);
        }

        System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort());

        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                // System.out.println("Connection on catport from: "
                // + clientSocket.getInetAddress().toString());
                CatHandler handler = new CatHandler(clientSocket, bot);
                handler.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:mpaf.Main.java

public static void main(String[] args) {
    // Apache commons configuration
    CompositeConfiguration config = new CompositeConfiguration();
    try {/*w  ww  .j ava2s.c om*/

        XMLConfiguration user = new XMLConfiguration("mpaf.properties.user.xml");
        XMLConfiguration defaults = new XMLConfiguration("mpaf.properties.default.xml");

        // careful configuration is read from top to bottom if you want a
        // config to overwrite the user config, add it as first element
        // also make it optional to load, check if the file exists and THEN
        // load it!
        if (user != null)
            config.addConfiguration(user);
        config.addConfiguration(defaults);
    } catch (ConfigurationException e1) {
        e1.printStackTrace();
    }

    SqlHandler sqlH = null;
    sqlH = new SqlHandler();
    sqlH.setDbtype(config.getString("db.type", "sqlite"));
    sqlH.setDbhost(config.getString("db.host", "127.0.0.1"));
    sqlH.setDbport(config.getString("db.port", "3306"));
    sqlH.setDbname(config.getString("db.name", "mpaf.db"));
    sqlH.setDbuser(config.getString("db.user"));
    sqlH.setDbpass(config.getString("db.password"));

    IceModel iceM = new IceModel(config);
    IceController iceC;
    try {
        iceC = new IceController(iceM, sqlH.getConnection());
    } catch (ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return;
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return;
    }

    Server server = new Server();

    ConsoleParser parser = new ConsoleParser(iceC, iceM, server);
    new Thread(parser).start();

    // will be called once a shutdown event is thrown(like ctrl+c or sigkill
    // etc.)
    ShutdownThread shutdown = new ShutdownThread(iceC);
    Runtime.getRuntime().addShutdownHook(new Thread(shutdown));

    if (config.getBoolean("jetty.enabled")) {
        SocketConnector connector = new SocketConnector();
        connector.setPort(config.getInt("jetty.ports.http", 10001));
        server.setConnectors(new Connector[] { connector });

        ServletContextHandler servletC = new ServletContextHandler(ServletContextHandler.SESSIONS);
        servletC.setContextPath("/");
        servletC.setAttribute("sqlhandler", sqlH);
        servletC.setAttribute("iceController", iceC);
        servletC.setAttribute("iceModel", iceM);
        // To add a servlet:
        ServletHolder holder = new ServletHolder(new DefaultCacheServlet());
        holder.setInitParameter("cacheControl", "max-age=3600,public");
        holder.setInitParameter("resourceBase", "web");
        servletC.addServlet(holder, "/");
        servletC.addServlet(new ServletHolder(new ServerList()), "/serverlist");
        servletC.addServlet(new ServletHolder(new ChannelList()), "/channellist");
        servletC.addServlet(new ServletHolder(new HandlerList()), "/handlerlist");
        servletC.addServlet(new ServletHolder(new ServerManage()), "/servermanage");
        servletC.addServlet(new ServletHolder(new Login()), "/login");
        servletC.addServlet(new ServletHolder(new Logout()), "/logout");
        servletC.addServlet(new ServletHolder(new UserCreate()), "/usercreate");
        servletC.addServlet(new ServletHolder(new UserInfo()), "/userinfo");
        servletC.addServlet(new ServletHolder(new UserList()), "/userlist");

        server.setHandler(servletC);
        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:com.ls.zencat.ZenCat.java

public static void main(String[] args) throws Exception {
    try {/*from  w  ww. ja  v  a  2s .  co  m*/
        if (args.length == 0) {
            System.out.println("first param should be config file");
            System.exit(-1);
        }
        XMLConfiguration c = null;
        try {
            c = new XMLConfiguration(args[0]);
        } catch (ConfigurationException cex) {
            System.err.println("Configuration error, check config file");
            cex.printStackTrace();
            System.exit(1);
        }

        ZenCat bot = new ZenCat(c);

        // listen for stuff and send it to irc:
        ServerSocket serverSocket = null;
        InetAddress inet = null;
        try {
            if (bot.getCatIP() != null)
                inet = InetAddress.getByName(bot.getCatIP());
        } catch (UnknownHostException ex) {
            System.out.println("Could not resolve config cat.ip, fix your config");
            ex.printStackTrace();
            System.exit(2);
        }

        try {
            serverSocket = new ServerSocket(bot.getCatPort(), 0, inet);
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + bot.getCatPort());
            System.exit(1);
        }

        System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort());

        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                // System.out.println("Connection on catport from: "
                // + clientSocket.getInetAddress().toString());
                CatHandler handler = new CatHandler(clientSocket, bot);
                handler.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:ch.astina.hesperid.agentbundle.Agent.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println("Usage: java -server agentbundle.jar configuration.xml");
        return;//  w  w w.  j  a  va  2s  . c  o  m
    }

    try {
        XMLConfiguration xmlConfiguration = new XMLConfiguration(args[0]);
        Agent agent = new Agent(xmlConfiguration);
        agent.run();
    } catch (ConfigurationException e) {
        logger.error("Error while creating agent", e);
    } catch (Exception e) {
        logger.error("Error while creating agent", e);
    }

    System.setProperty("http.maxConnections", "1");
    System.setProperty("http.keepAlive", "false");
}

From source file:com.knowbout.epg.FakeUpdate.java

public static void main(String[] args) {
    String configFile = "/etc/knowbout.tv/epg.xml";
    int nextarg = 0;
    if (args.length > 1) {
        if (args.length == 3 && args[0].equals("-config")) {
            configFile = args[1];//from  w w  w  .  j  av  a 2s.co m
            nextarg = 2;
        } else {
            System.err.println(
                    "Usage: java " + FakeUpdate.class.getName() + " [-config <xmlfile>] <program title>");
            System.exit(1);
        }
    }
    if (args.length <= nextarg) {
        System.err
                .println("Usage: java " + FakeUpdate.class.getName() + " [-config <xmlfile>] <program title>");
        System.exit(1);
    }
    String title = args[nextarg];

    try {
        XMLConfiguration config = new XMLConfiguration(configFile);

        HashMap<String, String> hibernateProperties = new HashMap<String, String>();
        Configuration database = config.subset("database");
        hibernateProperties.put(Environment.DRIVER, database.getString("driver"));
        hibernateProperties.put(Environment.URL, database.getString("url"));
        hibernateProperties.put(Environment.USER, database.getString("user"));
        hibernateProperties.put(Environment.PASS, database.getString("password"));
        hibernateProperties.put(Environment.DATASOURCE, null);

        HibernateUtil.setProperties(hibernateProperties);

        Session session = HibernateUtil.openSession();
        Transaction tx = session.beginTransaction();

        String hqlUpdate = "update Program set lastModified = :now where title = :title";
        int updatedEntities = session.createQuery(hqlUpdate).setTimestamp("now", new Date())
                .setString("title", title).executeUpdate();
        tx.commit();
        session.close();

        String alertUrl = config.getString("alertUrl");
        HessianProxyFactory factory = new HessianProxyFactory();
        AlertQueue alerts = (AlertQueue) factory.create(AlertQueue.class, alertUrl);
        alerts.checkAlerts();
    } catch (ConfigurationException e) {
        log.fatal("Configuration error in file " + configFile, e);
    } catch (IOException e) {
        log.fatal("Error downloading or processing EPG information", e);
    }

}

From source file:com.boozallen.cognition.ingest.storm.topology.ConfigurableIngestTopology.java

/**
 * This class takes an XML configuration and builds and submits a storm topology.
 *
 * @throws org.apache.commons.configuration.ConfigurationException
 * @throws ConfigurationException//from w w w. j ava 2  s.co  m
 */
public static void main(String[] args) throws Exception {
    // using config file
    if (args.length != 1) {
        System.err.println("usage: xmlConfigFile");
        System.exit(1);
    }
    XMLConfiguration conf = new XMLConfiguration(args[0]);

    ConfigurableIngestTopology topology = new ConfigurableIngestTopology();
    topology.configure(conf);

    boolean doLocalSubmit = conf.getBoolean(DO_LOCAL_SUBMIT, DO_LOCAL_SUBMIT_DEFAULT);
    if (doLocalSubmit)
        topology.submitLocal(new LocalCluster());
    else
        topology.submit();
}

From source file:com.github.ipaas.ideploy.plugin.util.XmlUtil.java

public static void main(String[] args) throws IOException {
    System.out.println(XmlUtil.getString(
            "D:/Users/TY-Chenql/runtime-EclipseApplication/crs_mave_ice/script/assembly.xml", "id", "sc"));
    try {//from  w ww  .  j  a v a 2  s  . c o  m
        XMLConfiguration config = new XMLConfiguration("D:/Users/TY-Chenql/workspace/crs_mave_ice/pom.xml");
        // ??????
        String str = config.getString("build.plugins.plugin.configuration.descriptors.descriptor");
        // System.out.println(str);
        // // ?.????
        // List<Object> names = config.getList("student.name");
        // System.out.println(Arrays.toString(names.toArray()));
        // // ???a,b,c,d ???
        // List<Object> titles = config.getList("title");
        // System.out.println(Arrays.toString(titles.toArray()));
        // // ? ??[@??] ??
        // String size = config.getString("ball[@size]");
        // System.out.println(size);
        // // ???? ??(??) ??
        // String id = config.getString("student(1)[@id]");
        // System.out.println(id);
        //
        // String go = config.getString("student.name(0)[@go]");
        // System.out.println(go);
        // /**
        // * ? tom [lily, lucy] [abc, cbc, bbc, bbs] 20 2 common1
        // *
        // */
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }

}

From source file:com.knowbout.epg.EPG.java

public static void main(String[] args) {
    String configFile = "/etc/flip.tv/epg.xml";
    boolean sitemaponly = false;
    if (args.length > 0) {
        if (args.length == 2 && args[0].equals("-config")) {
            configFile = args[1];//from   w w w .ja  va 2  s  .  c  o m
        } else if (args.length == 1 && args[0].equals("-sitemaponly")) {
            sitemaponly = true;
        } else {
            System.err.println("Usage: java " + EPG.class.getName() + " [-config <xmlfile>]");
            System.exit(1);
        }
    }

    try {
        XMLConfiguration config = new XMLConfiguration(configFile);

        HashMap<String, String> hibernateProperties = new HashMap<String, String>();
        Configuration database = config.subset("database");
        hibernateProperties.put(Environment.DRIVER, database.getString("driver"));
        hibernateProperties.put(Environment.URL, database.getString("url"));
        hibernateProperties.put(Environment.USER, database.getString("user"));
        hibernateProperties.put(Environment.PASS, database.getString("password"));
        hibernateProperties.put(Environment.DATASOURCE, null);

        HibernateUtil.setProperties(hibernateProperties);

        if (!sitemaponly) {
            //test(config);
            // Get the server configuration to download the content
            Configuration provider = config.subset("provider");
            InetAddress server = InetAddress.getByName(provider.getString("server"));
            File destinationFolder = new File(provider.getString("destinationFolder"));
            String username = provider.getString("username");
            String password = provider.getString("password");
            String remoteDirectory = provider.getString("remoteWorkingDirectory");
            boolean forceDownload = provider.getBoolean("forceDownload");
            Downloader downloader = new Downloader(server, username, password, destinationFolder,
                    remoteDirectory, forceDownload);
            int count = downloader.downloadFiles();
            log.info("Downloaded " + count + " files");
            //         int count = 14;
            if (count > 0) {
                log.info("Processing downloads now.");
                //Get the name of the files to process
                Configuration files = config.subset("files");
                File headend = new File(destinationFolder, files.getString("headend"));
                File lineup = new File(destinationFolder, files.getString("lineup"));
                File stations = new File(destinationFolder, files.getString("stations"));
                File programs = new File(destinationFolder, files.getString("programs"));
                File schedules = new File(destinationFolder, files.getString("schedules"));

                Parser parser = new Parser(config, headend, lineup, stations, programs, schedules);
                parser.parse();
                log.info("Finished parsing EPG Data. Invoking AlertQueue service now.");
                String alertUrl = config.getString("alertUrl");
                HessianProxyFactory factory = new HessianProxyFactory();
                AlertQueue alerts = (AlertQueue) factory.create(AlertQueue.class, alertUrl);
                alerts.checkAlerts();
                log.info("Updating sitemap");
                updateSitemap(config.getString("sitemap", "/usr/local/webapps/search/sitemap.xml.gz"));
                log.info("Exiting EPG now.");
            } else {
                log.info("No files were downloaded, so don't process the old files.");
            }
        } else {
            log.info("Updating sitemap");
            updateSitemap(config.getString("sitemap", "/usr/local/webapps/search/sitemap.xml.gz"));
            log.info("Done updating sitemap");
        }
    } catch (ConfigurationException e) {
        log.fatal("Configuration error in file " + configFile, e);
        e.printStackTrace();
    } catch (UnknownHostException e) {
        log.fatal("Unable to connect to host", e);
        e.printStackTrace();
    } catch (IOException e) {
        log.fatal("Error downloading or processing EPG information", e);
        e.printStackTrace();
    } catch (Throwable e) {
        log.fatal("Unexpected Error", e);
        e.printStackTrace();
    }

}