List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:org.socraticgrid.account.util.PropertyAccessor.java
/** * This method dumps the properties and associated values for a properties file to * the log file./*from w ww. j a va 2 s. c om*/ * * @param sPropertyFile The name of the property file. * @throws PropertyAccessException This is thrown if an error occurs accessing the property. */ public static void dumpPropsToLog(String sPropertyFile) throws PropertyAccessException { // Make sure everything is in a good state. //----------------------------------------- checkEnvVarSet(); stringIsValid("dumpPropsToLog", "sPropertyFile", sPropertyFile); StringBuffer sbLogMessage = new StringBuffer(); sbLogMessage.append("Dumping contents of property file: '" + sPropertyFile + "'." + CRLF); RefreshInfo oInfo = m_hNextRefresh.get(sPropertyFile); // This means we have never loaded the file - so load it now... //-------------------------------------------------------------- if (oInfo != null) { sbLogMessage.append("RefreshInfo.RefreshMode=" + oInfo.m_oRefreshMode + CRLF); sbLogMessage.append("RefreshInfo.RefreshMilliseconds=" + oInfo.m_iRefreshMilliseconds + CRLF); if (oInfo.m_dtRefreshDate != null) { SimpleDateFormat oFormat = new SimpleDateFormat("MM/dd/yyyy.HH:mm:ss"); sbLogMessage.append("RefreshInfo.RefreshDate=" + oFormat.format(oInfo.m_dtRefreshDate) + CRLF); } else { sbLogMessage.append("RefreshInfo.RefreshDate=null" + CRLF); } sbLogMessage.append("Properties:"); Properties oProps = m_hAllProps.get(sPropertyFile); if (oProps != null) { Set<String> setKeys = oProps.stringPropertyNames(); if (setKeys != null) { Iterator<String> iterKeys = setKeys.iterator(); while (iterKeys.hasNext()) { String sKey = iterKeys.next(); String sValue = oProps.getProperty(sKey); if (sValue != null) { sValue = sValue.trim(); } sbLogMessage.append("Property:" + sKey + "=" + sValue + CRLF); } } // if (setKeys != null) else { sbLogMessage.append("No properties were found in the property file." + CRLF); } } // if (oProps != null) else { sbLogMessage.append("No properties were found in the property file." + CRLF); } } //if (oInfo != null) else { sbLogMessage.append("No content. Property file has never been loaded." + CRLF); } log.info(sbLogMessage.toString()); }
From source file:edu.umass.cs.gnsserver.utils.ParametersAndOptions.java
/** * Returns a hash map with all options including options in config file and the command line arguments * * @param className//from w w w. j a v a2 s .c o m * @param commandLineOptions * @param args command line arguments given to JVM * @return hash map with KEY = parameter names, VALUE = values of parameters in String form * @throws IOException */ public static HashMap<String, String> getParametersAsHashMap(String className, Options commandLineOptions, String... args) throws IOException { CommandLine parser = null; try { parser = new GnuParser().parse(commandLineOptions, args); } catch (ParseException e) { System.err.println("Problem parsing command line:" + e); printUsage(className, commandLineOptions); System.exit(1); } if (parser.hasOption(HELP)) { printUsage(className, commandLineOptions); System.exit(0); } // load options given in config file in a java properties object Properties prop = new Properties(); if (parser.hasOption(CONFIG_FILE)) { String value = parser.getOptionValue(CONFIG_FILE); File f = new File(value); if (f.exists() == false) { System.err.println("Config file not found:" + value); System.exit(2); } InputStream input = new FileInputStream(value); // load a properties file prop.load(input); } // create a hash map with all options including options in config file and the command line arguments HashMap<String, String> allValues = new HashMap<String, String>(); // add options given in config file to hash map for (String propertyName : prop.stringPropertyNames()) { allValues.put(propertyName, prop.getProperty(propertyName)); } // add options given via command line to hashmap. these options can override options given in config file. for (Option option : parser.getOptions()) { String argName = option.getOpt(); String value = option.getValue(); // if an option has a boolean value, the command line arguments do not say true/false for some of these options // if option name is given as argument on the command line, it means the value is true. therefore, the hashmap // will also assign the value true for these options. if (value == null) { value = "true"; } allValues.put(argName, value); } return allValues; }
From source file:org.spring.data.gemfire.AbstractGemFireIntegrationTest.java
private static ServerLauncher buildServerLauncher(final String cacheXmlPathname, final Properties gemfireProperties, final String serverId, final int serverPort, final File serverWorkingDirectory) { ServerLauncher.Builder serverLauncherBuilder = new ServerLauncher.Builder() //.setCommand(ServerLauncher.Command.START) .setDebug(Boolean.FALSE).setForce(Boolean.FALSE).setRedirectOutput(Boolean.TRUE) .setServerPort(serverPort).setWorkingDirectory(serverWorkingDirectory.getAbsolutePath()) .set(DistributionConfig.CACHE_XML_FILE_NAME, cacheXmlPathname); if (!gemfireProperties.contains(DistributionConfig.NAME_NAME)) { serverLauncherBuilder.setMemberName(serverId); }/*from w w w .j a v a 2s. c om*/ for (String property : gemfireProperties.stringPropertyNames()) { serverLauncherBuilder.set(property, gemfireProperties.getProperty(property)); } return serverLauncherBuilder.build(); }
From source file:org.wso2.carbon.identity.event.EventManagementUtils.java
/** * Replace place holders in the given string with properties * * @param content Original content of the message which has place holders * @param replaceRegexStartsWith Placeholders starting regex * @param replaceRegexEndsWith Placeholders ending regex * @param properties Set of properties which are to be used for replacing * @return New content, place holders are replaced *///from w w w . ja v a 2s. c o m public static String replacePlaceHolders(String content, String replaceRegexStartsWith, String replaceRegexEndsWith, Properties properties) { // Stop proceeding if required arguments are not present if (properties == null || StringUtils.isEmpty(content) || StringUtils.isEmpty(replaceRegexEndsWith) || StringUtils.isEmpty(replaceRegexStartsWith)) { throw new IllegalArgumentException("Missing required arguments for replacing place holders"); } if (log.isDebugEnabled()) { log.debug("Place holders starting regex : " + replaceRegexStartsWith + ". End regex with : " + replaceRegexEndsWith); log.debug("Replacing place holders of String " + content); } // For each property check whether there is a place holder and replace the place // holders exist. for (String key : properties.stringPropertyNames()) { if (log.isDebugEnabled()) { log.debug("Replacing place holder with property key :" + key + " from value :" + properties.getProperty(key)); } content = content.replaceAll(replaceRegexStartsWith + key + replaceRegexEndsWith, properties.getProperty(key)); } if (log.isDebugEnabled()) { log.debug("Place holders replaced String " + content); } return content; }
From source file:org.wso2.carbon.identity.application.authentication.endpoint.util.AdaptiveAuthUtil.java
public static void init() { try {//from w ww .j a v a 2s. c o m String configFilePath = buildFilePath(Constants.TenantConstants.IDENTITY_XML_RELATIVE_PATH); File configFile = new File(configFilePath); if (configFile.exists()) { adaptiveAuthConfigs.put("AdaptiveAuth.HTTPConnectionTimeout", IdentityUtil.getProperty("AdaptiveAuth.HTTPConnectionTimeout")); adaptiveAuthConfigs.put("AdaptiveAuth.RefreshInterval", IdentityUtil.getProperty("AdaptiveAuth.RefreshInterval")); } else { Properties props = new Properties(); try (InputStream inputStream = AdaptiveAuthUtil.class.getClassLoader() .getResourceAsStream(Constants.TenantConstants.CONFIG_FILE_NAME)) { if (inputStream != null) { props.load(inputStream); if (log.isDebugEnabled()) { log.debug(Constants.TenantConstants.CONFIG_FILE_NAME + " file loaded from authentication endpoint webapp"); } } else { if (log.isDebugEnabled()) { log.debug("Input stream is null while loading authentication endpoint from webapp"); } } } Set<String> keys = props.stringPropertyNames(); for (String key : keys) { switch (key) { case "AdaptiveAuth.HTTPConnectionTimeout": case "AdaptiveAuth.RefreshInterval": adaptiveAuthConfigs.put(key, props.getProperty(key)); } } } } catch (IOException e) { log.error("Error while loading configs for adaptive authentication.", e); } }
From source file:org.apache.ranger.audit.provider.MiscUtil.java
public static Map<String, String> getPropertiesWithPrefix(Properties props, String prefix) { Map<String, String> prefixedProperties = new HashMap<String, String>(); if (props != null && prefix != null) { for (String key : props.stringPropertyNames()) { if (key == null) { continue; }/*from w w w. j a va2 s . c om*/ String val = props.getProperty(key); if (key.startsWith(prefix)) { key = key.substring(prefix.length()); if (key == null) { continue; } prefixedProperties.put(key, val); } } } return prefixedProperties; }
From source file:org.bdval.ExecuteSplitsMode.java
/** * Parse properties to extract optional model id definitions. The format is as follow: * <p/>/*from w ww.j a v a2 s. c o m*/ * <PRE> * define.model-id.column-id=modelid-noScaler * define.model-id.modelid-noScaler.exclude=a,b * define.model-id.modelid-noScaler.exclude.a.argument=scaler-name * define.model-id.modelid-noScaler.exclude.a.skip=1 * define.model-id.modelid-noScaler.exclude.b.argument=normalizer-name * define.model-id.modelid-noScaler.exclude.b.skip=1 * </PRE> * These properties would define one new model-id called, to be written in a column called modelid-noScaler, * which excludes two arguments and one value each from the hashcode modelId calculation. */ public static OptionalModelId[] parseOptionalModelIdProperties(final Properties configurationProperties) { final ObjectList<OptionalModelId> result = new ObjectArrayList<OptionalModelId>(); if (configurationProperties != null) { // inspect properties to figure out which optional model ids to create: final ObjectSet<String> optionalModelIdColumnNames = new ObjectArraySet<String>(); for (final String propertyName : configurationProperties.stringPropertyNames()) { if (propertyName.startsWith("define.model-id.column-id")) { final String columnIdNames = configurationProperties.getProperty(propertyName); final String[] names = columnIdNames.split(","); for (final String name : names) { optionalModelIdColumnNames.add(name); } } } for (final String optionalColumnId : optionalModelIdColumnNames) { final String defineModelIdExcludePropertyName = "define.model-id." + optionalColumnId + ".exclude"; final String argumentKeys = configurationProperties.getProperty(defineModelIdExcludePropertyName); final String[] keys; if (argumentKeys == null) { System.err.println( "Error parsing properties. Cannot find key=" + defineModelIdExcludePropertyName); keys = ArrayUtils.EMPTY_STRING_ARRAY; } else { keys = argumentKeys.split(","); } final OptionalModelId newOne = new OptionalModelId(optionalColumnId); for (String key : keys) { key = key.trim(); final String excludeArgumentName = configurationProperties .getProperty(defineModelIdExcludePropertyName + "." + key + ".argument"); final String excludeArgumentSkip = configurationProperties .getProperty(defineModelIdExcludePropertyName + "." + key + ".skip"); newOne.addExcludeArgument(excludeArgumentName, Integer.parseInt(excludeArgumentSkip)); } result.add(newOne); LOGGER.debug("Defined modelId: " + newOne); } } return result.toArray(new OptionalModelId[result.size()]); }
From source file:org.wso2.carbon.identity.event.internal.EventUtils.java
/** * Replace place holders in the given string with properties. * * @param content Original content of the message which has place holders * @param replaceRegexStartsWith Placeholders starting regex * @param replaceRegexEndsWith Placeholders ending regex * @param properties Set of properties which are to be used for replacing * @return New content, place holders are replaced *//*from ww w . j a va 2 s .c o m*/ public static String replacePlaceHolders(String content, String replaceRegexStartsWith, String replaceRegexEndsWith, Properties properties) { // Stop proceeding if required arguments are not present if (properties == null || StringUtils.isEmpty(content) || StringUtils.isEmpty(replaceRegexEndsWith) || StringUtils.isEmpty(replaceRegexStartsWith)) { throw new IllegalArgumentException("Missing required arguments for replacing place holders"); } if (logger.isDebugEnabled()) { logger.debug("Place holders starting regex : " + replaceRegexStartsWith + ". End regex with : " + replaceRegexEndsWith); logger.debug("Replacing place holders of String " + content); } // For each property check whether there is a place holder and replace the place // holders exist. for (String key : properties.stringPropertyNames()) { if (logger.isDebugEnabled()) { logger.debug("Replacing place holder with property key :" + key + " from value :" + properties.getProperty(key)); } content = content.replaceAll(replaceRegexStartsWith + key + replaceRegexEndsWith, properties.getProperty(key)); } if (logger.isDebugEnabled()) { logger.debug("Place holders replaced String " + content); } return content; }
From source file:gobblin.util.HadoopUtils.java
public static Configuration getConfFromProperties(Properties properties) { Configuration conf = newConfiguration(); for (String propName : properties.stringPropertyNames()) { conf.set(propName, properties.getProperty(propName)); }//www .ja va2 s . c om return conf; }
From source file:org.nd4j.linalg.jcublas.context.ContextHolder.java
/** * Singleton pattern/* w ww .j ava 2 s. c o m*/ * @return the instance for the context holder. */ public static synchronized ContextHolder getInstance() { if (INSTANCE == null) { Properties props = new Properties(); try { props.load(new ClassPathResource("/cudafunctions.properties", ContextHolder.class.getClassLoader()) .getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } INSTANCE = new ContextHolder(); INSTANCE.configure(); //set the properties to be accessible globally for (String pair : props.stringPropertyNames()) System.getProperties().put(pair, props.getProperty(pair)); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { INSTANCE.destroy(); } })); } return INSTANCE; }