List of usage examples for org.apache.commons.configuration Configuration getBoolean
boolean getBoolean(String key);
From source file:com.discursive.jccook.configuration.TypedConfigurationExample.java
public static void main(String[] args) throws Exception { Configuration config = new PropertiesConfiguration("test.properties"); System.out.println("Speed: " + config.getFloat("speed")); System.out.println("Names: " + config.getList("names")); System.out.println("Correct: " + config.getBoolean("correct")); }
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 ww.j ava 2s .co 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(); } }
From source file:com.manydesigns.elements.configuration.CommonsConfigurationFunctions.java
public static boolean getBoolean(Configuration configuration, String key) { return configuration.getBoolean(key); }
From source file:com.springrts.springls.accounts.Activator.java
private static AccountsService createAccountsService(Context context) { AccountsService accountsService = null; Configuration conf = context.getService(Configuration.class); boolean lanMode = conf.getBoolean(ServerConfiguration.LAN_MODE); boolean useDatabase = conf.getBoolean(ServerConfiguration.USE_DATABASE); if (lanMode) { accountsService = new LanAccountsService(); } else if (useDatabase) { accountsService = new JPAAccountsService(); } else {/*from w ww . ja va 2s. c o m*/ accountsService = new FSAccountsService(); } return accountsService; }
From source file:com.cisco.oss.foundation.monitoring.RMIRegistryManager.java
/** * Starts rmiregistry on the specified port. If property * "service.monitor.inProcess" is set to true in configSchema.xml, * then an in-process rmiregistry is started. * Otherwise rmiregistry will be started in a seperate process. * * @param port on which the rmiregistry needs to be started * @return true if successful or it is already started, false otherwise *//*from ww w .ja v a 2s . c om*/ public static boolean startRMIRegistry(Configuration configuration, int port) { if (isRMIRegistryRunning(configuration, port)) return true; if (configuration.getBoolean(FoundationMonitoringConstants.IN_PROC_RMI)) { return startInProcRMIRegistry(port); } else { return startOutProcRMIRegistry(configuration, port); } }
From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerOptions.java
private static void setOutputPath(Configuration conf, String customPath) { // store the root path for the output. File outPath = null;/*from www.j av a 2 s .co m*/ boolean traceProject = conf.getBoolean(CREATE_TRACE_PROJECT); if (customPath != null && !customPath.isEmpty()) { outPath = new File(customPath); } else { String project = conf.getString(ORCC_PROJECT); IProject pojo = EcoreHelper.getProject(project); outPath = pojo.getRawLocation().makeAbsolute().toFile(); outPath = new File(outPath, "turnus"); if (traceProject) { outPath = new File(outPath, "traces"); } else { outPath = new File(outPath, "profiling"); } } if (traceProject) { String trace = conf.getString(TRACE_PROJECT_NAME); // make path os friendly... trace = trace.replace(" ", "_"); File tmpPath = new File(outPath, trace); if (tmpPath.exists()) { tmpPath = TurnusUtils.findNextAvailable(outPath, trace, "_v", 2); } outPath = tmpPath; } conf.setProperty(OUTPUT_PATH, outPath.getAbsolutePath()); }
From source file:com.cisco.oss.foundation.message.RabbitMQMessagingFactory.java
static void connect() { try {/*from w w w . j a va 2 s.c o m*/ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(true); connectionFactory.setTopologyRecoveryEnabled(true); Configuration configuration = ConfigurationFactory.getConfiguration(); Configuration subsetBase = configuration.subset("service.rabbitmq"); Configuration subsetSecurity = subsetBase.subset("security"); int requestHeartbeat = subsetBase.getInt("requestHeartbeat", 10); connectionFactory.setRequestedHeartbeat(requestHeartbeat); String userName = subsetSecurity.getString("userName"); String password = subsetSecurity.getString("password"); boolean isEnabled = subsetSecurity.getBoolean("isEnabled"); final Map<String, Map<String, String>> serverConnections = ConfigUtil .parseComplexArrayStructure("service.rabbitmq.connections"); final ArrayList<String> serverConnectionKeys = Lists.newArrayList(serverConnections.keySet()); Collections.sort(serverConnectionKeys); if (isEnabled) { connectionFactory.setUsername(userName); connectionFactory.setPassword(password); } List<Address> addresses = new ArrayList<>(5); for (String serverConnectionKey : serverConnectionKeys) { Map<String, String> serverConnection = serverConnections.get(serverConnectionKey); String host = serverConnection.get("host"); int port = Integer.parseInt(serverConnection.get("port")); addresses.add(new Address(host, port)); // connectionFactory.setHost(host); // connectionFactory.setPort(Integer.parseInt(port)); } Address[] addrs = new Address[0]; connection = connectionFactory.newConnection(addresses.toArray(addrs)); connection.addBlockedListener(new BlockedListener() { public void handleBlocked(String reason) throws IOException { LOGGER.error("RabbitMQ connection is now blocked. Port: {}, Reason: {}", connection.getPort(), reason); IS_BLOCKED.set(true); } public void handleUnblocked() throws IOException { LOGGER.info("RabbitMQ connection is now un-blocked. Port: {}", connection.getPort()); IS_BLOCKED.set(false); } }); connection.addShutdownListener(new ShutdownListener() { @Override public void shutdownCompleted(ShutdownSignalException cause) { LOGGER.error("Connection shutdown detected. Reason: {}", cause.toString(), cause); } }); IS_CONNECTED.set(true); INIT_LATCH.countDown(); } catch (Exception e) { LOGGER.error("can't create RabbitMQ Connection: {}", e, e); // triggerReconnectThread(); throw new QueueException(e); } }
From source file:com.springrts.springls.bans.Activator.java
private BanService createBanService(Context context) { BanService banService = null;/* w ww . j av a 2 s . c o m*/ Configuration conf = context.getService(Configuration.class); boolean lanMode = conf.getBoolean(ServerConfiguration.LAN_MODE); if (!lanMode) { try { banService = new JPABanService(); } catch (Exception pex) { log.warn("Failed to access database for ban entries," + " bans are not supported!", pex); } } if (banService == null) { banService = new DummyBanService(); } return banService; }
From source file:com.springrts.springls.accounts.Activator.java
@Override public void start(BundleContext context) { Context springLsContext = Context.getService(context, Context.class); AccountsService accounts = createAccountsService(springLsContext); // switch to LAN mode if user accounts information is not present if (!accounts.isReadyToOperate()) { Configuration conf = springLsContext.getService(Configuration.class); assert (conf.getBoolean(ServerConfiguration.LAN_MODE)); log.error("Accounts service is not ready, shutting down the server"); springLsContext.getServerThread().closeServerAndExit(); }/*w w w.j av a 2 s . c o m*/ accounts.receiveContext(springLsContext); accounts.loadAccounts(); springLsContext.setAccountsService(accounts); context.registerService(new String[] { AccountsService.class.getName(), Updateable.class.getName() }, accounts, null); }
From source file:com.cisco.oss.foundation.directory.config.ServiceDirectoryConfigTest.java
@Test public void testGetProperty() { Configuration config = ServiceDirectory.getServiceDirectoryConfig(); assertFalse(config.getBoolean("ddd")); assertTrue(config.getDouble("notexists", 89.1) == 89.1); try {/*from w w w.j av a 2 s .c o m*/ config.getDouble("notexists"); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); } assertFalse(config.containsKey("not_property")); }