List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration getSection
public SubnodeConfiguration getSection(String name)
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests querying the content of the global section. *//*from ww w . j a v a 2 s.c o m*/ @Test public void testGetSectionGlobal() throws ConfigurationException { HierarchicalINIConfiguration config = setUpConfig(INI_DATA_GLOBAL); SubnodeConfiguration section = config.getSection(null); assertEquals("Wrong value of global variable", "testGlobal", section.getString("globalVar")); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether getSection() can deal with duplicate sections. *///from ww w. ja v a 2 s . c om @Test public void testGetSectionDuplicate() { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.addProperty("section.var1", "value1"); config.addProperty("section(-1).var2", "value2"); SubnodeConfiguration section = config.getSection("section"); Iterator<String> keys = section.getKeys(); assertEquals("Wrong key", "var1", keys.next()); assertFalse("Too many keys", keys.hasNext()); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether a duplicate session is merged. *//* w w w .j a va 2 s. c om*/ @Test public void testMergeDuplicateSection() throws ConfigurationException { final String data = "[section]\nvar1 = sec1\n\n" + "[section]\nvar2 = sec2\n"; HierarchicalINIConfiguration config = setUpConfig(data); assertEquals("Wrong value 1", "sec1", config.getString("section.var1")); assertEquals("Wrong value 2", "sec2", config.getString("section.var2")); SubnodeConfiguration sub = config.getSection("section"); assertEquals("Wrong sub value 1", "sec1", sub.getString("var1")); assertEquals("Wrong sub value 2", "sec2", sub.getString("var2")); StringWriter writer = new StringWriter(); config.save(writer); String content = writer.toString(); int pos = content.indexOf("[section]"); assertTrue("Section not found: " + content, pos >= 0); assertTrue("Section found multiple times: " + content, content.indexOf("[section]", pos + 1) < 0); }
From source file:it.jnrpe.server.IniJNRPEConfiguration.java
@Override public void load(final File confFile) throws ConfigurationException { // Parse an ini file ServerSection serverConf = getServerSection(); CommandsSection commandSection = getCommandSection(); try {// w w w. j a v a2s . c o m HierarchicalINIConfiguration confParser = new HierarchicalINIConfiguration(confFile); List<Object> vBindAddresses = confParser.getList("server.bind-address"); if (vBindAddresses != null) { for (Object address : vBindAddresses) { serverConf.addBindAddress((String) address); } } // Defaults accept params String sAcceptParams = confParser.getString("server.accept-params", "true"); serverConf.setAcceptParams( "true".equalsIgnoreCase(sAcceptParams) || "yes".equalsIgnoreCase(sAcceptParams)); serverConf.setPluginPath(confParser.getString("server.plugin-path", ".")); serverConf.setBackLogSize(confParser.getInt("server.backlog-size", ServerSection.DEFAULT_BACKLOG)); // TODO : move this to publicly accessible constants serverConf.setReadTimeout(confParser.getInteger("server.read-timeout", 10)); // TODO : move this to publicly accessible constants serverConf.setWriteTimeout(confParser.getInteger("server.write-timeout", 60)); List<Object> vAllowedAddresses = confParser.getList("server.allow-address"); if (vAllowedAddresses != null) { for (Object address : vAllowedAddresses) { serverConf.addAllowedAddress((String) address); } } SubnodeConfiguration sc = confParser.getSection("commands"); if (sc != null) { for (Iterator<String> it = sc.getKeys(); it.hasNext();) { String sCommandName = it.next(); String sCommandLine = org.apache.commons.lang.StringUtils.join(sc.getStringArray(sCommandName), ","); // first element of the command line is the plugin name String[] vElements = StringUtils.split(sCommandLine, false); String sPluginName = vElements[0]; // Rebuilding the commandline StringBuilder cmdLine = new StringBuilder(); for (int i = 1; i < vElements.length; i++) { cmdLine.append(quoteAndEscape(vElements[i])).append(' '); } commandSection.addCommand(sCommandName, sPluginName, cmdLine.toString()); } } } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException(e); } }
From source file:org.apache.hms.controller.Controller.java
public void parseConfig() { StringBuilder confPath = new StringBuilder(); String confDir = System.getProperty("HMS_CONF_DIR"); if (confDir == null) { confDir = "/etc/hms"; }/*from w ww . j a v a2 s . c o m*/ confPath.append(confDir); confPath.append("/hms.ini"); try { HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration(confPath.toString()); zookeeperAddress = ini.getSection("zookeeper").getString("quorum", null); String user = ini.getSection("zookeeper").getString("user", null); String password = ini.getSection("zookeeper").getString("password", null); if (user != null && password != null) { credential = new StringBuilder().append(user).append(":").append(password).toString(); } } catch (Exception e) { LOG.warn("Invalid HMS configuration file: " + confPath); zookeeperAddress = null; } LOG.info("ZooKeeper Quorum in " + confPath.toString() + ": " + zookeeperAddress); }
From source file:org.apache.tamaya.commons.IniConfigurationFormat.java
@Override public ConfigurationData readConfiguration(String name, InputStream inputStream) { PropertyValue data = PropertyValue.createObject(); data.setMeta("name", name); try {// w ww . j av a 2 s .c om HierarchicalINIConfiguration commonIniConfiguration; File file = new File(name); if (file.exists()) { commonIniConfiguration = new HierarchicalINIConfiguration(file); } else { commonIniConfiguration = new HierarchicalINIConfiguration(new URL(name)); } for (String section : commonIniConfiguration.getSections()) { SubnodeConfiguration sectionConfig = commonIniConfiguration.getSection(section); PropertyValue sectionNode = ((ObjectValue) data).getOrSetValue(section, () -> PropertyValue.createObject(section)); Map<String, String> properties = new HashMap<>(); Iterator<String> keyIter = sectionConfig.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); ((ObjectValue) sectionNode).setValue(key, sectionConfig.getString(key)); } } } catch (Exception e) { throw new ConfigException("Failed to parse ini-file format from " + name, e); } return new ConfigurationData(name, this, data); }
From source file:org.apache.tamaya.format.IniConfigurationFormat.java
@Override public Map<String, Map<String, String>> readConfiguration(URL url) { Map<String, Map<String, String>> result = new HashMap<>(); try {//from w w w. ja va 2s.c o m HierarchicalINIConfiguration commonIniConfiguration = new HierarchicalINIConfiguration(url); for (String section : commonIniConfiguration.getSections()) { SubnodeConfiguration sectionConfig = commonIniConfiguration.getSection(section); Map<String, String> properties = new HashMap<>(); Iterator<String> keyIter = sectionConfig.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); properties.put(key, sectionConfig.getString(key)); } result.put(section, properties); } return result; } catch (ConfigurationException e) { throw new ConfigException("Failed to parse ini-file format from " + url, e); } }
From source file:org.apache.tamaya.integration.commons.IniConfigurationFormat.java
public ConfigurationData readConfiguration(URL url) { ConfigurationDataBuilder builder = ConfigurationDataBuilder.of(url.toString(), this); try {// ww w .j a v a 2s . c o m HierarchicalINIConfiguration commonIniConfiguration = new HierarchicalINIConfiguration(url); for (String section : commonIniConfiguration.getSections()) { SubnodeConfiguration sectionConfig = commonIniConfiguration.getSection(section); Map<String, String> properties = new HashMap<>(); Iterator<String> keyIter = sectionConfig.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); properties.put(key, sectionConfig.getString(key)); } builder.addProperties(section, properties); } } catch (ConfigurationException e) { throw new ConfigException("Failed to parse ini-file format from " + url, e); } return builder.build(); }
From source file:org.apache.taverna.robundle.Bundles.java
public static URI getReference(Path path) throws IOException { if (path == null || isMissing(path)) return null; if (!isReference(path)) throw new IllegalArgumentException("Not a reference: " + path); // Note: Latin1 is chosen here because it would not bail out on // "strange" characters. We actually parse the URL as ASCII path = withExtension(path, DOT_URL); try (BufferedReader r = newBufferedReader(path, LATIN1)) { HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration(); ini.load(r);/*from ww w .j av a 2 s . c o m*/ String urlStr = ini.getSection(INI_INTERNET_SHORTCUT).getString(INI_URL); // String urlStr = ini.get(INI_INTERNET_SHORTCUT, INI_URL); if (urlStr == null) throw new IOException("Invalid/unsupported URL format: " + path); return URI.create(urlStr); } catch (ConfigurationException e) { throw new IOException("Can't parse reference: " + path, e); } }
From source file:org.davidmason.zayf.config.ConfigLoader.java
private List<ServerInfo> getServerList() throws ConfigurationException { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(userConfig); SubnodeConfiguration serverConfig = config.getSection("servers"); DataConfiguration dataConfig = new DataConfiguration(serverConfig); List<String> prefixes = findPrefixes(dataConfig); return findServerInfoByPrefixes(dataConfig, prefixes); }