List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:com.google.code.fqueue.util.Config.java
/** * ??//from w w w. j ava 2s . c o m * * @param path * * @throws FileNotFoundException */ public static synchronized void iniSetting(String path) { File file; file = new File(path); FileInputStream in = null; try { in = new FileInputStream(file); Properties p = new Properties(); p.load(in); // ???Map Enumeration<?> item = p.propertyNames(); while (item.hasMoreElements()) { String key = (String) item.nextElement(); setting.put(key, p.getProperty(key)); } in.close(); } catch (FileNotFoundException e) { log.error("config file not found at" + file.getAbsolutePath()); throw new ConfigException("FileNotFoundException", e); } catch (IOException e) { log.error("config file not found at" + file.getAbsolutePath()); throw new ConfigException("IOException", e); } catch (Exception e) { throw new ConfigException("Exception", e); } }
From source file:Main.java
public static void mergePropertiesIntoMap(Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } else {/* www .jav a2 s.c om*/ String key; Object value; if (props != null) { for (Enumeration en = props.propertyNames(); en.hasMoreElements(); map.put(key, value)) { key = (String) en.nextElement(); value = props.getProperty(key); if (value == null) { value = props.get(key); } } } } }
From source file:com.scf.core.context.app.cfg.module.ModuleConfigHandler.java
/** * marges props//from w w w .j a va 2 s. c o m * * @param marges * @param moduleName * @param props * @return */ @SuppressWarnings("rawtypes") private static ConfigParams loadModuleConfig(Properties marges, String moduleName, Properties props) { if (marges != null) { Enumeration pks = marges.propertyNames(); while (pks.hasMoreElements()) { String pk = (String) pks.nextElement(); String _pk = "module_" + moduleName + "."; if (pk.startsWith(_pk)) { _pk = pk.substring(_pk.length()); _logger.info("Module config override " + pk + " = " + marges.getProperty(pk) + "[default: " + props.getProperty(_pk) + "]"); props.setProperty(_pk, marges.getProperty(pk)); } } } ConfigParams cp = new ConfigParams(); cp.setParams(props); return cp; }
From source file:org.wso2.carbon.identity.mgt.endpoint.IdentityManagementServiceUtil.java
private static boolean isSecuredPropertyAvailable(Properties properties) { Enumeration propertyNames = properties.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); if (StringUtils.startsWith(properties.getProperty(key), IdentityManagementEndpointConstants.SECRET_ALIAS)) { return true; }/*from www .j a v a 2s . com*/ } return false; }
From source file:Main.java
/** * Read a set of properties from the received input stream, strip * off any excess white space that exists in those property values, * and then add those newly-read properties to the received * Properties object; not explicitly removing the whitespace here can * lead to problems.// w w w. j a v a2 s. c o m * * This method exists because of the manner in which the jvm reads * properties from file--extra spaces are ignored after a _key_, but * if they exist at the _end_ of a property decl line (i.e. as part * of a _value_), they are preserved, as outlined in the Java API: * * "Any whitespace after the key is skipped; if the first non- * whitespace character after the key is = or :, then it is ignored * and any whitespace characters after it are also skipped. All * remaining characters on the line become part of the associated * element string." * * @param iStr An input stream from which the new properties are to be * loaded (should already be initialized). * @param prop A set of properties to which the properties from * iStr will be added (should already be initialized). * properties loaded from 'iStr' (with the extra whitespace (if any) * removed from all values), will be returned via the parameter. * **/ public static void loadWithTrimmedValues(InputStream iStr, Properties prop) throws IOException { if ((iStr == null) || (prop == null)) { // shouldn't happen; just ignore this call and return. return; } // Else, load the properties from the received input stream. Properties p = new Properties(); p.load(iStr); // Now, trim off any excess whitespace, if any, and then // add the properties from file to the received Properties // set. for (Enumeration propKeys = p.propertyNames(); propKeys.hasMoreElements();) { // get the value, trim off the whitespace, then store it // in the received properties object. String tmpKey = (String) propKeys.nextElement(); String tmpValue = p.getProperty(tmpKey); tmpValue = tmpValue.trim(); prop.put(tmpKey, tmpValue); } return; }
From source file:com.asakusafw.cleaner.log.LogMessageLoader.java
/** * ??// w w w . j a v a2s. c o m * ???????? * <p> * ????.properties????? * ??????????? * </p> * @param manager ? * @throws IOException ????? */ static void loadFile(LogMessageManager manager) throws IOException { // ? InputStream in = null; Properties props = new Properties(); try { in = LogMessageLoader.class.getClassLoader().getResourceAsStream(Constants.LOG_MESSAGE_FILE); props.load(in); Enumeration<?> keys = props.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.endsWith(LEVEL_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, LEVEL_KEY_END); manager.putLevel(messageId, props.getProperty(key)); } else if (key.endsWith(TEMPLATE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, TEMPLATE_KEY_END); manager.putTemplate(messageId, props.getProperty(key)); } else if (key.endsWith(SIZE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, SIZE_KEY_END); String sizeStr = props.getProperty(key); if (NumberUtils.isNumber(sizeStr)) { manager.putSize(messageId, Integer.valueOf(sizeStr)); } } } } catch (IOException ex) { throw new IOException( "??????????" + Constants.LOG_MESSAGE_FILE, ex); } finally { IOUtils.closeQuietly(in); } }
From source file:com.googleapis.ajax.services.example.ResourceBundleGenerator.java
/** * Process command line.//w ww .java 2 s . co m * * @param line the line * @param options the options */ @SuppressWarnings("unchecked") private static void processCommandLine(CommandLine line, Options options) { if (line.hasOption(HELP_OPTION)) { printHelp(options); } else if (line.hasOption(APPLICATION_KEY_OPTION) && line.hasOption(RESOURCE_OPTION)) { GoogleSearchQueryFactory factory = GoogleSearchQueryFactory .newInstance(line.getOptionValue(APPLICATION_KEY_OPTION)); Properties resourceMessages = loadResourceMessages(line.getOptionValue(RESOURCE_OPTION)); List<String> propertyNames = (List<String>) Collections.list(resourceMessages.propertyNames()); List<Language> targetLanguages = getTargetLanguages(line.getOptionValue(LANGUAGES_OPTION)); for (Language language : targetLanguages) { Properties translatedResources = new Properties(); TranslateLanguageQuery translateQuery = factory.newTranslateLanguageQuery(); translateQuery.withLanguagePair(Language.ENGLISH, language); for (String name : propertyNames) { translateQuery.withQuery(resourceMessages.getProperty(name)); } List<TranslateLanguageResult> result = translateQuery.list(); if (result.size() == propertyNames.size()) { int index = 0; for (String name : propertyNames) { translatedResources.setProperty(name, result.get(index++).getTranslatedText()); } } saveResourceMessages(translatedResources, line.getOptionValue(RESOURCE_OPTION), language); } } else { printHelp(options); } }
From source file:CollectionUtils.java
/** * Merge the given Properties instance into the given Map, * copying all properties (key-value pairs) over. * <p>Uses <code>Properties.propertyNames()</code> to even catch * default properties linked into the original Properties instance. * @param props the Properties instance to merge (may be <code>null</code>) * @param map the target Map to merge the properties into *//*w w w .j a va 2s.com*/ public static void mergePropertiesIntoMap(Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } if (props != null) { for (Enumeration en = props.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); map.put(key, props.getProperty(key)); } } }
From source file:com.salas.bb.utils.xml.XmlReaderFactory.java
/** * Reads properties from the resource into the map. Each key in properties resource * is a value for comma-delimetered list of keys. * * @param propertiesName name of properties resource. * * @return map.//from ww w . ja v a 2s .c om * * @throws IOException in case of I/O error. */ static Map readPropsToMap(String propertiesName) throws IOException { Properties props = new Properties(); props.load(XmlReaderFactory.class.getClassLoader().getResourceAsStream(propertiesName)); Map map = new HashMap(); Enumeration propEnumeration = props.propertyNames(); while (propEnumeration.hasMoreElements()) { String readerClassName = ((String) propEnumeration.nextElement()).trim(); String[] encodings = StringUtils.split(props.getProperty(readerClassName), ","); putKeysInMap(map, encodings, readerClassName); } return map; }
From source file:org.wso2.carbon.identity.mgt.endpoint.IdentityManagementServiceUtil.java
private static void resolveSecrets(Properties properties) { SecretResolver secretResolver = SecretResolverFactory.create(properties); Enumeration propertyNames = properties.propertyNames(); if (secretResolver != null && secretResolver.isInitialized()) { // Iterate through config file, find encrypted properties and resolve them while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); if (StringUtils.startsWith(properties.getProperty(key), IdentityManagementEndpointConstants.SECRET_ALIAS)) { String secretAlias = properties.getProperty(key) .split(IdentityManagementEndpointConstants.SECRET_ALIAS_SEPARATOR, 2)[1]; if (secretResolver.isTokenProtected(secretAlias)) { if (log.isDebugEnabled()) { log.debug("Resolving and replacing secret for " + secretAlias); }/* w ww . j a v a 2s . com*/ // Resolving the secret password. String value = secretResolver.resolve(secretAlias); // Replaces the original encrypted property with resolved property properties.put(key, value); } else { if (log.isDebugEnabled()) { log.debug("No encryption done for value with key :" + key); } } } } } else { log.warn("Secret Resolver is not present. Failed to resolve encryption in " + IdentityManagementEndpointConstants.SERVICE_CONFIG_FILE_NAME + " file"); } }