List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:info.magnolia.importexport.PropertiesImportExport.java
public void createContent(Content root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream);//w ww. j a va2 s . com properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, ItemType.CONTENTNODE.getSystemName()); Content c = ContentUtil.createPath(root, path, new ItemType(type)); populateContent(c, propertyName, valueStr); } }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
@Override protected DriverPropertyInfo[] getPropertyInfo(Properties connProps, List<DriverPropertyInfo> baseDriverProps) { DriverPropertyInfo[] driverProps = new DriverPropertyInfo[10 + baseDriverProps.size()]; this.copyBaseProperties(driverProps, baseDriverProps, 10); // Query Endpoint parameter driverProps[0] = new DriverPropertyInfo(PARAM_QUERY_ENDPOINT, connProps.getProperty(PARAM_QUERY_ENDPOINT)); driverProps[0].required = !connProps.containsKey(PARAM_UPDATE_ENDPOINT); driverProps[0].description = "Sets the SPARQL Query endpoint to use for query operations, if this is specified and " + PARAM_UPDATE_ENDPOINT + " is not then a read-only connection will be created"; // Update Endpoint parameter driverProps[1] = new DriverPropertyInfo(PARAM_UPDATE_ENDPOINT, connProps.getProperty(PARAM_UPDATE_ENDPOINT)); driverProps[1].required = !connProps.containsKey(PARAM_UPDATE_ENDPOINT); driverProps[1].description = "Sets the SPARQL Update endpoint to use for update operations, if this is specified and " + PARAM_QUERY_ENDPOINT + " is not then a write-only connection will be created"; // Default Graph parameter driverProps[2] = new DriverPropertyInfo(PARAM_DEFAULT_GRAPH_URI, null); driverProps[2].required = false;//from www . ja va 2s . com driverProps[2].description = "Sets the URI for a default graph for queries, may be specified multiple times to specify multiple graphs which should form the default graph"; // Named Graph parameter driverProps[3] = new DriverPropertyInfo(PARAM_NAMED_GRAPH_URI, null); driverProps[3].required = false; driverProps[3].description = "Sets the URI for a named graph for queries, may be specified multiple times to specify multiple named graphs which should be accessible"; // Using Graph parameter driverProps[4] = new DriverPropertyInfo(PARAM_USING_GRAPH_URI, null); driverProps[4].required = false; driverProps[4].description = "Sets the URI for a default graph for updates, may be specified multiple times to specify multiple graphs which should form the default graph"; // Using Named Graph parameter driverProps[5] = new DriverPropertyInfo(PARAM_USING_NAMED_GRAPH_URI, null); driverProps[5].required = false; driverProps[5].description = "Sets the URI for a named graph for updates, may be specified multiple times to specify multiple named graph which should be accessible"; // Results Types driverProps[6] = new DriverPropertyInfo(PARAM_SELECT_RESULTS_TYPE, connProps.getProperty(PARAM_SELECT_RESULTS_TYPE)); driverProps[6].required = false; driverProps[6].description = "Sets the results type for SELECT queries that will be requested from the remote endpoint"; driverProps[7] = new DriverPropertyInfo(PARAM_MODEL_RESULTS_TYPE, connProps.getProperty(PARAM_MODEL_RESULTS_TYPE)); driverProps[7].required = false; driverProps[7].description = "Sets the results type for CONSTRUCT and DESCRIBE queries that will be requested from the remote endpoint"; // User Name parameter driverProps[8] = new DriverPropertyInfo(PARAM_USERNAME, connProps.getProperty(PARAM_USERNAME)); // Password parameter driverProps[9] = new DriverPropertyInfo(PARAM_PASSWORD, connProps.getProperty(PARAM_PASSWORD)); return driverProps; }
From source file:cz.alej.michalik.totp.client.AddDialog.java
/** * Odele nov zznam/*from w ww . j a v a 2 s.c o m*/ * * @param prop * Properties * @param name * Textov pole s jmnem * @param secret * Textov pole s heslem * @param exitOnError * Zave okno i pi chyb, pokud uivatel klikne na kek */ private void submit(final Properties prop, final JTextField name, final JTextField secret, boolean exitOnError) { System.out.printf("Jmno: %s | Heslo: %s\n", name.getText(), secret.getText()); boolean error = false; sanitize(secret); if (name.getText().equals("") || secret.getText().equals("") || !verify(secret)) { System.out.println("Nepidno"); error = true; } else { System.out.printf("Base32 heslo je: %s\n", new Base32().encodeToString(secret.getText().getBytes())); int id = prop.size(); // Po odstrann me bt nkter index pesko?en while (prop.containsKey(String.valueOf(id))) { id++; } StringBuilder sb = new StringBuilder(); // Zznam je ve tvaru "jmno;heslo" sb.append(name.getText()); sb.append(";"); sb.append(secret.getText()); prop.setProperty(String.valueOf(id), sb.toString()); App.saveProperties(); App.loadProperties(); } if (exitOnError || !error) { this.dispose(); } }
From source file:io.warp10.standalone.StandaloneIngressHandler.java
public StandaloneIngressHandler(KeyStore keystore, StandaloneDirectoryClient directoryClient, StoreClient storeClient) {//ww w . j a va 2 s . c om this.keyStore = keystore; this.storeClient = storeClient; this.directoryClient = directoryClient; this.classKey = this.keyStore.getKey(KeyStore.SIPHASH_CLASS); this.classKeyLongs = SipHashInline.getKey(this.classKey); this.labelsKey = this.keyStore.getKey(KeyStore.SIPHASH_LABELS); this.labelsKeyLongs = SipHashInline.getKey(this.labelsKey); Properties props = WarpConfig.getProperties(); if (props.containsKey(Configuration.DATALOG_DIR)) { File dir = new File(props.getProperty(Configuration.DATALOG_DIR)); if (!dir.exists()) { throw new RuntimeException("Data logging target '" + dir + "' does not exist."); } else if (!dir.isDirectory()) { throw new RuntimeException("Data logging target '" + dir + "' is not a directory."); } else { loggingDir = dir; LOG.info("Data logging enabled in directory '" + dir + "'."); } String id = props.getProperty(Configuration.DATALOG_ID); if (null == id) { throw new RuntimeException("Property '" + Configuration.DATALOG_ID + "' MUST be set to a unique value for this instance."); } else { datalogId = new String(OrderPreservingBase64.encode(id.getBytes(Charsets.UTF_8)), Charsets.US_ASCII); } } else { loggingDir = null; datalogId = null; } if (props.containsKey(Configuration.DATALOG_PSK)) { this.datalogPSK = this.keyStore.decodeKey(props.getProperty(Configuration.DATALOG_PSK)); } else { this.datalogPSK = null; } this.logforwarded = "true".equals(props.getProperty(Configuration.DATALOG_LOGFORWARDED)); this.maxValueSize = Long .parseLong(props.getProperty(Configuration.STANDALONE_VALUE_MAXSIZE, DEFAULT_VALUE_MAXSIZE)); }
From source file:org.aon.esolutions.appconfig.client.web.SystemPropertiesListener.java
private void loadPropsFromSystem(ServletContext sc) { String propertiesLocationProp = sc.getInitParameter("properties.location.property"); String privateKeyLocationProp = sc.getInitParameter("privatekey.location.property"); String applicationName = sc.getInitParameter("application.name"); String environmentName = sc.getInitParameter("environment.name"); Properties props = System.getProperties(); String propertiesFileLocation = props.getProperty(propertiesLocationProp); String privateKeyLocation = props.getProperty(privateKeyLocationProp); if (StringUtils.isEmpty(propertiesFileLocation)) { logger.warn("Not loading properties from system property (" + propertiesLocationProp + ") as it was not provided."); return;//from w w w . j a va2s .c o m } AppConfigClientFactory acClient = new AppConfigClientFactory(); acClient.setPropertiesFileName(propertiesFileLocation); acClient.setPrivateKeyFileName(privateKeyLocation); Properties loadedProps = acClient.getAppConfigClient().loadProperties(applicationName, environmentName); for (Map.Entry<Object, Object> e : loadedProps.entrySet()) { if (props.containsKey(e.getKey()) == false) props.put(e.getKey(), e.getValue()); } }
From source file:org.apache.gobblin.runtime.mapreduce.MRJobLauncherTest.java
/** * Byteman test that ensures the {@link MRJobLauncher} successfully cleans up all staging data even * when an exception is thrown in the {@link MRJobLauncher#countersToMetrics(GobblinMetrics)} method. * The {@link BMRule} is to inject an {@link IOException} when the * {@link MRJobLauncher#countersToMetrics(GobblinMetrics)} method is called. */// ww w.j ava 2s .c o m @Test @BMRule(name = "testJobCleanupOnError", targetClass = "org.apache.gobblin.runtime.mapreduce.MRJobLauncher", targetMethod = "countersToMetrics(GobblinMetrics)", targetLocation = "AT ENTRY", condition = "true", action = "throw new IOException(\"Exception for testJobCleanupOnError\")") public void testJobCleanupOnError() throws IOException { Properties props = loadJobProps(); try { this.jobLauncherTestHelper.runTest(props); Assert.fail("Byteman is not configured properly, the runTest method should have throw an exception"); } catch (Exception e) { // The job should throw an exception, ignore it } finally { this.jobLauncherTestHelper.deleteStateStore(props.getProperty(ConfigurationKeys.JOB_NAME_KEY)); } Assert.assertTrue(props.containsKey(ConfigurationKeys.WRITER_STAGING_DIR)); Assert.assertTrue(props.containsKey(ConfigurationKeys.WRITER_OUTPUT_DIR)); File stagingDir = new File(props.getProperty(ConfigurationKeys.WRITER_STAGING_DIR)); File outputDir = new File(props.getProperty(ConfigurationKeys.WRITER_OUTPUT_DIR)); Assert.assertEquals(FileUtils.listFiles(stagingDir, null, true).size(), 0); if (outputDir.exists()) { Assert.assertEquals(FileUtils.listFiles(outputDir, null, true).size(), 0); } }
From source file:com.adaptris.jdbc.connection.FailoverDataSource.java
private void init(Properties p) { if (p == null) { throw new RuntimeException("No Configuration available "); }//w ww. j a va 2 s .c o m for (int i = 0; i < REQUIRED_PROPERTIES.length; i++) { if (!p.containsKey(REQUIRED_PROPERTIES[i])) { throw new RuntimeException("Missing Configuration " + REQUIRED_PROPERTIES[i]); } } databaseConfig = new FailoverConfig(p); poolMaximum = Integer.parseInt(p.getProperty(POOL_MAX_SIZE, "10")); poolTimeToWait = Integer.parseInt(p.getProperty(POOL_TIME_TO_WAIT, "20000")); pool = new GenericObjectPool(new PoolAttendant(databaseConfig), poolMaximum, GenericObjectPool.WHEN_EXHAUSTED_BLOCK, poolTimeToWait); pool.setTestOnBorrow(true); pool.setTestWhileIdle(true); }
From source file:com.infochimps.hadoop.pig.hbase.StaticFamilyStorage.java
@Override public void setStoreLocation(String location, Job job) throws IOException { if (location.startsWith("hbase://")) { job.getConfiguration().set(HBaseTableOutputFormat.OUTPUT_TABLE, location.substring(8)); } else {/* w w w . j a v a 2 s.c o m*/ job.getConfiguration().set(HBaseTableOutputFormat.OUTPUT_TABLE, location); } Properties props = UDFContext.getUDFContext().getUDFProperties(getClass(), new String[] { contextSignature }); if (!props.containsKey(contextSignature + "_schema")) { props.setProperty(contextSignature + "_schema", ObjectSerializer.serialize(schema_)); } m_conf = HBaseConfiguration.addHbaseResources(job.getConfiguration()); if (m_conf.get(HAS_BEEN_UPLOADED) == null) { HadoopUtils.uploadLocalFile(new Path(LOCAL_SCHEME + hbaseConfig_), new Path(HBASE_CONFIG_HDFS_PATH), m_conf); HadoopUtils.shipIfNotShipped(new Path(HBASE_CONFIG_HDFS_PATH), m_conf); m_conf.set(HAS_BEEN_UPLOADED, "true"); } }
From source file:org.apache.hive.hcatalog.pig.HCatLoader.java
@Override public void setLocation(String location, Job job) throws IOException { HCatContext.INSTANCE.setConf(job.getConfiguration()).getConf().get() .setBoolean(HCatConstants.HCAT_DATA_TINY_SMALL_INT_PROMOTION, true); Properties udfProps = getUdfProperties(); job.getConfiguration().set(INNER_SIGNATURE, INNER_SIGNATURE_PREFIX + "_" + signature); Pair<String, String> dbTablePair = PigHCatUtil.getDBTableNames(location); dbName = dbTablePair.first;/*from ww w . j av a 2s . c o m*/ tableName = dbTablePair.second; if (udfProps.containsKey(HCatConstants.HCAT_PIG_LOADER_LOCATION_SET)) { // setLocation() has been called on this Loader before. // Don't call HCatInputFormat.setInput(). Why? // 1. Can be expensive. E.g. Metastore.getPartitions(). // 2. Can't call getPartitions() in backend. // Instead, restore settings from UDFContext. restoreLoaderSpecificStateFromUDFContext(job, udfProps); if (!HCatUtil.checkJobContextIfRunningFromBackend(job)) { // Combine credentials and credentials from job takes precedence for freshness Credentials crd = jobCredentials.get(INNER_SIGNATURE_PREFIX + "_" + signature); job.getCredentials().addAll(crd); } } else { // This is the first time setLocation() was called. // Must bear the full cost of setInput(). Job localJob = getLocalJobClone(job); // Leave actual jobConf unchanged. HCatInputFormat.setInput(localJob, dbName, tableName, getPartitionFilterString()); String serializedInputJobInfo = localJob.getConfiguration().get(HCatConstants.HCAT_KEY_JOB_INFO); // Place in cache, awaiting HCatInputFormat construction. cacheForSerializedJobInfo.put(signature, serializedInputJobInfo); InputJobInfo inputJobInfo = (InputJobInfo) HCatUtil.deserialize(serializedInputJobInfo); SpecialCases.addSpecialCasesParametersForHCatLoader(localJob.getConfiguration(), inputJobInfo.getTableInfo()); // Prefetch data-size statistics. long dataSizeInMB = getSizeInBytes(inputJobInfo) / 1024 / 1024; LOG.info("Prefetched value for dataSizeInMB: " + dataSizeInMB); localJob.getConfiguration().setLong(HCAT_KEY_INPUT_DATA_SIZE_MB, dataSizeInMB); // Clear PartInfo from inputJobInfo, before serialization (to reduce size of udfProps). LOG.info("Number of part infos: " + inputJobInfo.getPartitions().size()); inputJobInfo.getPartitions().clear(); String serializedInputJobInfoWithoutPartInfo = HCatUtil.serialize(inputJobInfo); localJob.getConfiguration().set(HCatConstants.HCAT_KEY_JOB_INFO, serializedInputJobInfoWithoutPartInfo); LOG.info("Before clearing PartInfo, serializedInputJobInfo size == " + serializedInputJobInfo.length()); LOG.info("After clearing PartInfo, serializedInputJobInfo size == " + serializedInputJobInfoWithoutPartInfo.length()); // Store changed properties in localJob into UDF-properties. storeDifferenceToUDFProperties(localJob.getConfiguration(), job.getConfiguration(), udfProps); // ... and that's all she wrote. udfProps.put(HCatConstants.HCAT_PIG_LOADER_LOCATION_SET, true); // Store credentials in a private hash map and not the udf context to // make sure they are not public. Credentials crd = new Credentials(); crd.addAll(localJob.getCredentials()); // In case they were updated in setInput(). jobCredentials.put(INNER_SIGNATURE_PREFIX + "_" + signature, crd); } // setLocation() could be called several times, before and after pushProjection() is called. // Must check and store projection-columns to UDFContext. setProjectionSchemaInfoInUDFContext(job, udfProps); // Handle pushdown predicate. predicatePushdownEnabled = job.getConfiguration() .getBoolean(HCatConstants.HCAT_PIG_LOADER_PREDICATE_PUSHDOWN_ENABLED, false); if (predicatePushdownEnabled) { LOG.info("Predicate push-down is enabled for HCatLoader."); String pushdownPredicate = udfProps.getProperty(signature + PREDICATE_FOR_PUSHDOWN_SUFFIX); if (StringUtils.isNotBlank(pushdownPredicate)) { LOG.info("Pushing down predicate."); Job localJob = getLocalJobClone(job); HCatInputFormat.setPushdownPredicate(localJob, pushdownPredicate); storeDifferenceToUDFProperties(localJob.getConfiguration(), job.getConfiguration(), udfProps); } else { LOG.info("Predicate is empty/blank. Skipping push-down-predicate."); } } else { LOG.info("Predicate push-down is disabled for HCatLoader."); } }
From source file:com.smartitengineering.loadtest.engine.impl.LoadTestEngineImpl.java
public void init(String testName, Set<UnitTestInstance> testInstances, Properties initProperties) throws IllegalArgumentException, IllegalStateException { if (getState().getStateStep() != State.CREATED.getStateStep()) { throw new IllegalStateException(); }// w ww. ja va 2s . com if (testName == null || testName.length() <= 0) { throw new IllegalArgumentException(); } if (testInstances == null || testInstances.isEmpty()) { throw new IllegalArgumentException(); } if (initProperties != null && !initProperties.isEmpty()) { if (initProperties.containsKey(PROPS_PERMIT_KEY)) { try { setPermits(Integer.parseInt(initProperties.getProperty(PROPS_PERMIT_KEY))); } catch (Exception ex) { ex.printStackTrace(); setPermits(-1); } } } initializeInternals(testName); initializeFinishDetector(); initializeResult(testName); initializeTestInstances(testInstances); setState(State.INITIALIZED); }