List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:be.agiv.security.demo.Main.java
private String getVersion() { InputStream propertiesInputStream = Main.class.getResourceAsStream("/agiv-security-demo.properties"); if (null == propertiesInputStream) { return "unknown"; }/*from ww w . jav a 2 s .co m*/ Properties properties = new Properties(); try { properties.load(propertiesInputStream); } catch (IOException e) { LOG.error("error loading properties: " + e.getMessage()); return "unknown"; } String version = (String) properties.get("version"); return version; }
From source file:com.streamsets.datacollector.cluster.BaseClusterProvider.java
private boolean copyDpmTokenIfEnabled(Properties props, File etcStagingDir, String include) throws IOException { Object isDPMEnabled = props.get(RemoteSSOService.DPM_ENABLED); if (isDPMEnabled != null) { if (Boolean.parseBoolean(((String) isDPMEnabled).trim())) { copyDpmTokenIfAbsolute(props, etcStagingDir); if (include != null) { try (OutputStream outputStream = new FileOutputStream(new File(etcStagingDir, include))) { props.store(outputStream, null); }/*w ww. j av a 2 s . c o m*/ } return true; } } return false; }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.ApiIdeaInterface.java
/** * GET http://localhost:8080/<portal>/api/rs/en/idea?code=1 * @param properties/*ww w. ja va2s . co m*/ * @return * @throws Throwable */ public JAXBIdea getIdeaForApi(Properties properties) throws Throwable { JAXBIdea jaxbIdea = null; try { String codeParam = properties.getProperty("code"); if (StringUtils.isNotBlank(codeParam)) codeParam = URLDecoder.decode(codeParam, "UTF-8"); IIdea idea = this.getIdeaManager().getIdea(codeParam); if (null == idea) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + codeParam + "' does not exist", Response.Status.CONFLICT); } UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER); Collection<Integer> userStatusList = this.extractIdeaStatusListForUser(user); IdeaInstance instance = this.getIdeaInstanceManager().getIdeaInstance(idea.getInstanceCode()); if (null == instance) { _logger.warn("instance {} not found", idea.getInstanceCode()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + idea.getId() + "' does not exist", Response.Status.CONFLICT); } if (!isAuthOnInstance(user, instance)) { _logger.warn("the current user is not granted to any group required by instance {}", idea.getId()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + idea.getId() + "' does not exist", Response.Status.CONFLICT); } if (!userStatusList.contains(idea.getStatus())) { _logger.warn("the current user is not granted to access to idea {} due to the status {}", codeParam, idea.getStatus()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + codeParam + "' does not exist", Response.Status.CONFLICT); } jaxbIdea = new JAXBIdea(idea); //TODO CREATE ROLE if (null == user || !this.getAuthorizationManager().isAuthOnPermission(user, Permission.SUPERUSER)) { if (null != jaxbIdea) { jaxbIdea.getCommentsNotApproved().clear(); jaxbIdea.getCommentsToApprove().clear(); } } } catch (ApiException ae) { throw ae; } catch (Throwable t) { _logger.error("Error loading idea", t); throw new ApsSystemException("Error loading idea", t); } return jaxbIdea; }
From source file:org.cds06.speleograph.data.fileio.SpeleoFileReader.java
/** * Read a header line to add series in headers information. * <p>I must write to you the english doc for series lines</p> * * @param file The file used to extract the data * @param line The parsed line/*from www . j a v a2s. co m*/ * @param headers The object which represent the headers */ private void readSeriesHeaderLine(File file, String[] line, HeaderInformation headers) { int size = line.length, column = Integer.parseInt(line[0]); if (size < 3) { // A series line must have a length gather than 2 log.info("Invalid header : " + StringUtils.join(line, ' ')); return; } @NonNls Properties p = new Properties(line); Type t = Type.getType(line[1], line[2]); Series series = new Series(file, t); { if (p.getBoolean("show")) series.setShow(true); if (p.getBoolean("stepped")) series.setStepped(true); if (p.get("style") != null) { String style = p.get("style"); for (DrawStyle s : DrawStyle.values()) { if (s.toString().equals(style)) series.setStyle(s); } } if (p.get("color") != null) series.setColor(new Color(Integer.parseInt(p.get("color")))); if (p.get("name") != null) { series.setName(p.get("name")); } if (p.getNumber("axis") != null) { Integer id = p.getNumber("axis"); if (typeAxesChecker.get(id)) { t.setAxis(axes.get(id)); } else { series.setAxis(axes.get(id)); } } } if (p.getBoolean("min-max")) { Integer min = p.getNumber("min"), max = p.getNumber("max"); if (min == null || max == null) return; if (headers.hasSeriesForColumn(min) && headers.hasSeriesForColumn(max)) { series.delete(); } series.setMinMax(true); headers.set(series, min, max); } else { headers.set(series, column); } }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.ApiIdeaInterface.java
public StringApiResponse voteIdea(JAXBVote vote, Properties properties) throws ApiException, Throwable { StringApiResponse response = new StringApiResponse(); try {/* w ww . j av a 2s . co m*/ String ideaId = vote.getIdeaId(); if (StringUtils.isNotBlank(ideaId)) ideaId = URLDecoder.decode(ideaId, "UTF-8"); IIdea idea = this.getIdeaManager().getIdea(ideaId); if (null == idea) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + ideaId + "' does not exist", Response.Status.CONFLICT); } UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER); IdeaInstance instance = this.getIdeaInstanceManager().getIdeaInstance(idea.getInstanceCode()); if (null == instance) { _logger.warn("instance {} not found", idea.getInstanceCode()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + idea.getInstanceCode() + "' does not exist", Response.Status.CONFLICT); } if (!isAuthOnInstance(user, instance)) { _logger.warn("the current user is not granted to any group required by instance {}", instance.getCode()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + instance.getCode() + "' does not exist", Response.Status.CONFLICT); } if (idea.getStatus() != IIdea.STATUS_APPROVED) { _logger.warn("the idea {} is not in statu approved ", idea.getId(), idea.getStatus()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + idea.getId() + "' does not exist", Response.Status.CONFLICT); } String voteType = vote.getType(); if (StringUtils.isBlank(voteType)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Vote is required", Response.Status.CONFLICT); } if (!voteType.equals("like") && !voteType.equals("unlike")) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Vote invalid. Accepted values are 'like' and 'unlike'", Response.Status.CONFLICT); } if (StringUtils.isNotBlank(voteType)) voteType = URLDecoder.decode(voteType, "UTF-8"); if (voteType.equalsIgnoreCase("like")) { ((Idea) idea).setVotePositive(idea.getVotePositive() + 1); this.getIdeaManager().updateIdea(idea); } else if (voteType.equalsIgnoreCase("unlike")) { ((Idea) idea).setVoteNegative(idea.getVoteNegative() + 1); this.getIdeaManager().updateIdea(idea); } response.setResult(IResponseBuilder.SUCCESS, null); } catch (ApiException ae) { response.addErrors(ae.getErrors()); response.setResult(IResponseBuilder.FAILURE, null); } catch (Throwable t) { _logger.error("Error on vote", t); throw new ApsSystemException("Error on vote", t); } return response; }
From source file:edu.cornell.med.icb.goby.modes.DiscoverSequenceVariantsMode.java
/** * Parse the group-definition file, in the format sample-id=group-id (Java properties file) * * @param groupsDefinitionFile file with sample=group mapping information. * @param inputFilenames/*w w w .ja va2 s .c om*/ * @return group definition in the format expected by the --groups argument. */ private String parseGroupFile(String groupsDefinitionFile, String[] inputFilenames) { Properties groupProps = new Properties(); FileReader fileReader = null; try { fileReader = new FileReader(groupsDefinitionFile); groupProps.load(fileReader); Object2ObjectMap<String, MutableString> groupDefs = new Object2ObjectArrayMap<String, MutableString>(); for (final Object key : groupProps.keySet()) { final String groupId = (String) groupProps.get(key); MutableString groupDef = groupDefs.get(groupId); if (groupDef == null) { groupDef = new MutableString(); groupDefs.put(groupId, groupDef); } final String sampleId = (String) key; if (groupDef.indexOf(sampleId) == -1) { if (isInputFilename(inputFilenames, sampleId)) { groupDef.append(sampleId); groupDef.append(','); } } } MutableString result = new MutableString(); for (final String groupId : groupDefs.keySet()) { result.append(groupId); result.append('='); result.append(groupDefs.get(groupId)); // remove trailing coma: result.setLength(result.length() - 1); result.append('/'); } result.setLength(result.length() - 1); System.out.println("generated group text: " + result); return result.toString(); } catch (IOException e) { System.err.println("Cannot open or parse groups-file parameter " + groupsDefinitionFile); System.exit(1); } finally { IOUtils.closeQuietly(fileReader); } return null; }
From source file:com.glaf.core.config.MutilPropertyPlaceholderConfigurer.java
@Override protected Properties mergeProperties() throws IOException { Properties mergeProperties = super.mergeProperties(); // ????properties this.properties = new Properties(); // ?,mode//from w w w . ja va 2 s .co m String mode = System.getProperty(RUN_MODE); if (StringUtils.isEmpty(mode)) { String str = mergeProperties.getProperty(RUN_MODE); mode = str != null ? str : PRODUCTION; } LOG.info("####run mode:" + mode); properties.put(RUN_MODE, mode); String[] modes = mode.split(","); Set<Entry<Object, Object>> es = mergeProperties.entrySet(); for (Entry<Object, Object> entry : es) { String key = (String) entry.getKey(); int idx = key.lastIndexOf('_'); String realKey = idx == -1 ? key : key.substring(0, idx); if (!properties.containsKey(realKey)) { Object value = null; for (String md : modes) { value = mergeProperties.get(realKey + "_" + md); if (value != null) { properties.put(realKey, value); break; } } if (value == null) { value = mergeProperties.get(realKey); if (value != null) { properties.put(realKey, value); } } } } logger.debug(properties); return properties; }
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.java
@Override protected Object createPoolOrConnection() { // AuthInfoProvider,LoadBalancingPolicy, ReconnectionPolicy, // RetryPolicy,ProtocolOptions.Compression, SSLOptions, // PoolingOptions,SocketOptions if (logger.isDebugEnabled()) { logger.debug("Intiatilzing connection"); }//w w w.j a v a 2 s. c o m Properties connectionProperties = CassandraPropertyReader.csmd.getConnectionProperties(); Builder connectionBuilder = Cluster.builder(); // add host/port and AuthInfoProvider for (Host host : configuration.getCassandraHosts()) { connectionBuilder.addContactPoint(host.getHost()).withPort(host.getPort()); if (host.getUser() != null) { connectionBuilder.withCredentials(host.getUser(), host.getPassword()); } } // add policy configuration String loadBalancingPolicy = connectionProperties.getProperty(Constants.LOADBALANCING_POLICY); if (!StringUtils.isBlank(loadBalancingPolicy)) { LoadBalancingPolicy policy = getPolicyInstance(BalancingPolicy.getPolicy(loadBalancingPolicy), connectionProperties); if (policy != null) { connectionBuilder.withLoadBalancingPolicy(policy); } } // compression String compression = connectionProperties.getProperty("compression"); if (!StringUtils.isBlank(compression)) { connectionBuilder.withCompression(Compression.valueOf(compression)); } // ReconnectionPolicy String reconnectionPolicy = connectionProperties.getProperty("reconnection.policy"); if (!StringUtils.isBlank(reconnectionPolicy)) { com.datastax.driver.core.policies.ReconnectionPolicy policy = getPolicy( ReconnectionPolicy.getPolicy(reconnectionPolicy), connectionProperties); if (policy != null) { connectionBuilder.withReconnectionPolicy(policy); } } // , RetryPolicy String retryPolicy = connectionProperties.getProperty("retry.policy"); if (!StringUtils.isBlank(retryPolicy)) { com.datastax.driver.core.policies.RetryPolicy policy = getPolicy(RetryPolicy.getPolicy(retryPolicy), connectionProperties); if (policy != null) { connectionBuilder.withRetryPolicy(policy); } } // TODO::: SSLOptions? Not sure how to add it. // SocketOptions connectionBuilder.withSocketOptions(getSocketOptions(connectionProperties)); // PoolingOptions, connectionBuilder.withPoolingOptions(getPoolingOptions(connectionProperties)); // finally build cluster. Cluster cluster = connectionBuilder.build(); PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = persistenceUnitMetadata.getProperties(); if (externalProperties != null) { keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE); } if (keyspace == null) { keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE); } setSessionObject(cluster); // TODO custom session return cluster; // TODO custom cluster }
From source file:com.netscape.admin.certsrv.Console.java
/** * main routine. It will pass the command line parameters then call the Console constructor * to create a console instance./*from ww w .java 2 s. c o m*/ * * @param parameters list */ public static void mainImpl(String argv[]) throws Exception { Options options = new Options(); Option option = new Option("f", true, "Capture stderr and stdout to file."); option.setArgName("file"); options.addOption(option); option = new Option("D", true, "Debug options."); option.setArgName("options"); options.addOption(option); option = new Option("x", true, "Extra options (javalaf, nowinpos, nologo)."); option.setArgName("options"); options.addOption(option); options.addOption("v", "verbose", false, "Run in verbose mode."); options.addOption("h", "help", false, "Show help message."); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, argv); String[] cmdArgs = cmd.getArgs(); verbose = cmd.hasOption("verbose"); String outFile = cmd.getOptionValue("f"); if (outFile != null) { try { TeeStream.tee(outFile); } catch (Exception e) { System.err.println("Missing or invalid output file specification for the -f option: " + e); System.exit(1); } } if (cmd.hasOption("D")) { Debug.setApplicationStartTime(_t0); String extraParam = cmd.getOptionValue("D"); if (!extraParam.isEmpty()) { if (extraParam.equals("?") || !Debug.setTraceMode(extraParam)) { System.out.println(Debug.getUsage()); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(0); } } else { Debug.setTraceMode(null); } // Show all system proprties if debug level is 9 if (Debug.getTraceLevel() == 9) { try { Properties props = System.getProperties(); for (Enumeration<Object> e = props.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = (String) props.get(key); Debug.println(9, key + "=" + val); } } catch (Exception e) { } } } if (cmdArgs.length != 1 || cmd.hasOption("help")) { printHelp(); waitForKeyPress(); // allow the user to read the msg on Win NT return; } Debug.println(0, "Management-Console/" + _resource.getString("console", "displayVersion") + " B" + VersionInfo.getBuildNumber()); if (cmd.hasOption("x")) { String extraParam = cmd.getOptionValue("x"); boolean supportedOption = false; if (extraParam.indexOf(OPTION_NOLOGO) != -1) { _showSplashScreen = false; supportedOption = true; } if (extraParam.indexOf(OPTION_NOWINPOS) != -1) { Framework.setEnableWinPositioning(false); supportedOption = true; } if (extraParam.indexOf(OPTION_JAVALAF) != -1) { _useJavaLookAndFeel = true; supportedOption = true; } if (supportedOption == false) { printHelp(); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(0); } } String sAdminURL = cmdArgs[0]; ConsoleInfo cinfo = new ConsoleInfo(); CMSAdmin admin = new CMSAdmin(); URL url = null; try { url = new URL(sAdminURL); } catch (Exception e) { String es = e.toString(); String ep = "java.net.MalformedURLException:"; if (es != null && es.startsWith(ep)) { es = es.substring(ep.length()); } System.err.println("\nURL error: " + es + "\n"); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(1); } if (url == null) { System.err.println("\nIncorrect URL: " + sAdminURL + "\n"); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(1); } cinfo.put("cmsServerInstance", "instanceID"); String protocol = url.getProtocol(); String hostName = url.getHost(); String path = url.getPath(); /* Protocol part of URL is required only by URL class. Console assumes URL protocol. */ if (protocol == null || protocol.length() == 0 || ((!protocol.equalsIgnoreCase("https")) && (!protocol.equalsIgnoreCase("http")))) { System.err.println( "\nIncorrect protocol" + ((protocol != null && protocol.length() > 0) ? ": " + protocol : ".") + "\nDefault supported protocol is 'https'.\n"); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(1); } if (hostName == null || hostName.length() == 0) { System.err.println("\nMissing hostName: " + sAdminURL + "\n"); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(1); } if (path == null || path.length() < 2) { System.err.println("\nMissing URL path: " + sAdminURL + "\nDefault supported URL paths are 'ca', 'kra', 'ocsp', and 'tks'.\n"); waitForKeyPress(); // allow the user to read the msg on Win NT System.exit(1); } path = path.substring(1); if ((!path.equals("ca")) && (!path.equals("kra")) && (!path.equals("ocsp")) && (!path.equals("tks"))) { System.err.println("\nWarning: Potentially incorrect URL path: " + path + "\n Default supported URL paths are 'ca', 'kra', 'ocsp', and 'tks'.\n"); } int portNumber = url.getPort(); if (portNumber < 0) { System.err.println("\nWarning: Unspecified port number: " + sAdminURL + "\n"); /* Add warning about using non default port numbers after port separation is done. "\n Default port number is 9443.\n"); } else if (portNumber != 9443) { System.err.println("\nWarning: Attempt to connect to non default port number: "+sAdminURL+ "\n Default port number is 9443.\n"); */ } UtilConsoleGlobals.initJSS(); ClientConfig config = new ClientConfig(); config.setServerURL(protocol, hostName, portNumber); PKIClient client = new PKIClient(config); InfoClient infoClient = new InfoClient(client); Info info = infoClient.getInfo(); String banner = info.getBanner(); if (banner != null) { System.out.println(banner); System.out.println(); System.out.print("Do you want to proceed (y/N)? "); System.out.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine().trim(); if (!line.equalsIgnoreCase("Y")) { return; } } cinfo.put("cmsHost", url.getHost()); cinfo.put("cmsPort", Integer.toString(portNumber)); cinfo.put("cmsPath", path); admin.initialize(cinfo); admin.run(null, null); /* _console = new Console(sAdminURL, localAdminURL, sLang, host, uid, password); */ }
From source file:edu.stanford.epadd.launcher.Splash.java
/** sets up SETTINGS_DIR by reading epadd.properties in home dir if required, also sets up IS_DISCOVERY_MODE. * out and err streams are expected to be available. * call this before setting up logging because it can affect the location of the log file */// www . j av a 2 s.co m private static void readConfigFile() { // compute settings_DIR, which is also used as logging_dir. so it should be called before logging is set up. // Important: this logic should be the same as in EpaddInitializer inside the webapp (which calls muse/Config.java) { String DEFAULT_SETTINGS_DIR = System.getProperty("user.home") + File.separator + "epadd-settings"; Properties props = new Properties(); File f = new File(EPADD_PROPS_FILE); if (f.exists() && f.canRead()) { out.println("Reading configuration from: " + EPADD_PROPS_FILE); try { InputStream is = new FileInputStream(EPADD_PROPS_FILE); props.load(is); } catch (Exception e) { err.println("Error reading epadd properties file " + EPADD_PROPS_FILE + " " + e); } } else { err.println("ePADD properties file " + EPADD_PROPS_FILE + " does not exist or is not readable"); } // set up settings_dir SETTINGS_DIR = System.getProperty("epadd.settings.dir"); if (SETTINGS_DIR == null || SETTINGS_DIR.length() == 0) SETTINGS_DIR = props.getProperty("epadd.settings.dir"); if (SETTINGS_DIR == null || SETTINGS_DIR.length() == 0) SETTINGS_DIR = DEFAULT_SETTINGS_DIR; if (System.getProperty("epadd.mode.discovery") != null || "discovery".equalsIgnoreCase((String) props.get("epadd.mode"))) IS_DISCOVERY_MODE = true; } }