List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:er.extensions.foundation.ERXProperties.java
/** * For every application specific property, this method generates a similar property without * the application name in the property key. The original property is not removed. * <p>//from w ww . j av a 2 s . c om * Ex: if current application is MyApp, for a property foo.bar.MyApp=true a new property * foo.bar=true is generated. * * @param properties Properties to update */ // xxxxxxxxxxxxxxxxxxx // This is more complex than it needs to be. Can just use endsWith.... // public static void flattenPropertyNames(Properties properties) { if (_useLoadtimeAppSpecifics == false) { return; } WOApplication application = WOApplication.application(); if (application == null) { return; } String applicationName = application.name(); for (Object keyObj : new TreeSet<Object>(properties.keySet())) { String key = (String) keyObj; if (key != null && key.length() > 0) { String value = properties.getProperty(key); int lastDotPosition = key.lastIndexOf("."); if (lastDotPosition != -1) { String lastElement = key.substring(lastDotPosition + 1); if (lastElement.equals(applicationName)) { properties.put(key.substring(0, lastDotPosition), value); } } } } }
From source file:edu.ku.brc.specify.datamodel.SpUICell.java
/** * Recreates the initialize string from the properties and clones the properties hashtable. * @param cell the source of the props//w ww . j a v a2 s . c o m * @return the string */ protected String getInitStrFromProps(final FormCellIFace cell) { Properties props = cell.getProperties(); if (props != null) { StringBuilder sb = new StringBuilder(); for (Object keyObj : props.keySet()) { String key = (String) keyObj; if (sb.length() > 0) sb.append(';'); sb.append(key); sb.append("="); sb.append(properties.getProperty(key)); } properties = (Properties) cell.getProperties().clone(); return sb.toString(); } return null; }
From source file:com.github.rvesse.airline.parser.aliases.UserAliasesSource.java
public List<AliasMetadata> load() throws FileNotFoundException, IOException { Properties properties = new Properties(); // Find the home directory since we will use this File homeDir = null;//from w ww. j a v a2s . c o m if (!StringUtils.isEmpty(System.getProperty("user.home"))) { homeDir = new File(System.getProperty("user.home")); } // Search locations in reverse order overwriting previously found values // each time. Thus the first location in the list has highest precedence Set<String> loaded = new HashSet<>(); for (int i = searchLocations.size() - 1; i >= 0; i--) { // Check an actual location String loc = searchLocations.get(i); if (StringUtils.isBlank(loc)) continue; // Allow use of ~/ or ~\ as reference to user home directory if (loc.startsWith("~" + File.separator)) { if (homeDir == null) continue; loc = homeDir.getAbsolutePath() + loc.substring(homeDir.getAbsolutePath().endsWith(File.separator) ? 2 : 1); } // Don't read property files multiple times if (loaded.contains(loc)) continue; File f = new File(loc); f = new File(f, filename); if (f.exists() && f.isFile() && f.canRead()) { try (FileInputStream input = new FileInputStream(f)) { properties.load(input); } finally { // Remember we've tried to read this file so we don't try // and read it multiple times loaded.add(loc); } } } // Strip any irrelevant properties if (StringUtils.isNotBlank(prefix)) { List<Object> keysToRemove = new ArrayList<Object>(); for (Object key : properties.keySet()) { if (!key.toString().startsWith(prefix)) keysToRemove.add(key); } for (Object key : keysToRemove) { properties.remove(key); } } // Generate the aliases List<AliasMetadata> aliases = new ArrayList<>(); for (Object key : properties.keySet()) { String name = key.toString(); if (!StringUtils.isBlank(prefix)) name = name.substring(prefix.length()); AliasBuilder<C> alias = new AliasBuilder<C>(name); String value = properties.getProperty(key.toString()); if (StringUtils.isEmpty(value)) { aliases.add(alias.build()); continue; } // Process property value into arguments List<String> args = AliasArgumentsParser.parse(value); alias.withArguments(args.toArray(new String[args.size()])); aliases.add(alias.build()); } return aliases; }
From source file:mondrian.gui.Workbench.java
/** * this method loads any available menubar plugins based on *///from ww w.j av a2 s. c o m private void loadMenubarPlugins() { // render any plugins InputStream pluginStream = null; try { Properties props = new Properties(); pluginStream = getClass().getResourceAsStream("/workbench_plugins.properties"); if (pluginStream != null) { props.load(pluginStream); for (Object key : props.keySet()) { String keystr = (String) key; if (keystr.startsWith("workbench.menu-plugin")) { String val = props.getProperty(keystr); WorkbenchMenubarPlugin plugin = (WorkbenchMenubarPlugin) Class.forName(val).newInstance(); plugin.setWorkbench(this); plugin.addItemsToMenubar(menuBar); } } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (pluginStream != null) { pluginStream.close(); } } catch (Exception e) { } } }
From source file:nl.nn.adapterframework.jms.JNDIBase.java
protected Hashtable getJndiEnv() throws NamingException { Properties jndiEnv = new Properties(); if (StringUtils.isNotEmpty(getJndiProperties())) { URL url = ClassUtils.getResourceURL(classLoader, getJndiProperties()); if (url == null) { throw new NamingException("cannot find jndiProperties from [" + getJndiProperties() + "]"); }//from w w w .j a v a2 s .c o m try { jndiEnv.load(url.openStream()); } catch (IOException e) { throw new NamingException("cannot load jndiProperties [" + getJndiProperties() + "] from url [" + url.toString() + "]"); } } if (getInitialContextFactoryName() != null) jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactoryName()); if (getProviderURL() != null) jndiEnv.put(Context.PROVIDER_URL, getProviderURL()); if (getAuthentication() != null) jndiEnv.put(Context.SECURITY_AUTHENTICATION, getAuthentication()); if (getPrincipal() != null || getCredentials() != null || getJndiAuthAlias() != null) { CredentialFactory jndiCf = new CredentialFactory(getJndiAuthAlias(), getPrincipal(), getCredentials()); if (StringUtils.isNotEmpty(jndiCf.getUsername())) jndiEnv.put(Context.SECURITY_PRINCIPAL, jndiCf.getUsername()); if (StringUtils.isNotEmpty(jndiCf.getPassword())) jndiEnv.put(Context.SECURITY_CREDENTIALS, jndiCf.getPassword()); } if (getUrlPkgPrefixes() != null) jndiEnv.put(Context.URL_PKG_PREFIXES, getUrlPkgPrefixes()); if (getSecurityProtocol() != null) jndiEnv.put(Context.SECURITY_PROTOCOL, getSecurityProtocol()); if (log.isDebugEnabled()) { for (Iterator it = jndiEnv.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); String value = jndiEnv.getProperty(key); log.debug("jndiEnv [" + key + "] = [" + value + "]"); } } return jndiEnv; }
From source file:de.escidoc.core.common.business.indexing.IndexingHandler.java
/** * Get configuration for available indexes. * * @throws IOException e// ww w. j a v a 2 s . co m * @throws SystemException e */ private void getIndexConfigs() throws IOException, SystemException { // Build IndexInfo HashMap this.objectTypeParameters = new HashMap<String, Map<String, Map<String, Object>>>(); final String searchPropertiesDirectory = EscidocConfiguration.getInstance() .get(EscidocConfiguration.SEARCH_PROPERTIES_DIRECTORY); for (final String indexName : getIndexNames()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("getting configuration for index " + indexName); } final Properties indexProps = new Properties(); InputStream propStream = null; try { try { propStream = getInputStream('/' + searchPropertiesDirectory + "/index/" + indexName + "/index.object-types.properties"); } catch (IOException e) { propStream = IndexingHandler.class.getResourceAsStream('/' + searchPropertiesDirectory + "/index/" + indexName + "/index.object-types.properties"); } if (propStream == null) { throw new SystemException(searchPropertiesDirectory + "/index/" + indexName + "/index.object-types.properties " + "not found"); } indexProps.load(propStream); } finally { IOUtils.closeStream(propStream); } final Pattern objectTypePattern = Pattern.compile(".*?\\.(.*?)\\..*"); final Matcher objectTypeMatcher = objectTypePattern.matcher(""); final Collection<String> objectTypes = new HashSet<String>(); for (final Object o : indexProps.keySet()) { final String key = (String) o; if (key.startsWith("Resource")) { final String propVal = indexProps.getProperty(key); if (LOGGER.isDebugEnabled()) { LOGGER.debug("found property " + key + ':' + propVal); } objectTypeMatcher.reset(key); if (!objectTypeMatcher.matches()) { throw new IOException(key + " is not a supported property"); } final String objectType = de.escidoc.core.common.business.Constants.RESOURCES_NS_URI + objectTypeMatcher.group(1); if (objectTypeParameters.get(objectType) == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("initializing HashMap for objectType " + objectType); } objectTypeParameters.put(objectType, new HashMap<String, Map<String, Object>>()); } if (objectTypeParameters.get(objectType).get(indexName) == null) { objectTypeParameters.get(objectType).put(indexName, new HashMap<String, Object>()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding " + indexName + " to " + objectType); } objectTypes.add(objectType); } if (key.contains("Prerequisite")) { if (objectTypeParameters.get(objectType).get(indexName).get("prerequisites") == null) { objectTypeParameters.get(objectType).get(indexName).put("prerequisites", new HashMap<String, String>()); } ((Map<String, String>) objectTypeParameters.get(objectType).get(indexName) .get("prerequisites")).put(key.replaceFirst(".*\\.", ""), propVal); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding prerequisite " + key + ':' + propVal); } } else { objectTypeParameters.get(objectType).get(indexName).put(key.replaceFirst(".*\\.", ""), propVal); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding parameter " + key + ':' + propVal); } } } } for (final String objectType : objectTypes) { if (objectTypeParameters.get(objectType).get(indexName).get("indexAsynchronous") == null) { objectTypeParameters.get(objectType).get(indexName).put("indexAsynchronous", "false"); } if (objectTypeParameters.get(objectType).get(indexName).get("indexReleasedVersion") == null) { objectTypeParameters.get(objectType).get(indexName).put("indexReleasedVersion", "false"); } } } }
From source file:org.apache.maven.archetype.creator.FilesetArchetypeCreator.java
private void addRequiredProperties(ArchetypeDescriptor archetypeDescriptor, Properties properties) { Properties requiredProperties = new Properties(); requiredProperties.putAll(properties); requiredProperties.remove(Constants.ARCHETYPE_GROUP_ID); requiredProperties.remove(Constants.ARCHETYPE_ARTIFACT_ID); requiredProperties.remove(Constants.ARCHETYPE_VERSION); requiredProperties.remove(Constants.GROUP_ID); requiredProperties.remove(Constants.ARTIFACT_ID); requiredProperties.remove(Constants.VERSION); requiredProperties.remove(Constants.PACKAGE); requiredProperties.remove(Constants.EXCLUDE_PATTERNS); for (Iterator<?> propertiesIterator = requiredProperties.keySet().iterator(); propertiesIterator .hasNext();) {/*from w ww.jav a 2 s . c o m*/ String propertyKey = (String) propertiesIterator.next(); RequiredProperty requiredProperty = new RequiredProperty(); requiredProperty.setKey(propertyKey); requiredProperty.setDefaultValue(requiredProperties.getProperty(propertyKey)); archetypeDescriptor.addRequiredProperty(requiredProperty); getLogger().debug("Adding requiredProperty " + propertyKey + "=" + requiredProperties.getProperty(propertyKey) + " to archetype's descriptor"); } }
From source file:com.cloud.api.ApiServer.java
private void processConfigFiles(String[] apiConfig, boolean pluggableServicesConfig) { try {/* w ww .j a v a2s.c om*/ if (_apiCommands == null) { _apiCommands = new Properties(); } Properties preProcessedCommands = new Properties(); if (apiConfig != null) { for (String configFile : apiConfig) { File commandsFile = PropertiesUtil.findConfigFile(configFile); if (commandsFile != null) { try { preProcessedCommands.load(new FileInputStream(commandsFile)); } catch (FileNotFoundException fnfex) { // in case of a file within a jar in classpath, try to open stream using url InputStream stream = PropertiesUtil.openStreamFromURL(configFile); if (stream != null) { preProcessedCommands.load(stream); } else { s_logger.error("Unable to find properites file", fnfex); } } } } for (Object key : preProcessedCommands.keySet()) { String preProcessedCommand = preProcessedCommands.getProperty((String) key); String[] commandParts = preProcessedCommand.split(";"); _apiCommands.put(key, commandParts[0]); if (pluggableServicesConfig) { s_pluggableServiceCommands.add(commandParts[0]); } if (commandParts.length > 1) { try { short cmdPermissions = Short.parseShort(commandParts[1]); if ((cmdPermissions & ADMIN_COMMAND) != 0) { s_adminCommands.add((String) key); } if ((cmdPermissions & RESOURCE_DOMAIN_ADMIN_COMMAND) != 0) { s_resourceDomainAdminCommands.add((String) key); } if ((cmdPermissions & DOMAIN_ADMIN_COMMAND) != 0) { s_resellerCommands.add((String) key); } if ((cmdPermissions & USER_COMMAND) != 0) { s_userCommands.add((String) key); } } catch (NumberFormatException nfe) { s_logger.info("Malformed command.properties permissions value, key = " + key + ", value = " + preProcessedCommand); } } } s_allCommands.addAll(s_adminCommands); s_allCommands.addAll(s_resourceDomainAdminCommands); s_allCommands.addAll(s_userCommands); s_allCommands.addAll(s_resellerCommands); } } catch (FileNotFoundException fnfex) { s_logger.error("Unable to find properites file", fnfex); } catch (IOException ioex) { s_logger.error("Exception loading properties file", ioex); } }
From source file:com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfigurator.java
/** * Return a KinesisClientLibConfiguration with variables configured as specified by the properties in config stream. * Program will fail immediately, if customer provide: 1) invalid variable value. Program will log it as warning and * continue, if customer provide: 1) variable with unsupported variable type. 2) a variable with name which does not * match any of the variables in KinesisClientLibConfigration. * //from w w w.j a va 2 s . co m * @param properties a Properties object containing the configuration information * @return KinesisClientLibConfiguration */ public KinesisClientLibConfiguration getConfiguration(Properties properties) { // The three minimum required arguments for constructor are obtained first. They are all mandatory, all of them // should be provided. If any of these three failed to be set, program will fail. IPropertyValueDecoder<String> stringValueDecoder = new StringPropertyValueDecoder(); IPropertyValueDecoder<AWSCredentialsProvider> awsCPPropGetter = new AWSCredentialsProviderPropertyValueDecoder(); String applicationName = stringValueDecoder.decodeValue(properties.getProperty(PROP_APP_NAME)); String streamName = stringValueDecoder.decodeValue(properties.getProperty(PROP_STREAM_NAME)); AWSCredentialsProvider provider = awsCPPropGetter .decodeValue(properties.getProperty(PROP_CREDENTIALS_PROVIDER)); if (applicationName == null || applicationName.isEmpty()) { throw new IllegalArgumentException("Value of applicationName should be explicitly provided."); } if (streamName == null || streamName.isEmpty()) { throw new IllegalArgumentException("Value of streamName should be explicitly provided."); } // Allow customer not to provide workerId or to provide empty worker id. String workerId = stringValueDecoder.decodeValue(properties.getProperty(PROP_WORKER_ID)); if (workerId == null || workerId.isEmpty()) { workerId = UUID.randomUUID().toString(); LOG.info("Value of workerId is not provided in the properties. WorkerId is automatically " + "assigned as: " + workerId); } KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(applicationName, streamName, provider, workerId); Set<String> requiredNames = new HashSet<String>( Arrays.asList(PROP_STREAM_NAME, PROP_APP_NAME, PROP_WORKER_ID, PROP_CREDENTIALS_PROVIDER)); // Set all the variables that are not used for constructor. for (Object keyObject : properties.keySet()) { String key = keyObject.toString(); if (!requiredNames.contains(key)) { withProperty(key, properties, config); } } return config; }