List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys();
From source file:org.overlord.gadgets.server.ConfiguredModule.java
/** * Loads configuration properties from a file on the file system. We look for the file in a variety of * places, although users can override the file's location by setting a system property. *///from w w w .j a v a 2s .c o m private static void loadFromFile() { String configFile = System.getProperty("gadget-server.config.file.name"); Long refreshDelay = 60000l; Configuration config = ConfigurationFactory.createConfig(configFile, "gadget-server.properties", refreshDelay, "/META-INF/config/org.overlord.gadgets.properties", ConfiguredModule.class); Iterator<?> keys = config.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); String value = config.getString(key); properties.put(key, value); } }
From source file:org.roda.core.RodaCoreFactory.java
private static void fillInPropertiesToCache(String cacheName, List<String> prefixesToCache) { if (rodaPropertiesCache.get(cacheName) == null) { HashMap<String, String> newCacheEntry = new HashMap<>(); Configuration configuration = RodaCoreFactory.getRodaConfiguration(); Iterator<String> keys = configuration.getKeys(); while (keys.hasNext()) { String key = String.class.cast(keys.next()); String value = configuration.getString(key, ""); for (String prefixToCache : prefixesToCache) { if (key.startsWith(prefixToCache)) { newCacheEntry.put(key, value); break; }/*from ww w. j ava 2s . c o m*/ } } rodaPropertiesCache.put(cacheName, newCacheEntry); } }
From source file:org.seasar.karrta.jcr.commons.SystemConfiguration.java
/** * initialize/*from w w w .j a va 2 s.com*/ * */ public synchronized void initialize() throws ConfigurationException { systemConfigList_ = new ArrayList<Map<String, String>>(); Configuration config = new PropertiesConfiguration(this.configurationName_); String mode = config.getString(PROP_MODE_KEY_NAME) + "."; Iterator<?> i = config.getKeys(); String key, value; while (i.hasNext()) { key = (String) i.next(); value = config.getString(key); if (key.indexOf(mode) == 0 || key.indexOf(PROP_MODE_DEFAULT_NAME) == 0) { String storeKey = key.indexOf(mode) > -1 ? key.substring(mode.length()) : key; Map<String, String> map = new HashMap<String, String>(); map.put(storeKey, value); systemConfigList_.add(map); logger_.debug("::: SystemConfiguration:[" + map + "]"); } } }
From source file:org.seedstack.javamail.internal.PropertyFileSessionConfigurer.java
@Override public Map<String, Session> doConfigure() { Map<String, Session> sessions = Maps.newHashMap(); String mailProviders[] = configuration.getStringArray("providers"); if (mailProviders != null) { for (String provider : mailProviders) { Configuration mailProviderConfig = configuration .subset(String.format("provider.%s.property", provider)); Properties mailProviderProperties = new Properties(); Iterator<String> keys = mailProviderConfig.getKeys(); while (keys.hasNext()) { String configuredProperty = keys.next(); mailProviderProperties.put(configuredProperty, mailProviderConfig.getProperty(configuredProperty)); }//w w w . j a v a 2s . co m Session session = Session.getInstance(mailProviderProperties); sessions.put(provider, session); } } return sessions; }
From source file:org.seedstack.seed.core.internal.application.ApplicationImpl.java
/** * Merge property from props section recursively starting by the atomic * parent package section coming from entity class name. Properties can be * overwritten by using the same key on the subpackage(s) section. * * @param key props section name/*from www. j a va2s . c om*/ */ private void mergeEntityPackageConfiguration(String key, Map<String, String> entityConfiguration) { if (key.matches(REGEX_FOR_SUBPACKAGE)) { mergeEntityPackageConfiguration(key.replaceFirst(REGEX_FOR_SUBPACKAGE, "$1*"), entityConfiguration); } Configuration configuration = this.configuration.subset(key.replace("*", ".*")); if (!configuration.isEmpty()) { Iterator<String> keys = configuration.getKeys(); while (keys.hasNext()) { String propertyKey = keys.next(); entityConfiguration.put(propertyKey, configuration.getString(propertyKey)); } } }
From source file:org.seedstack.seed.core.internal.application.ApplicationImpl.java
/** * Merge property from props section recursively starting by "*" section. * * @param key props section name//from w w w . j a v a 2 s. co m * @return configuration map */ private Map<String, String> getEntityConfiguration(String key) { Configuration configuration = this.configuration.subset("*"); Map<String, String> entityConfig = new HashMap<String, String>(); if (!configuration.isEmpty()) { Iterator<String> keys = configuration.getKeys(); while (keys.hasNext()) { String propertyKey = keys.next(); entityConfig.put(propertyKey, configuration.getString(propertyKey)); } } mergeEntityPackageConfiguration(key, entityConfig); return entityConfig; }
From source file:org.seedstack.seed.security.internal.authorization.ConfigurationRolePermissionResolver.java
private void processPermissionsConfiguration(Configuration permissionsConfiguration) { Iterator<String> keys = permissionsConfiguration.getKeys(); while (keys.hasNext()) { String roleName = keys.next(); String[] tokens = permissionsConfiguration.getStringArray(roleName); Set<String> permissions = new HashSet<String>(); for (String permission : tokens) { permissions.add(permission); }/*from w ww . j a v a 2 s. co m*/ roles.put(roleName, permissions); } }
From source file:org.seedstack.seed.security.internal.realms.ConfigurationRealm.java
private void processUsersConfiguration(Configuration usersConfiguration) { Iterator<String> keys = usersConfiguration.getKeys(); while (keys.hasNext()) { String userName = keys.next(); ConfigurationUser user = new ConfigurationUser(userName); String[] values = usersConfiguration.getStringArray(userName); if (values.length == 0) { user.password = ""; } else {/*from w ww . j a va 2 s . c om*/ user.password = values[0]; for (int i = 1; i < values.length; i++) { user.roles.add(values[i]); } } users.add(user); } }
From source file:org.shaf.shell.view.ConfigurationView.java
/** * Shows the configuration on the text-based terminal. *//*from w ww .ja va 2 s .c om*/ @Override public void show(final Configuration content) { int nameWidth = 0; int valueWidth = 0; Iterator<String> keys = content.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (key.length() > nameWidth) { nameWidth = key.length(); } String value = content.getProperty(key).toString(); if (value.length() > valueWidth) { valueWidth = value.length(); } } String fmt = "%-" + nameWidth + "s = %-" + valueWidth + "s"; keys = content.getKeys(); while (keys.hasNext()) { String key = keys.next(); Object value = content.getProperty(key); this.terminal.println(String.format(fmt, key, value)); } }
From source file:org.soaplab.admin.ExploreConfig.java
/************************************************************************* * * An entry point//ww w . j a v a 2s. c o m * *************************************************************************/ @SuppressWarnings("unchecked") public static void main(String[] args) { try { BaseCmdLine cmd = getCmdLine(args, ExploreConfig.class); String param = null; // remember System properties before we initialize // Soaplab's Config Properties sysProps = System.getProperties(); // for testing: adding property files if ((param = cmd.getParam("-f")) != null) { title("Adding config property files:"); String[] files = param.split(","); for (String filename : files) { if (Config.addConfigPropertyFile(filename)) msgln("Added: " + filename); else msgln("Failed: " + filename); } msgln(""); } if ((param = cmd.getParam("-xml")) != null) { title("Adding config XML files:"); String[] files = param.split(","); for (String filename : files) { if (Config.addConfigXMLFile(filename)) msgln("Added: " + filename); else msgln("Failed: " + filename); } msgln(""); } // list of configurations if (cmd.hasOption("-lf")) { title("Using property resources (in this order):"); int i = 0; while (true) { Configuration cfg = null; int count = 0; try { cfg = Config.get().getConfiguration(i++); for (Iterator<String> it = cfg.getKeys(); it.hasNext(); count++) it.next(); } catch (IndexOutOfBoundsException e) { break; } if (count == 0) msg(i + ": (empty) "); else msg(i + ": (" + String.format("%1$5d", count) + ") "); if (cfg instanceof FileConfiguration) { msgln(((FileConfiguration) cfg).getFile().getAbsolutePath()); } else if (cfg instanceof SystemConfiguration) { msgln("Java System Properties"); } else if (cfg instanceof BaseConfiguration) { msgln("Directly added properties (no config file)"); } else { msgln(cfg.getClass().getName()); } } msgln(""); } // list of properties boolean listProps = cmd.hasOption("-l"); boolean listAllProps = cmd.hasOption("-la"); if (listProps || listAllProps) { title("Available properties" + (listProps ? " (except System properties):" : ":")); SortedMap<String, String> allProps = new TreeMap<String, String>(); int maxLen = 0; for (Iterator<String> it = Config.get().getKeys(); it.hasNext();) { String key = it.next(); if (listAllProps || !sysProps.containsKey(key)) { if (key.length() > maxLen) maxLen = key.length(); String[] values = Config.get().getStringArray(key); if (values.length != 0) allProps.put(key, StringUtils.join(values, ",")); } } for (Iterator<Map.Entry<String, String>> it = allProps.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> entry = it.next(); msgln(String.format("%1$-" + maxLen + "s", entry.getKey()) + " => " + entry.getValue()); } msgln(""); } // get properties by prefix if ((param = cmd.getParam("-prefix")) != null) { String serviceName = cmd.getParam("-service"); if (serviceName == null) title("Properties matching prefix:"); else title("Properties matching service name and prefix:"); SortedSet<String> selectedKeys = new TreeSet<String>(); int maxLen = 0; Properties props = Config.getMatchingProperties(param, serviceName, null); for (Enumeration en = props.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); if (key.length() > maxLen) maxLen = key.length(); selectedKeys.add(key); } for (Iterator<String> it = selectedKeys.iterator(); it.hasNext();) { String key = it.next(); msgln(String.format("%1$-" + maxLen + "s", key) + " => " + props.getProperty(key)); } msgln(""); } // show individual properties value if (cmd.params.length > 0) { int maxLen = 0; for (int i = 0; i < cmd.params.length; i++) { int len = cmd.params[i].length(); if (len > maxLen) maxLen = len; } title("Selected properties:"); for (int i = 0; i < cmd.params.length; i++) { String value = Config.get().getString(cmd.params[i]); msgln(String.format("%1$-" + maxLen + "s", cmd.params[i]) + " => " + (value == null ? "<null>" : value)); } } } catch (Throwable e) { processErrorAndExit(e); } }