List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration getSection
public SubnodeConfiguration getSection(String name)
From source file:org.davidmason.zayf.rest.ServerProxyImpl.java
private void loadZanataUserConfig() { File userConfig = new File(System.getProperty("user.home"), DEFAULT_CONFIG_LOCATION); System.out.println("Config file: " + userConfig.getAbsolutePath()); try {/* w w w .ja v a 2 s. com*/ HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(userConfig); SubnodeConfiguration serverConfig = config.getSection("servers"); DataConfiguration dataConfig = new DataConfiguration(serverConfig); servers = getServerList(dataConfig); } catch (ConfigurationException e) { System.out.println("Failed to load configuration from " + userConfig.getAbsolutePath()); e.printStackTrace(); } }
From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java
/** * Read the Server settings from a INI Configuration file. * * @param configReader The initialized configuration reader to read * the server configuration from file. * @return True if everything was read in correctly otherwise false. *//* ww w. j av a2s. co m*/ @SuppressWarnings("unchecked") protected boolean readServersFromConfig(final HierarchicalINIConfiguration configReader) { final Map<String, ServerConfiguration> servers = new HashMap<String, ServerConfiguration>(); // Read in and process the servers if (!configReader.getRootNode().getChildren("servers").isEmpty()) { final SubnodeConfiguration serversNode = configReader.getSection("servers"); for (final Iterator<String> it = serversNode.getKeys(); it.hasNext();) { final String key = it.next(); // Find the prefix (aka server name) on urls if (key.endsWith(".url")) { String prefix = key.substring(0, key.length() - ".url".length()); final String name = prefix.substring(0, prefix.length() - 1); final String url = serversNode.getString(prefix + ".url"); final String username = serversNode.getString(prefix + ".username"); // Check that a url was specified if (url == null) { command.printError(ClientUtilities.getMessage("NO_SERVER_URL_MSG", name), false); return false; } // Create the Server Configuration final ServerConfiguration serverConfig = new ServerConfiguration(); serverConfig.setName(name); serverConfig.setUrl(url); serverConfig.setUsername(username); servers.put(name, serverConfig); } // Just the default server name else if (key.equals(Constants.DEFAULT_SERVER_NAME)) { // Create the Server Configuration final ServerConfiguration serverConfig = new ServerConfiguration(); serverConfig.setName(key); serverConfig.setUrl(serversNode.getString(key)); serverConfig.setUsername(serversNode.getString(key + "..username")); servers.put(Constants.DEFAULT_SERVER_NAME, serverConfig); } } } else { // Add the default server config to the list of server configurations final ServerConfiguration config = new ServerConfiguration(); config.setName(Constants.DEFAULT_SERVER_NAME); config.setUrl("http://localhost:8080/TopicIndex/"); servers.put(Constants.DEFAULT_SERVER_NAME, config); } // Add the servers to the client configuration clientConfig.setServers(servers); return true; }
From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java
/** * Read the Zanata Server settings from a INI Configuration file. * * @param configReader The initialized configuration reader to read * the server configuration from file. * @return True if everything was read in correctly otherwise false. */// w ww . j a v a2 s . c om @SuppressWarnings("unchecked") protected boolean readZanataDetailsFromConfig(final HierarchicalINIConfiguration configReader) { // Read in the zanata server information final Map<String, ZanataServerConfiguration> zanataServers = new HashMap<String, ZanataServerConfiguration>(); // Read in and process the servers if (!configReader.getRootNode().getChildren("zanata").isEmpty()) { final SubnodeConfiguration serversNode = configReader.getSection("zanata"); for (final Iterator<String> it = serversNode.getKeys(); it.hasNext();) { final String key = it.next(); // Find the prefix (aka server name) on urls if (key.endsWith(".url")) { String prefix = key.substring(0, key.length() - ".url".length()); final String name = prefix.substring(0, prefix.length() - 1); final String url = serversNode.getString(prefix + ".url"); final String username = serversNode.getString(prefix + ".username"); final String token = serversNode.getString(prefix + ".key"); final boolean cache = serversNode.getBoolean(prefix + ".cache", true); // Check that a url was specified if (url == null) { command.printError(ClientUtilities.getMessage("NO_ZANATA_SERVER_URL_MSG", name), false); return false; } // Create the Server Configuration final ZanataServerConfiguration serverConfig = new ZanataServerConfiguration(); serverConfig.setName(name); serverConfig.setUrl(url); serverConfig.setUsername(username); serverConfig.setToken(token); serverConfig.setCache(cache); zanataServers.put(name, serverConfig); } } } // Setup the default zanata server if (zanataServers.containsKey(Constants.DEFAULT_SERVER_NAME) && !zanataServers.get(Constants.DEFAULT_SERVER_NAME).getUrl().matches("^(http://|https://).*")) { if (!zanataServers.containsKey(zanataServers.get(Constants.DEFAULT_SERVER_NAME).getUrl())) { command.printError(ClientUtilities.getMessage("NO_ZANATA_SERVER_FOUND_FOR_DEFAULT_SERVER_MSG"), false); return false; } else { final ZanataServerConfiguration defaultConfig = zanataServers.get(Constants.DEFAULT_SERVER_NAME); final ZanataServerConfiguration config = zanataServers.get(defaultConfig.getUrl()); defaultConfig.setUrl(config.getUrl()); defaultConfig.setUsername(config.getUsername()); defaultConfig.setToken(config.getToken()); defaultConfig.setUsername(config.getUsername()); defaultConfig.setCache(config.useCache()); } } clientConfig.setZanataServers(zanataServers); return true; }
From source file:org.loggo.server.KafkaConsumer.java
public void initialize(HierarchicalINIConfiguration props, LinkedBlockingDeque<LogEntry> queue) { SubnodeConfiguration kafkaConsumer = props.getSection("KafkaConsumer"); this.consumerConfig = new ConsumerConfig(asProperties(kafkaConsumer)); SubnodeConfiguration kafka = props.getSection("kafka"); topic = kafka.getString("topic", Defaults.TOPIC); this.queue = queue; }
From source file:org.loggo.server.Server.java
void initialize(HierarchicalINIConfiguration config) throws ConfigurationException, AccumuloException, AccumuloSecurityException { Configuration kafkaConsumerSection = config.getSection("KafkaConsumer"); Configuration serverSection = config.getSection("server"); Configuration accumuloSection = config.getSection("accumulo"); Configuration batchSection = config.getSection("batchwriter"); Configuration kafkaSection = config.getSection("kafka"); ClientConfiguration clientConfig = new ClientConfiguration(accumuloSection); // connect to accumulo, check on the table String username = batchSection.getString("user", Defaults.USER); String password = batchSection.getString("password", Defaults.PASSWORD); String table = batchSection.getString("table", Defaults.TABLE); Instance instance = new ZooKeeperInstance(clientConfig); Connector connector = instance.getConnector(username, new PasswordToken(password.getBytes())); if (!connector.tableOperations().exists(table)) { createTable(connector, table);/* w ww . j av a2 s . com*/ } createTopic(kafkaConsumerSection.getString("zookeeper.connect"), kafkaSection); LinkedBlockingDeque<LogEntry> queue = new LinkedBlockingDeque<LogEntry>( config.getInt("queue.size", Defaults.QUEUE_SIZE)); this.writer = new Writer(queue, clientConfig, batchSection); ServerBootstrap b = new ServerBootstrap(); // @formatter:off // tcp b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new LoggerReaderInitializer(queue)); // udp Bootstrap bb = new Bootstrap(); bb.group(dgramGroup).channel(NioDatagramChannel.class).handler(new DgramHandler(queue)); // @formatter:on String host = serverSection.getString("host", Defaults.HOST); serverSection.setProperty("host", host); if (host.equals(Defaults.HOST)) { try { serverSection.setProperty("host", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ex) { throw new RuntimeException("Unable to determine local hostname: " + ex.toString()); } } try { int tcpPort = serverSection.getInteger("tcp.port", Defaults.PORT); channel = b.bind(host, tcpPort).sync().channel(); tcpPort = ((InetSocketAddress) channel.localAddress()).getPort(); serverSection.setProperty("tcp.port", tcpPort); int udpPort = serverSection.getInteger("udp.port", Defaults.PORT); Channel channel2 = bb.bind(host, udpPort).sync().channel(); udpPort = ((InetSocketAddress) channel2.localAddress()).getPort(); serverSection.setProperty("udp.port", udpPort); registerInZookeeper(serverSection); } catch (IOException | KeeperException | InterruptedException ex) { throw new RuntimeException(ex); } String zookeeperConnect = kafkaConsumerSection.getString("zookeeper.connect"); if (zookeeperConnect != null) { kafkaConsumer = new KafkaConsumer(); kafkaConsumer.initialize(config, queue); kafkaConsumer.start(); } }
From source file:org.porquebox.core.PorqueBoxMetaData.java
public PorqueBoxMetaData(HierarchicalINIConfiguration data) { for (String sectionName : data.getSections()) { SubnodeConfiguration section = data.getSection(sectionName); Map<String, String> sectionData = new HashMap<String, String>(); for (Iterator<String> keyIter = section.getKeys(); keyIter.hasNext();) { String key = keyIter.next(); String value = (String) section.getProperty(key); sectionData.put(key, value); }//from www . j a v a2 s . c om this.data.put(sectionName, (Object) sectionData); } }
From source file:org.zanata.client.commands.init.UserConfigHandler.java
private List<URL> readServerUrlsFromUserConfig(HierarchicalINIConfiguration config) throws ConfigurationException { SubnodeConfiguration servers = config.getSection("servers"); DataConfiguration dataConfig = new DataConfiguration(servers); List<URL> serverUrls = Lists.newArrayList(); for (Iterator<String> iterator = dataConfig.getKeys(); iterator.hasNext();) { String key = iterator.next(); if (key.endsWith(".url")) { serverUrls.add(dataConfig.get(URL.class, key)); }/*from w ww . j av a 2s . c om*/ } return serverUrls; }
From source file:uk.q3c.krail.core.config.InheritingConfiguration.java
/** * Returns a section specified by {@code sectionName}, or null if none exists. Sections are recognised only be * {@link HierarchicalINIConfiguration}, and any other type of configuration contained within this composite will * be/* w ww .j ava 2s.c o m*/ * ignored. * * @param sectionName * * @return */ public SubnodeConfiguration getSection(String sectionName) { int c = getNumberOfConfigurations(); for (int i = c - 1; i >= 0; i--) { Configuration cfg = getConfiguration(i); if (cfg instanceof HierarchicalINIConfiguration) { HierarchicalINIConfiguration config = (HierarchicalINIConfiguration) cfg; if (config.getSections().contains(sectionName)) { return config.getSection(sectionName); } } } return null; }