List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:ch.bfh.uniboard.typed.TypedService.java
@Override protected Attributes beforePost(byte[] message, Attributes alpha, Attributes beta) { Properties p = this.configurationManager.getConfiguration(CONFIG_NAME); if (p == null) { logger.log(Level.SEVERE, "Configuration for component " + CONFIG_NAME + " is missing."); beta.add(Attributes.ERROR, new StringValue("BGT-003 This UniBoard instance is down due to a configuration error.")); return beta; }//from w ww . j ava2s .c o m if (p.containsKey(NON_GROUPED_MODE)) { String schemaPath = p.getProperty(NON_GROUPED_MODE); if (this.validate(new String(message, Charset.forName("UTF-8")), schemaPath)) { return beta; } else { beta.add(Attributes.REJECTED, new StringValue("BGT-005 Message does not match the schema.")); return beta; } } else { if (!alpha.containsKey(ATTRIBUTE_NAME)) { beta.add(Attributes.REJECTED, new StringValue("BGT-001 Missing required attribute: " + ATTRIBUTE_NAME)); return beta; } if (!(alpha.getValue(ATTRIBUTE_NAME) instanceof StringValue)) { beta.add(Attributes.REJECTED, new StringValue( "BGT-002 Required attribute: " + ATTRIBUTE_NAME + " is not of type string.")); return beta; } StringValue group = (StringValue) alpha.getValue(ATTRIBUTE_NAME); if (!p.containsKey(group.getValue())) { beta.add(Attributes.REJECTED, new StringValue("BGT-004 Unknown " + ATTRIBUTE_NAME + ": " + group.getValue())); return beta; } String schemaPath = p.getProperty(group.getValue()); if (this.validate(new String(message, Charset.forName("UTF-8")), schemaPath)) { return beta; } else { beta.add(Attributes.REJECTED, new StringValue("BGT-006 Message is not of type " + group.getValue())); return beta; } } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ExtractData.java
@Override public void run(CommandLine commandLine) throws Exception { String separator = commandLine.hasOption("separator") ? commandLine.getOptionValue("separator") : " "; String[] fields = commandLine.getArgs(); // indicators are prepared, run the data extraction routine ResultFileReader input = null;//from w w w . j a v a2s . co m PrintStream output = null; try { // setup the problem if (commandLine.hasOption("problem")) { problem = ProblemFactory.getInstance().getProblem(commandLine.getOptionValue("problem")); } else { problem = new ProblemStub(Integer.parseInt(commandLine.getOptionValue("dimension"))); } try { input = new ResultFileReader(problem, new File(commandLine.getOptionValue("input"))); try { output = commandLine.hasOption("output") ? new PrintStream(new File(commandLine.getOptionValue("output"))) : System.out; // optionally print header line if (!commandLine.hasOption("noheader")) { output.print('#'); for (int i = 0; i < fields.length; i++) { if (i > 0) { output.print(separator); } output.print(fields[i]); } output.println(); } // process entries while (input.hasNext()) { ResultEntry entry = input.next(); Properties properties = entry.getProperties(); for (int i = 0; i < fields.length; i++) { if (i > 0) { output.print(separator); } if (properties.containsKey(fields[i])) { output.print(properties.getProperty(fields[i])); } else if (fields[i].startsWith("+")) { output.print(evaluate(fields[i].substring(1), entry, commandLine)); } else { throw new FrameworkException("missing field"); } } output.println(); } } finally { if ((output != null) && (output != System.out)) { output.close(); } } } finally { if (input != null) { input.close(); } } } finally { if (problem != null) { problem.close(); } } }
From source file:com.dtolabs.rundeck.core.common.impl.URLFileUpdater.java
/** * Add appropriate cache headers to the request method, but only if there is valid data in the cache (content type * as well as file content)/*from w ww.j a v a 2s .c o m*/ */ private void applyCacheHeaders(final Properties cacheProperties, final httpClientInteraction method) { if (isCachedContentPresent() && null != contentType) { if (cacheProperties.containsKey(E_TAG)) { method.setRequestHeader(IF_NONE_MATCH, cacheProperties.getProperty(E_TAG)); } if (cacheProperties.containsKey(LAST_MODIFIED)) { method.setRequestHeader(IF_MODIFIED_SINCE, cacheProperties.getProperty(LAST_MODIFIED)); } } }
From source file:gobblin.util.SchedulerUtilsTest.java
@Test public void testloadGenericJobConfig() throws ConfigurationException, IOException { Path jobConfigPath = new Path(this.subDir11.getAbsolutePath(), "test111.pull"); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); Properties jobProps = SchedulerUtils.loadGenericJobConfig(properties, jobConfigPath, new Path(this.jobConfigDir.getAbsolutePath())); Assert.assertEquals(jobProps.stringPropertyNames().size(), 7); Assert.assertTrue(jobProps.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps.getProperty("k1"), "d1"); Assert.assertEquals(jobProps.getProperty("k2"), "a2"); Assert.assertEquals(jobProps.getProperty("k3"), "a3"); Assert.assertEquals(jobProps.getProperty("k8"), "a8"); Assert.assertEquals(jobProps.getProperty("k9"), "a8"); }
From source file:it.larusba.neo4j.jdbc.http.driver.CypherExecutor.java
/** * Default constructor./*from w ww. j ava 2s.c om*/ * * @param host Hostname of the Neo4j instance. * @param port HTTP port of the Neo4j instance. * @param properties Properties of the url connection. * @throws SQLException */ public CypherExecutor(String host, Integer port, Properties properties) throws SQLException { // Create the http client builder HttpClientBuilder builder = HttpClients.custom(); // Adding authentication to the http client if needed if (properties.containsKey("user") && properties.containsKey("password")) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials( properties.get("user").toString(), properties.get("password").toString())); builder.setDefaultCredentialsProvider(credsProvider); } // Setting user-agent StringBuilder sb = new StringBuilder(); sb.append("Neo4j JDBC Driver"); if (properties.containsKey("userAgent")) { sb.append(" via "); sb.append(properties.getProperty("userAgent")); } builder.setUserAgent(sb.toString()); // Create the http client this.http = builder.build(); // Create the url endpoint StringBuffer sbEndpoint = new StringBuffer(); sbEndpoint.append("http://").append(host).append(":").append(port).append("/db/data/transaction"); this.transactionUrl = sbEndpoint.toString(); // Setting autocommit this.setAutoCommit(Boolean.valueOf(properties.getProperty("autoCommit", "true"))); }
From source file:com.meltmedia.cadmium.core.messaging.jgroups.JGroupsMembershipTracker.java
private void handleSyncRequest(View new_view) { log.info("Here is the new view {}", new_view); final ChannelMember coordinator = getCoordinator(); if (coordinator != null && !coordinator.isMine()) { timer.schedule(new TimerTask() { public void run() { log.debug("I'm not the coordinator!!!"); if (gitService != null) { try { log.debug("Waiting for content git service to initialize."); gitService.getGitService(); gitService.releaseGitService(); } catch (Throwable t) { }// w w w . j a v a2 s . co m } if (configGitService != null) { try { log.debug("Waiting for config git service to initialize."); configGitService.getGitService(); configGitService.releaseGitService(); } catch (Throwable t) { } } Properties configProperties = configManager.getDefaultProperties(); SyncRequest request = new SyncRequest(); if (configProperties.containsKey("repo") && configProperties.containsKey("branch") && configProperties.containsKey("git.ref.sha")) { request.setContentLocation(new GitLocation(configProperties.getProperty("repo"), configProperties.getProperty("branch"), configProperties.getProperty("git.ref.sha"))); log.info("I have repo:{}, branch:{}, and sha:{} for content", new Object[] { configProperties.getProperty("repo"), configProperties.getProperty("branch"), configProperties.getProperty("git.ref.sha") }); } if (configProperties.containsKey("config.repo") && configProperties.containsKey("config.branch") && configProperties.containsKey("config.git.ref.sha")) { request.setConfigLocation(new GitLocation(configProperties.getProperty("config.repo"), configProperties.getProperty("config.branch"), configProperties.getProperty("config.git.ref.sha"))); log.info("I have repo:{}, branch:{}, and sha:{} for configuration", new Object[] { configProperties.getProperty("config.repo"), configProperties.getProperty("config.branch"), configProperties.getProperty("config.git.ref.sha") }); } Message<SyncRequest> syncMessage = new Message<SyncRequest>(ProtocolMessage.SYNC, request); try { sender.sendMessage(syncMessage, coordinator); } catch (Exception e) { log.warn("Failed to send sync message: {}", e.getMessage()); } } }, 50l); } }
From source file:org.alfresco.repo.admin.patch.impl.SiteLoadPatch.java
/** * Load the site in.<br/>//from www .j a v a2s . com * Site will be loaded as admin user. */ private String applyInternalImpl() throws Exception { if (descriptorService != null) { // if the descriptor service is wired up only load the site at install time (and not on upgrade) Descriptor installed = descriptorService.getInstalledRepositoryDescriptor(); Descriptor live = descriptorService.getServerDescriptor(); if (!installed.getVersion().equals(live.getVersion())) { return I18NUtil.getMessage(MSG_SITE_NOT_CREATED, siteName); } } if (bootstrapViews == null || bootstrapViews.size() == 0) { if (logger.isDebugEnabled()) { logger.debug("No Bootstraps given to import from - bootstrap import ignored"); } return I18NUtil.getMessage(MSG_NO_BOOTSTRAP_VIEWS_GIVEN, siteName); } // Is the site already there? // (Run now as we need DB + Security Context) if (siteService.getSite(siteName) != null) { if (logger.isDebugEnabled()) { logger.debug("Site " + siteName + " already exists - bootstrap import ignored"); } return I18NUtil.getMessage(MSG_SITE_ALREADY_EXISTS, siteName); } // If we get here, we're good to go! if (logger.isDebugEnabled()) { logger.debug("Performing bootstrap of site " + siteName); } // Create the site as the admin user SiteInfo site = siteService.createSite(siteName, siteName, siteName, null, SiteVisibility.PUBLIC); // At this point we can go back to being the system AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); // Setup the Importer Bootstrap Beans for (ImporterBootstrap bootstrap : new ImporterBootstrap[] { spacesBootstrap, usersBootstrap }) { bootstrap.setAllowWrite(true); bootstrap.setUseExistingStore(true); bootstrap.setUuidBinding(UUID_BINDING.REPLACE_EXISTING); } // Normally paths aren't given for the views, so supply // the defaults where they weren't for (String type : DEFAULT_PATHS.keySet()) { Properties props = bootstrapViews.get(type); if (props != null && DEFAULT_PATHS.get(type) != null) { if (!props.containsKey("path")) { props.setProperty("path", DEFAULT_PATHS.get(type)); } } } // Load our various bootstraps, in the required order // for things to come in correctly // Load any users requested if (bootstrapViews.containsKey(PROPERTIES_USERS)) { List<Properties> views = new ArrayList<Properties>(1); views.add(bootstrapViews.get(PROPERTIES_USERS)); usersBootstrap.setBootstrapViews(views); usersBootstrap.bootstrap(); } // Load any people requested if (bootstrapViews.containsKey(PROPERTIES_PEOPLE)) { List<Properties> views = new ArrayList<Properties>(1); views.add(bootstrapViews.get(PROPERTIES_PEOPLE)); spacesBootstrap.setBootstrapViews(views); spacesBootstrap.bootstrap(); } // Put people into groups if (bootstrapViews.containsKey(PROPERTIES_GROUPS)) { try { doGroupImport(bootstrapViews.get(PROPERTIES_GROUPS).getProperty("location")); } catch (Throwable t) { throw new AlfrescoRuntimeException("Bootstrap failed", t); } } // Load the Main (ACP) Contents if (bootstrapViews.containsKey(PROPERTIES_CONTENTS)) { // Disable the behaviour which prevents site deletion. behaviourFilter.disableBehaviour(site.getNodeRef(), ContentModel.ASPECT_UNDELETABLE); try { // Clear up the stub content that createSite gave us, first // apply the temporary aspect though to prevent the node from // being archived nodeService.addAspect(site.getNodeRef(), ContentModel.ASPECT_TEMPORARY, null); nodeService.deleteNode(site.getNodeRef()); } finally { behaviourFilter.enableBehaviour(site.getNodeRef(), ContentModel.ASPECT_UNDELETABLE); } // Now load in the real content from the ACP List<Properties> views = new ArrayList<Properties>(1); views.add(bootstrapViews.get(PROPERTIES_CONTENTS)); spacesBootstrap.setBootstrapViews(views); spacesBootstrap.bootstrap(); } return I18NUtil.getMessage(MSG_SITE_CREATED, siteName); }
From source file:kenh.xscript.database.elements.Datasource.java
public void process(@Attribute(ATTRIBUTE_VARIABLE) String var) throws UnsupportedScriptException { var = StringUtils.trimToEmpty(var); if (StringUtils.isBlank(var)) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Variable name is empty."); throw ex; }/*from w ww . j a va 2 s . co m*/ Properties properties = new Properties(); this.invokeChildren(); Vector<Element> children = this.getChildren(); for (Element child : children) { if (child instanceof Param) { Param c = (Param) child; String name = c.getName(); Object value = Param.getParsedValue(c); if (c.isLink()) { String linkName = c.getLinkName(); if (!properties.containsKey(linkName)) new UnsupportedScriptException(this, "Could not find the parameter to link. [" + name + ", " + linkName + "]"); value = properties.get(linkName); } properties.put(name, value); } } try { DataSource datasource = BasicDataSourceFactory.createDataSource(properties); this.saveVariable(var, datasource, null); } catch (Exception e) { throw new UnsupportedScriptException(this, e); } }
From source file:org.deegree.console.ResourceManagerMetadata2.java
private ResourceManagerMetadata2(ResourceManager mgr) { if (mgr.getMetadata() != null) { for (Object o : mgr.getMetadata().getResourceProviders()) { ResourceProvider provider = (ResourceProvider) o; ResourceProviderMetadata providerMd = ResourceProviderMetadata.getMetadata(provider); providers.add(provider);// w ww .ja va2s . co m providerNames.add(providerMd.getName()); nameToProvider.put(providerMd.getName(), provider); } } else { providers = Collections.emptyList(); } String className = mgr.getClass().getName(); URL url = ResourceManagerMetadata2.class.getResource("/META-INF/console/resourcemanager/" + className); if (url != null) { LOG.debug("Loading resource manager metadata from '" + url + "'"); Properties props = new Properties(); InputStream is = null; try { is = url.openStream(); props.load(is); name = props.getProperty("name"); if (name != null) { name = name.trim(); } category = props.getProperty("category"); if (props.containsKey("start_view")) { startView = props.getProperty("start_view").trim(); } } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } this.mgr = mgr; }
From source file:org.accada.reader.hal.impl.sim.SimulatorClient.java
public SimulatorClient() throws SimulatorServerException { // load properties from properties file Properties props; try {/*from w w w .j a v a2 s. c om*/ props = new Properties(); props.load(this.getClass().getResourceAsStream(PROPERTIES_FILE_LOCATION)); } catch (IOException e) { throw new SimulatorServerException("Could not load property file."); } // check properties if (!props.containsKey("host")) { throw new SimulatorServerException("Property 'host' not found."); } if (!props.containsKey("port")) { throw new SimulatorServerException("Property 'port' not found."); } if (!props.containsKey("timeout")) { throw new SimulatorServerException("Property 'timeout' not found."); } if (!props.containsKey("waittime")) { throw new SimulatorServerException("Property 'waittime' not found."); } // get properties host = props.getProperty("host"); try { port = Integer.parseInt(props.getProperty("port")); timeout = Integer.parseInt(props.getProperty("timeout")); waittime = Integer.parseInt(props.getProperty("waittime")); } catch (NumberFormatException e) { throw new SimulatorServerException("Properties 'port', 'timeout' and 'waittime' must be numbers"); } }