List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:org.springmodules.cache.provider.ReflectionCacheModelEditor.java
/** * @throws IllegalStateException//from w ww . j a v a 2s . c o m * if the class of the cache model to create has not been set. * @see SemicolonSeparatedPropertiesParser#parseProperties(String) * @see PropertyEditor#setAsText(String) * @see org.springframework.beans.PropertyAccessor#setPropertyValue(String, * Object) */ public final void setAsText(String text) { if (cacheModelClass == null) { throw new IllegalStateException("cacheModelClass should not be null"); } Properties properties = SemicolonSeparatedPropertiesParser.parseProperties(text); BeanWrapper beanWrapper = new BeanWrapperImpl(cacheModelClass); if (properties != null) { for (Iterator i = properties.keySet().iterator(); i.hasNext();) { String propertyName = (String) i.next(); String textProperty = properties.getProperty(propertyName); Object propertyValue = null; PropertyEditor propertyEditor = getPropertyEditor(propertyName); if (propertyEditor != null) { propertyEditor.setAsText(textProperty); propertyValue = propertyEditor.getValue(); } else { propertyValue = textProperty; } beanWrapper.setPropertyValue(propertyName, propertyValue); } } setValue(beanWrapper.getWrappedInstance()); }
From source file:org.apache.rave.util.OverridablePropertyPlaceholderConfigurer.java
@Override protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException { super.processProperties(beanFactoryToProcess, props); // load the application properties into a map that is exposed via public getter resolvedProps = new HashMap<String, String>(); for (Object key : props.keySet()) { String keyStr = key.toString(); resolvedProps.put(keyStr, resolvePlaceholder(keyStr, props, SYSTEM_PROPERTIES_MODE_OVERRIDE)); }/* w w w .j av a 2s . co m*/ }
From source file:de.micromata.genome.tpsb.builder.ScenarioLoaderContext.java
/** * Load a scenario property file./*from w w w . jav a 2s. c om*/ * * @param id the id of the scenario properties * @return a map with the properties */ public Map<String, String> loadLocalPropertiesScenario(String id) { File file = getScenarioFile(id, ".properties"); Map<String, String> map = new HashMap<String, String>(); try { Properties props = new Properties(); FileInputStream fin = new FileInputStream(file); props.load(fin); for (Object k : props.keySet()) { String key = (String) k; map.put(key, props.getProperty((String) k)); } return map; } catch (IOException ex) { throw new RuntimeIOException(ex); } }
From source file:com.liferay.portal.configuration.ExtletConfigurationImpl.java
/** * Merge the .properties file with the portal.properties *//*from www. j a va 2 s . c om*/ protected void addPropertiesToLiferay(InputStream is) throws IOException { if (is == null) { return; } try { Properties props = new Properties(); props.load(is); Properties newProps = new Properties(); for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); if (_log.isDebugEnabled()) { _log.debug("Key found: " + key + ", value is " + props.getProperty(key)); } String newValue; String newKey; // key+=value if (key.endsWith(PLUS_SIGN)) { if (_log.isDebugEnabled()) { _log.debug("Key is ending with +, so we will merge the properties."); } newKey = key.substring(0, key.length() - 1); if (_log.isDebugEnabled()) { _log.debug("New key is: " + newKey); } String oldValue = get(newKey); if ((oldValue == null) || ("".equals(oldValue.trim()))) { if (_log.isDebugEnabled()) { _log.debug("Old value not found, creating new property."); } newValue = props.getProperty(key); } else { if (_log.isDebugEnabled()) { _log.debug("Old value found, it's: " + oldValue + ", therefore I'm merging."); } newValue = oldValue + "," + props.getProperty(key); } } else { // key=value if (_log.isDebugEnabled()) { _log.debug("Key is not ending with +, so I'm in overwrite more."); } newValue = props.getProperty(key); newKey = key; } if (_log.isDebugEnabled()) { _log.debug("Key is: " + newKey); _log.debug("Value is: " + newValue); } newProps.setProperty(newKey, newValue); } // add properties to the original one addProperties(newProps); } finally { if (is != null) { is.close(); } } }
From source file:org.apache.sqoop.mapreduce.odps.OdpsImportJob.java
private Map<String, OdpsType> getColTypeMap() { Map colTypeMap = Maps.newLinkedHashMap(); Properties userMapping = options.getMapColumnOdps(); String[] columnNames = getColumnNames(); for (Object column : userMapping.keySet()) { boolean found = false; for (String c : columnNames) { if (c.equals(column)) { found = true;//from w ww. java 2 s .com break; } } if (!found) { throw new IllegalArgumentException( "No column by the name " + column + "found while importing data"); } } for (String col : columnNames) { String userType = userMapping.getProperty(col); if (userType != null) { colTypeMap.put(col, OdpsType.valueOf(userType)); } else { LOG.warn("Column " + col + " type not specified, defaulting to STRING."); colTypeMap.put(col, OdpsType.STRING); } } return colTypeMap; }
From source file:com.operalot.validator.util.OverridablePropertyPlaceholderConfigurer.java
@Override protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException { super.processProperties(beanFactoryToProcess, props); // generate the application properties into a map that is exposed via public getter resolvedProps = new HashMap<String, String>(); for (Object key : props.keySet()) { String keyStr = key.toString(); resolvedProps.put(keyStr, resolvePlaceholder(keyStr, props, PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE)); }/*from w ww. j a va 2 s.c o m*/ }
From source file:com.adaptris.security.TestCompositeKeystore.java
/** * @see TestCase#setUp()/*from w w w. j av a 2s.c om*/ */ public void setUp() throws Exception { super.setUp(); config = Config.getInstance(); cfg = config.getProperties(); if (cfg == null) { fail("No Configuration(!) available"); } keystoreLocationList = new ArrayList(); config.buildKeystore(cfg.getProperty(Config.KEYSTORE_TEST_URL), null, false); Properties p = config.getPropertySubset(Config.KEYSTORE_COMPOSITE_URLROOT); for (Iterator i = p.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); KeystoreLocation kloc = KeystoreFactory.getDefault().create(cfg.getProperty(key), cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray()); keystoreLocationList.add(kloc); } }
From source file:com.reversemind.hypergate.server.PayloadProcessor.java
private Hashtable getJndiProperties(Properties jndi) { Set set = jndi.keySet(); Hashtable localTable = new Hashtable(); for (Object key : set) { localTable.put(key, jndi.get(key)); }//from w w w .ja va2 s . c o m return localTable; }
From source file:py.una.pol.karaku.configuration.PropertiesUtil.java
@Override protected void processProperties(final ConfigurableListableBeanFactory beanFactory, final Properties props) { super.processProperties(beanFactory, mergeProperties(props)); propertiesMap = new HashMap<String, String>(); for (Object key : props.keySet()) { String keyStr = key.toString(); propertiesMap.put(keyStr, props.getProperty(keyStr)); }//from w ww .j a v a 2 s.c o m }
From source file:com.clearspring.metriccatcher.Loader.java
/** * Load properties, build a MetricCatcher, start catching * * @param propertiesFile The config file * @throws IOException if the properties file cannot be read *//* ww w . j a v a 2 s . co m*/ public Loader(File propertiesFile) throws IOException { logger.info("Starting metriccatcher"); logger.info("Loading configuration from: " + propertiesFile.getAbsolutePath()); Properties properties = new Properties(); try { properties.load(new FileReader(propertiesFile)); for (Object key : properties.keySet()) { // copy properties into system properties System.setProperty((String) key, (String) properties.get(key)); } } catch (IOException e) { logger.error("error reading properties file: " + e); System.exit(1); } int reportingInterval = 60; String intervalProperty = properties.getProperty(METRICCATCHER_INTERVAL); if (intervalProperty != null) { try { reportingInterval = Integer.parseInt(intervalProperty); } catch (NumberFormatException e) { logger.warn("Couldn't parse " + METRICCATCHER_INTERVAL + " setting", e); } } boolean disableJvmMetrics = false; String disableJvmProperty = properties.getProperty(METRICCATCHER_DISABLE_JVM_METRICS); if (disableJvmProperty != null) { disableJvmMetrics = BooleanUtils.toBoolean(disableJvmProperty); if (disableJvmMetrics) { logger.info("Disabling JVM metric reporting"); } } boolean reportingEnabled = false; // Start a Ganglia reporter if specified in the config String gangliaHost = properties.getProperty(METRICCATCHER_GANGLIA_HOST); String gangliaPort = properties.getProperty(METRICCATCHER_GANGLIA_PORT); if (gangliaHost != null && gangliaPort != null) { logger.info("Creating Ganglia reporter pointed at " + gangliaHost + ":" + gangliaPort); GangliaReporter gangliaReporter = new GangliaReporter(gangliaHost, Integer.parseInt(gangliaPort)); gangliaReporter.printVMMetrics = !disableJvmMetrics; gangliaReporter.start(reportingInterval, TimeUnit.SECONDS); reportingEnabled = true; } // Start a Graphite reporter if specified in the config String graphiteHost = properties.getProperty(METRICCATCHER_GRAPHITE_HOST); String graphitePort = properties.getProperty(METRICCATCHER_GRAPHITE_PORT); if (graphiteHost != null && graphitePort != null) { String graphitePrefix = properties.getProperty(METRICCATCHER_GRAPHITE_PREFIX); if (graphitePrefix == null) { graphitePrefix = InetAddress.getLocalHost().getHostName(); } logger.info("Creating Graphite reporter pointed at " + graphiteHost + ":" + graphitePort + " with prefix '" + graphitePrefix + "'"); GraphiteReporter graphiteReporter = new GraphiteReporter(graphiteHost, Integer.parseInt(graphitePort), StringUtils.trimToNull(graphitePrefix)); graphiteReporter.printVMMetrics = !disableJvmMetrics; graphiteReporter.start(reportingInterval, TimeUnit.SECONDS); reportingEnabled = true; } String reporterConfigFile = properties.getProperty(METRICCATCHER_REPORTER_CONFIG); if (reporterConfigFile != null) { logger.info("Trying to load reporterConfig from file: {}", reporterConfigFile); try { ReporterConfig.loadFromFileAndValidate(reporterConfigFile).enableAll(); } catch (Exception e) { logger.error("Failed to load metrics-reporter-config, metric sinks will not be activated", e); } reportingEnabled = true; } if (!reportingEnabled) { logger.error("No reporters enabled. MetricCatcher can not do it's job"); throw new RuntimeException("No reporters enabled"); } int maxMetrics = Integer.parseInt(properties.getProperty(METRICCATCHER_MAX_METRICS, "500")); logger.info("Max metrics: " + maxMetrics); Map<String, Metric> lruMap = new LRUMap<String, Metric>(10, maxMetrics); int port = Integer.parseInt(properties.getProperty(METRICCATCHER_UDP_PORT, "1420")); logger.info("Listening on UDP port " + port); DatagramSocket socket = new DatagramSocket(port); metricCatcher = new MetricCatcher(socket, lruMap); metricCatcher.start(); // Register a shutdown hook and wait for termination Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { shutdown(); }; }); }