List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys();
From source file:org.apache.distributedlog.DistributedLogConfiguration.java
/** * Load configuration from other configuration object. * * @param baseConf Other configuration object *///from ww w .j ava 2 s . c o m public void loadConf(Configuration baseConf) { for (Iterator<String> iter = baseConf.getKeys(); iter.hasNext();) { String key = iter.next(); setProperty(key, baseConf.getProperty(key)); } }
From source file:org.apache.hawq.pxf.api.utilities.ProfilesConf.java
private Map<String, String> getProfilePluginMap(Configuration profileSubset) { @SuppressWarnings("unchecked") //IteratorUtils doesn't yet support generics. List<String> plugins = IteratorUtils.toList(profileSubset.getKeys()); Map<String, String> pluginsMap = new HashMap<>(); for (String plugin : plugins) { String pluginValue = profileSubset.getString(plugin); if (!StringUtils.isEmpty(StringUtils.trim(pluginValue))) { pluginsMap.put("X-GP-" + plugin.toUpperCase(), pluginValue); }//from w w w . j a v a2 s . c om } return pluginsMap; }
From source file:org.apache.james.mailetcontainer.impl.MailetConfigImpl.java
/** * Set the Avalon Configuration object for the mailet. * //from ww w . ja v a 2 s .c om * @param newConfiguration * the new Configuration for the mailet */ public void setConfiguration(Configuration newConfiguration) { DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); // Disable the delimiter parsing. See JAMES-1232 builder.setDelimiterParsingDisabled(true); Iterator<String> keys = newConfiguration.getKeys(); while (keys.hasNext()) { String key = keys.next(); String[] values = newConfiguration.getStringArray(key); // See JAMES-1177 // Need to replace ".." with "." // See // http://commons.apache.org/configuration/userguide-1.2/howto_xml.html // Escaping dot characters in XML tags key = key.replaceAll("\\.\\.", "\\."); // Convert array values to a "," delimited string value StringBuilder valueBuilder = new StringBuilder(); for (int i = 0; i < values.length; i++) { valueBuilder.append(values[i]); if (i + 1 < values.length) { valueBuilder.append(","); } } builder.addProperty(key, valueBuilder.toString()); } configuration = builder; }
From source file:org.apache.james.postage.configuration.ConfigurationLoader.java
private void addDescription(PostageConfiguration postageConfiguration, Configuration configuration) { Iterator<String> keys = configuration.getKeys(); while (keys.hasNext()) { String itemName = keys.next(); String itemContent = configuration.getString(itemName); postageConfiguration.addDescriptionItem(itemName, itemContent); }//from w ww. java2 s . co m }
From source file:org.apache.marmotta.platform.core.services.config.ConfigurationServiceImpl.java
/** * Initialise the ConfigurationService. Takes the marmotta.home system property from the servlet * init parameters// www . j av a2 s . c o m * (web.xml) as bootstrap home. In case a system-config.properties file is found in this * directory, the * configuration is then loaded from this file. In case a system-config.properties file does not * yet exist, * the method loads bootstrap settings from the resource default-config.properties in the * classpath (in the * standard bundling, the file is in the kiwi-core-XXX.jar archive). After loading the * configuration, the * service initialises the plugin subsystem and the SOLR home directory by unpacking the default * configuration * if the SOLR configuration does not yet exist. * @param override */ @Override public void initialize(String home, Configuration override) { lock.writeLock().lock(); try { initialising = true; log.info("Apache Marmotta Configuration Service starting up ..."); if (isTomcat7()) { log.info("Apache Marmotta running on Apache Tomcat 7.x"); } else if (isTomcat6()) { log.info("Apache Marmotta running on Apache Tomcat <= 6.x"); } else if (isJetty7()) { log.info("Apache Marmotta running on Jetty 7.x"); } else if (isJetty6()) { log.info("Apache Marmotta running on Jetty <= 6.x"); } else { log.info("Apache Marmotta running on an unknown servlet container"); } setHome(home); if (getHome() != null) { File f1 = new File(getHome()); if (!f1.exists()) { f1.mkdirs(); } // ensure directory for user configuration files File f2 = new File(getHome() + File.separator + DIR_CONFIG); if (!f2.exists()) { f2.mkdirs(); } // ensure directory for logging messages File f3 = new File(getHome() + File.separator + DIR_LOG); if (!f3.exists()) { f3.mkdirs(); } // ensure directory for importing data File f4 = new File(getHome() + File.separator + DIR_IMPORT); if (!f4.exists()) { f4.mkdirs(); } } // the save configuration will be in the home directory try { if (getHome() != null) { configFileName = getHome() + File.separator + "system-config.properties"; metaFileName = getHome() + File.separator + "system-meta.properties"; File configFile = new File(configFileName); if (!configFile.exists()) { log.info("creating system configuration in configuration file {}", configFile.getAbsolutePath()); } else { log.info("reading system configuration from existing configuration file {}", configFile.getAbsolutePath()); } saveConfiguration = new PropertiesConfiguration(configFile); File metaFile = new File(metaFileName); if (!metaFile.exists()) { log.info("creating system configuration metadata in configuration file {}", metaFile.getAbsolutePath()); } else { log.info("reading system configuration metadata from existing configuration file {}", metaFile.getAbsolutePath()); } saveMetadata = new PropertiesConfiguration(metaFile); } else { log.error( "error while initialising configuration: no marmotta.home property given; creating memory-only configuration"); saveConfiguration = new MapConfiguration(new HashMap<String, Object>()); saveMetadata = new MapConfiguration(new HashMap<String, Object>()); } } catch (Exception e) { log.error("error while initialising configuration file {}: {}; creating memory-only configuration", configFileName, e.getMessage()); saveConfiguration = new MapConfiguration(new HashMap<String, Object>()); saveMetadata = new MapConfiguration(new HashMap<String, Object>()); } config = new FallbackConfiguration(); final ConfigurationInterpolator _int = config.getInterpolator(); _int.registerLookup("pattern.quote", new StrLookup() { @Override public String lookup(String key) { return Pattern.quote(_int.getDefaultLookup().lookup(key)); } }); _int.registerLookup("urlencode", new StrLookup() { @Override public String lookup(String key) { try { return URLEncoder.encode(_int.getDefaultLookup().lookup(key), "utf8"); } catch (UnsupportedEncodingException e) { return _int.getDefaultLookup().lookup(key); } } }); config.addConfiguration(saveConfiguration, true); // load all default-config.properties try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("config-defaults.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); config.addConfiguration(new PropertiesConfiguration(url)); } } catch (IOException e) { log.error("I/O error while loading default configurations", e); } catch (ConfigurationException e) { log.error("configuration error while loading default configurations", e); } // legacy support (to be removed) try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("default-config.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); config.addConfiguration(new PropertiesConfiguration(url)); log.warn( "found legacy configuration file {}; should be replaced with per-module configuration!", url); } } catch (IOException e) { log.error("I/O error while loading default configurations", e); } catch (ConfigurationException e) { log.error("configuration error while loading default configurations", e); } // create the configuration that is responsible for getting metadata about configuration keys in the main // configuration; since the keys will be different, we store changes also to the main save configuration configDescriptions = new FallbackConfiguration(); configDescriptions.addConfiguration(saveMetadata, true); try { Enumeration<URL> configs = this.getClass().getClassLoader() .getResources("config-descriptions.properties"); while (configs.hasMoreElements()) { URL url = configs.nextElement(); configDescriptions.addConfiguration(new PropertiesConfiguration(url)); } } catch (IOException e) { log.error("I/O error while loading configuration descriptions", e); } catch (ConfigurationException e) { log.error("configuration error while loading configuration descriptions", e); } // setup home if it is given as system property, // the bootstrap configuration is overwritten if (getHome() != null) { config.setProperty("marmotta.home", getHome()); } // in case override configuration is given, change all settings in the configuration accordingly if (override != null) { for (Iterator<String> it = override.getKeys(); it.hasNext();) { String key = it.next(); config.setProperty(key, override.getProperty(key)); } } save(); // configuration service is now ready to use initialised = true; loggingStartEvent.fire(new LoggingStartEvent()); // this should maybe move to the KiWiPreStartupFilter ... initDatabaseConfiguration(); save(); log.info("Apache Marmotta Configuration Service: initialisation completed"); configurationInitEvent.fire(new ConfigurationServiceInitEvent()); } finally { lock.writeLock().unlock(); } }
From source file:org.apache.marmotta.platform.core.webservices.modules.ModuleWebService.java
/** * Return the configuration of the module identified by the name passed as query argument. The module will be * a map containing the values specified in the kiwi-module.properties file of the module. * * @param moduleName the name of the module for which to return the configuration * @return a map with key/value pairs representing the module configuration as contained in kiwi-module.properties *//*from w w w .jav a 2 s .c o m*/ @Path("/module") @GET @Produces("application/json") public Map<String, Object> getConfiguration(@QueryParam("name") String moduleName) { Configuration cfg = null; try { cfg = moduleService.getModuleConfiguration(URLDecoder.decode(moduleName, "UTF-8")).getConfiguration(); } catch (UnsupportedEncodingException e) { return null; } if (cfg != null) { Map<String, Object> result = new HashMap<String, Object>(); for (Iterator<String> it = cfg.getKeys(); it.hasNext();) { String key = it.next(); result.put(key, cfg.getProperty(key)); } return result; } else return null; }
From source file:org.apache.marmotta.platform.security.services.SecurityServiceImpl.java
/** * Load a pre-configured security profile from the classpath. When calling this method, the service will * look for files called security-profile.<name>.properties and replace all existing security constraints by * the new security constraints./*from w w w. ja v a 2 s . c o m*/ * * @param profile */ @Override public void loadSecurityProfile(String profile) { profileLoading = true; LinkedHashSet<String> profiles = new LinkedHashSet<String>(); Configuration securityConfig = loadProfile(profile, profiles); if (securityConfig != null) { // remove all configuration keys that define permissions or restrictions for (String type : Lists.newArrayList("permission", "restriction")) { // determine the names of constraints that are configured for (String key : configurationService.listConfigurationKeys("security." + type)) { configurationService.removeConfiguration(key); } } for (Iterator<String> keys = securityConfig.getKeys(); keys.hasNext();) { String key = keys.next(); configurationService.setConfigurationWithoutEvent(key, securityConfig.getProperty(key)); } configurationService.setConfigurationWithoutEvent("security.configured", true); } profileLoading = false; initSecurityConstraints(); }
From source file:org.apache.marmotta.platform.security.services.SecurityServiceImpl.java
private Configuration loadProfile(String profile, LinkedHashSet<String> profiles) { URL securityConfigUrl = this.getClass().getClassLoader() .getResource("security-profile." + profile + ".properties"); if (securityConfigUrl != null) { try {/*w ww .java 2 s . com*/ Configuration securityConfig = null; securityConfig = new PropertiesConfiguration(securityConfigUrl); if (securityConfig.containsKey("security.profile.base")) { final String baseP = securityConfig.getString("security.profile.base"); if (profiles.contains(baseP)) { log.warn("Cycle in security configuration detected: {} -> {}", profiles, baseP); return securityConfig; } else { profiles.add(baseP); final Configuration baseProfile = loadProfile(baseP, profiles); for (Iterator<String> keys = securityConfig.getKeys(); keys.hasNext();) { String key = keys.next(); baseProfile.setProperty(key, securityConfig.getProperty(key)); } return baseProfile; } } else { return securityConfig; } } catch (ConfigurationException e) { log.error("error parsing security-profile.{}.properties file at {}: {}", new Object[] { profile, securityConfigUrl, e.getMessage() }); } } return null; }
From source file:org.apache.metron.helpers.topology.SettingsLoader.java
public static Map<String, JSONObject> loadKnownHosts(String config_path) throws ConfigurationException, ParseException { Configuration hosts = new PropertiesConfiguration(config_path); Iterator<String> keys = hosts.getKeys(); Map<String, JSONObject> known_hosts = new HashMap<String, JSONObject>(); JSONParser parser = new JSONParser(); while (keys.hasNext()) { String key = keys.next().trim(); JSONArray value = (JSONArray) parser.parse(hosts.getProperty(key).toString()); known_hosts.put(key, (JSONObject) value.get(0)); }/*from ww w. j a va 2 s . c o m*/ return known_hosts; }
From source file:org.apache.qpid.server.configuration.plugins.AbstractConfiguration.java
/** * Sets the configuration for this plugin * * @param path// w w w . java2 s. c om * @param configuration the configuration for this plugin. */ public void setConfiguration(String path, Configuration configuration) throws ConfigurationException { _config = configuration; // Extract a list of elements for processing Iterator<?> keys = configuration.getKeys(); Set<String> elements = new HashSet<String>(); while (keys.hasNext()) { String key = (String) keys.next(); int elementNameIndex = key.indexOf("."); String element = key.trim(); if (elementNameIndex != -1) { element = key.substring(0, elementNameIndex).trim(); } // Trim any element properties elementNameIndex = element.indexOf("["); if (elementNameIndex > 0) { element = element.substring(0, elementNameIndex).trim(); } elements.add(element); } //Remove the items we already expect in the configuration for (String tag : getElementsProcessed()) { // Work round the issue with Commons configuration. // With an XMLConfiguration the key will be [@property] // but with a CompositeConfiguration it will be @property]. // Hide this issue from our users so when/if we change the // configuration they don't have to. int bracketIndex = tag.indexOf("["); if (bracketIndex != -1) { tag = tag.substring(bracketIndex + 1, tag.length()); } elements.remove(tag); } if (_logger.isInfoEnabled()) { if (!elements.isEmpty()) { _logger.info("Elements to lookup:" + path); for (String tag : elements) { _logger.info("Tag:'" + tag + "'"); } } } validateConfiguration(); }