List of usage examples for org.apache.commons.configuration SubnodeConfiguration getKeys
public Iterator getKeys()
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 a v a2 s .c o m*/ 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 . j a va 2 s. co 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 {//from w w w .ja v a 2 s . 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.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. *//*from w w w . ja v a 2 s .c om*/ @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 w w . java 2 s . c o m*/ @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.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 ww w . j a v a 2 s .c o m this.data.put(sectionName, (Object) sectionData); } }
From source file:sf.net.experimaestro.tasks.ServerTask.java
private ConstraintSecurityHandler getSecurityHandler() { // -- Security // From/* w w w .j a v a 2 s. c o m*/ // http://docs.codehaus.org/display/JETTY/How+to+Configure+Security+with+Embedded+Jetty Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(new String[] { "user" }); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); String passwordProperty = configuration.getString("passwords"); final HashLoginService loginService; if (passwordProperty != null) { File passwordFile = new File(passwordProperty); loginService = new HashLoginService(XPM_REALM, passwordFile.getAbsolutePath()); } else { loginService = new HashLoginService(XPM_REALM); } // Read passwords final SubnodeConfiguration passwords = configuration.getSection("passwords"); final Iterator keys = passwords.getKeys(); while (keys.hasNext()) { String user = (String) keys.next(); final String[] fields = passwords.getString(user).split("\\s*,\\s*", 2); final String[] roles = fields[1].split("\\s*,\\s*"); LOGGER.info("Adding user %s", user); loginService.putUser(user, new Password(fields[0]), roles); } ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setRealmName(XPM_REALM); csh.setAuthenticator(new BasicAuthenticator()); csh.setConstraintMappings(new ConstraintMapping[] { cm }); csh.addConstraintMapping(cm); csh.setLoginService(loginService); return csh; }