List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:com.github.htfv.maven.plugins.buildconfigurator.core.configurators.propertyfiles.PropertyFileConfigurator.java
/** * Updates project properties. Properties are immutable - if there is * already a user or a project property with the same key defined, it will * not be overwritten.// ww w .j a v a 2s . c om * * @param ctx * The configuration context. * @param resultBuilder * The result builder. */ private void updateProjectProperties(final ConfigurationContext ctx, final Result.Builder resultBuilder) { final Configuration properties = ctx.getProperties(); final MavenProject project = ctx.getProject(); final Properties projectProperties = project.getProperties(); final Properties userProperties = project.getProjectBuildingRequest().getUserProperties(); @SuppressWarnings("unchecked") final Iterator<String> keys = properties.getKeys(); while (keys.hasNext()) { final String key = keys.next(); if (userProperties.containsKey(key) || projectProperties.containsKey(key)) { continue; } final String value = ctx.getStringValue(properties.getString(key)); projectProperties.setProperty(key, value); resultBuilder.newProperty(key, value); } }
From source file:com.frentix.restapi.RestConnection.java
/** * Applies the given properties./*from w ww .j a v a 2 s . c o m*/ * * @param properties the Properties */ public void applyProperties(Properties properties) { /* host */ if (properties.containsKey("restconnection.host")) { setHost(properties.getProperty("restconnection.host")); } /* port */ if (properties.containsKey("restconnection.port")) { setPort(Integer.parseInt(properties.getProperty("restconnection.port"))); } /* protocol */ if (properties.containsKey("restconnection.protocol")) { setProtocol(properties.getProperty("restconnection.protocol")); } /* context path */ if (properties.containsKey("restconnection.contextpath")) { setContextPath(properties.getProperty("restconnection.contextpath")); } /* login */ if (properties.containsKey("restconnection.login")) { setLogin(properties.getProperty("restconnection.login")); } /* password */ if (properties.containsKey("restconnection.password")) { setPassword(properties.getProperty("restconnection.password")); } }
From source file:com.facebook.LinkBench.LinkBenchDriver.java
/** * Create a new random number generated, optionally seeded to a known * value from the config file. If seed value not provided, a seed * is chosen. In either case the seed is logged for later reproducibility. * @param props//from www . j a v a2 s . com * @param configKey config key for the seed value * @return */ private Random createMasterRNG(Properties props, String configKey) { long seed; if (props.containsKey(configKey)) { seed = ConfigUtil.getLong(props, configKey); logger.info("Using configured random seed " + configKey + "=" + seed); } else { seed = System.nanoTime() ^ (long) configKey.hashCode(); logger.info("Using random seed " + seed + " since " + configKey + " not specified"); } SecureRandom masterRandom; try { masterRandom = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { logger.warn("SHA1PRNG not available, defaulting to default SecureRandom" + " implementation"); masterRandom = new SecureRandom(); } masterRandom.setSeed(ByteBuffer.allocate(8).putLong(seed).array()); // Can be used to check that rng is behaving as expected logger.debug("First number generated by master " + configKey + ": " + masterRandom.nextLong()); return masterRandom; }
From source file:com.elasticgrid.amazon.boot.Bootstrapper.java
/** * This method translate EC2 lauch parameters into {@link Properties} which can be used through * all Elastic Grid code.// w ww . j ava2 s . com * * @param launchParameters the EC2 launch parameters * @return the Elastic Grid parameters * @throws IOException if the metadata can't be fetched */ private Properties translateProperties(Properties launchParameters) throws IOException { // translate properties Properties egParameters = new Properties(); for (Map.Entry property : launchParameters.entrySet()) { String key = (String) property.getKey(); if (LAUNCH_PARAMETER_ACCESS_ID.equals(key)) egParameters.put(EC2Configuration.AWS_ACCESS_ID, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_ACCESS_ID)) System.err.println("The Amazon Access ID could not be retrieved!"); if (LAUNCH_PARAMETER_SECRET_KEY.equals(key)) egParameters.put(EC2Configuration.AWS_SECRET_KEY, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_SECRET_KEY)) System.err.println("The Amazon Secret Key could not be retrieved!"); if (LAUNCH_PARAMETER_CLUSTER_NAME.equals(key)) egParameters.put(EC2Configuration.EG_CLUSTER_NAME, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_CLUSTER_NAME)) System.err.println("The name of the cluster could not be retrieved!"); if (LAUNCH_PARAMETER_DROP_BUCKET.equals(key)) egParameters.put(EC2Configuration.EG_DROP_BUCKET, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_DROP_BUCKET)) System.err.println("The name of the Amazon S3 drop bucket could not be retrieved!"); if (LAUNCH_PARAMETER_OVERRIDES_URL.equals(key)) egParameters.put(EC2Configuration.EG_OVERRIDES_BUCKET, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_OVERRIDES_URL)) egParameters.put(EC2Configuration.EG_OVERRIDES_BUCKET, ""); if (LAUNCH_PARAMETER_EC2_SECURED.equals(key)) egParameters.put(EC2Configuration.AWS_EC2_SECURED, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_SECURED)) egParameters.put(EC2Configuration.AWS_EC2_SECURED, Boolean.TRUE.toString()); if (LAUNCH_PARAMETER_SQS_SECURED.equals(key)) egParameters.put(EC2Configuration.AWS_SQS_SECURED, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_SQS_SECURED)) egParameters.put(EC2Configuration.AWS_SQS_SECURED, Boolean.TRUE.toString()); if (LAUNCH_PARAMETER_EC2_KEYPAIR.equals(key)) egParameters.put(EC2Configuration.AWS_EC2_KEYPAIR, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_KEYPAIR)) System.err.println("The Amazon keypair name could not be retrieved!"); /* else egParameters.put(EC2Configuration.AWS_EC2_KEYPAIR, EC2Utils.getInstanceMetadata("keypair")); // todo: check the value of the metadata property */ if (LAUNCH_PARAMETER_EC2_AMI32.equals(key)) egParameters.put(EC2Configuration.AWS_EC2_AMI32, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_AMI32)) System.err.println("The 32 bits AMI ID could not be retrieved!"); if (LAUNCH_PARAMETER_EC2_AMI64.equals(key)) egParameters.put(EC2Configuration.AWS_EC2_AMI64, property.getValue()); else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_AMI64)) System.err.println("The 64 bits AMI ID could not be retrieved!"); if (LAUNCH_PARAMETER_YUM_PACKAGES.equals(key)) egParameters.put(EC2Configuration.REDHAT_YUM_PACKAGES, property.getValue()); } return egParameters; }
From source file:com.px100systems.data.browser.controller.MainController.java
public String setUserPassword(String user, String oldPassword, String newPassword) { try {/*from ww w . ja v a 2 s . c o m*/ Properties users = authenticationProvider.getUsers(); if (newPassword == null || newPassword.trim().isEmpty()) return "Empty password"; if (!users.containsKey(user)) return "User not found: " + user; String oldPass = users.getProperty(user); if (oldPass != null && !oldPass.isEmpty() && (oldPassword == null || !passwordEncoder.matches(oldPassword, oldPass))) return "Old password mismatch"; users.setProperty(user, passwordEncoder.encode(newPassword.trim())); authenticationProvider.saveUsers(users); return null; } catch (Exception e) { return e.getMessage(); } }
From source file:com.github.fedorchuck.webstore.config.DataConfig.java
/** * annotation and xml don't want work, like i want. but wrote configuration data in code i don't want. so.. :( *//* w ww .jav a2 s.c o m*/ @SuppressWarnings("unchecked") private void readConfig() { Properties property = new Properties(); try (InputStream is = res.getInputStream()) { property.load(is); Field[] fields = this.getClass().getSuperclass().getDeclaredFields(); String canonicalField; String[] parts; for (Field field : fields) { parts = field.getName().split("DataConfig."); canonicalField = parts[0]; if (property.containsKey("jdbc." + canonicalField)) { field.setAccessible(true); field.set(this, property.get("jdbc." + canonicalField)); } } } catch (IOException | IllegalAccessException | NullPointerException e) { logger.error("problem read config. reason: ", e); } }
From source file:edu.si.services.fits.itest.UCT_FITS_IT.java
@Override public void setUp() throws Exception { //System.getProperties().list(System.out); log.debug("===================[ KARAF_HOME = {} ]===================", System.getProperty("karaf.home")); List<String> propFileList = loadAdditionalPropertyFiles(); if (loadAdditionalPropertyFiles() != null) { for (String propFile : propFileList) { Properties extra = new Properties(); try { extra.load(new FileInputStream(propFile)); this.extra.putAll(extra); } catch (IOException e) { e.printStackTrace();// ww w . java2s.co m } } } for (Map.Entry<Object, Object> p : System.getProperties().entrySet()) { if (extra.containsKey(p.getKey())) { extra.setProperty(p.getKey().toString(), p.getValue().toString()); } } super.setUp(); FITS_URI = extra.getProperty("si.fits.host"); }
From source file:com.google.api.ads.adwords.jaxws.extensions.exporter.ReportExporter.java
/** * Generates the HashMap with all the data from reports * * @param dateStart the start date for the reports * @param dateEnd the end date for the reports * @param accountId the account CID to generate PDF for * @param properties the properties file containing all the configuration * @param sumAdExtensions to add up all the extensions *//*w w w . j ava2s . c o m*/ public Map<String, Object> createReportDataMap(String dateStart, String dateEnd, Long accountId, Properties properties, Boolean sumAdExtensions) { Map<String, Object> reportDataMap = Maps.newHashMap(); Set<ReportDefinitionReportType> reports = csvReportEntitiesMapping.getDefinedReports(); for (ReportDefinitionReportType reportType : reports) { if (properties.containsKey(reportType.name())) { // Adding each report type rows from DB to the accounts montlyeports list. List<Report> monthlyReports = Lists.newArrayList( persister.listMonthReports(csvReportEntitiesMapping.getReportBeanClass(reportType), accountId, DateUtil.parseDateTime(dateStart), DateUtil.parseDateTime(dateEnd))); if (sumAdExtensions && reportType.name() == "PLACEHOLDER_FEED_ITEM_REPORT") { Map<String, NameImprClicks> adExtensionsMap = new HashMap<String, NameImprClicks>(); int sitelinks = 0; for (Report report : monthlyReports) { String clickType = ((ReportPlaceholderFeedItem) report).getClickType(); Long impressions = ((ReportPlaceholderFeedItem) report).getImpressions(); Long clicks = ((ReportPlaceholderFeedItem) report).getClicks(); if (!clickType.equals("Headline")) { if (clickType.equals("Sitelink")) { sitelinks++; } if (adExtensionsMap.containsKey(clickType)) { NameImprClicks oldValues = adExtensionsMap.get(clickType); oldValues.impressions += impressions; oldValues.clicks += clicks; adExtensionsMap.put(clickType, oldValues); } else { NameImprClicks values = new NameImprClicks(); values.impressions = impressions; values.clicks = clicks; adExtensionsMap.put(clickType, values); } } } List<NameImprClicks> adExtensions = new ArrayList<NameImprClicks>(); for (Map.Entry<String, NameImprClicks> entry : adExtensionsMap.entrySet()) { NameImprClicks nic = new NameImprClicks(); nic.clickType = entry.getKey(); if (nic.clickType.equals("Sitelink")) { nic.clickType = "Sitelinks (x" + sitelinks + ")"; } nic.clicks = entry.getValue().clicks; nic.impressions = entry.getValue().impressions; adExtensions.add(nic); } reportDataMap.put("ADEXTENSIONS", adExtensions); } reportDataMap.put(reportType.name(), monthlyReports); } } return reportDataMap; }
From source file:de.innovationgate.webgate.api.jdbc.pool.DBCPReplicationConnectionProvider.java
public void configure(Map propsMap) throws HibernateException { try {/*from ww w. j ava2 s .c o m*/ log.info("Configure DBCPReplicationConnectionProvider"); Properties props = new Properties(); props.putAll(propsMap); String jdbcUrl = props.getProperty(Environment.URL); // split jdbcURL by "|" and configure masterDS for first and slaveDataSources for all other URLs _jdbcUrls = jdbcUrl.split("\\|"); // spec. configuration for dbcp if (!props.containsKey("hibernate.connection.connectTimeout")) { props.setProperty("hibernate.dbcp.poolPreparedStatements", "true"); } if (!props.containsKey("hibernate.connection.connectTimeout")) { props.setProperty("hibernate.connection.connectTimeout", "5000"); } if (!props.containsKey("hibernate.connection.socketTimeout")) { props.setProperty("hibernate.connection.socketTimeout", "20000"); } if (!props.containsKey("hibernate.dbcp.testOnBorrow")) { props.setProperty("hibernate.dbcp.testOnBorrow", "true"); } if (!props.containsKey("hibernate.dbcp.validationQuery")) { props.setProperty("hibernate.dbcp.validationQuery", "select 1"); } // create master DS log.info("configuring master datasource on url: " + _jdbcUrls[0]); Properties masterProps = (Properties) props.clone(); masterProps.setProperty(Environment.URL, _jdbcUrls[0]); DBCPConnectionProvider masterProvider = new DBCPConnectionProvider(); masterProvider.configure(masterProps); _masterDS = masterProvider.getDs(); // create slave datasources for (int i = 1; i < _jdbcUrls.length; i++) { log.info("configuring slave datasource on url: " + _jdbcUrls[i]); Properties slaveProps = (Properties) props.clone(); slaveProps.setProperty(Environment.URL, _jdbcUrls[i]); DBCPConnectionProvider slaveProvider = new DBCPConnectionProvider(); slaveProvider.configure(slaveProps); _slaveDSList.add(slaveProvider.getDs()); } log.info("Configure DBCPReplicationConnectionProvider complete"); } catch (Exception e) { log.fatal("Could not create DBCPReplicationConnectionProvider.", e); throw new HibernateException("Could not create DBCPReplicationConnectionProvider.", e); } }
From source file:com.formkiq.core.service.notification.MailSenderService.java
/** * @param prop {@link Properties}/* w w w . ja va 2 s. com*/ * @return {@link JavaMailSenderImpl} * @throws IOException IOException */ private JavaMailSenderImpl createJavaMailSender(final Properties prop) throws IOException { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(prop.getProperty("mail.host")); sender.setPort(Integer.parseInt(prop.getProperty("mail.port"))); sender.setUsername(prop.getProperty("mail.username")); sender.setPassword(prop.getProperty("mail.password")); Properties property = sender.getJavaMailProperties(); if (prop.containsKey("mail.smtp.auth")) { property.setProperty("mail.smtp.auth", prop.getProperty("mail.smtp.auth")); } if (prop.containsKey("mail.smtp.starttls.enable")) { property.setProperty("mail.smtp.starttls.enable", prop.getProperty("mail.smtp.starttls.enable")); } if (prop.containsKey("mail.smtp.quitwait")) { property.setProperty("mail.smtp.quitwait", prop.getProperty("mail.smtp.quitwait")); } LOG.log(Level.INFO, "Setting mail.host = " + sender.getHost() + ":" + sender.getPort()); LOG.log(Level.INFO, "Setting mail.username = " + sender.getUsername()); for (Map.Entry<Object, Object> e : sender.getJavaMailProperties().entrySet()) { LOG.log(Level.INFO, "Setting " + e.getKey() + " = " + e.getValue()); } return sender; }