List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:org.apache.stratos.common.util.CartridgeConfigFileReader.java
/** * Reads cartridge-config.properties file and assign properties to system * properties/*from www . java 2 s.com*/ */ public static void readProperties() { Properties properties = new Properties(); try { properties.load(new FileInputStream(carbonHome + File.separator + "repository" + File.separator + "conf" + File.separator + "cartridge-config.properties")); } catch (Exception e) { log.error("Exception is occurred in reading properties file. Reason:" + e.getMessage()); } if (log.isInfoEnabled()) { log.info("Setting config properties into System properties"); } if (log.isDebugEnabled()) { log.debug("Start reading properties and set it as system properties"); } SecretResolver secretResolver = SecretResolverFactory.create(properties); for (String name : properties.stringPropertyNames()) { String value = properties.getProperty(name); if (log.isDebugEnabled()) { log.debug(" >>> Property Name :" + name + " Property Value :" + value); } if (value.equalsIgnoreCase("secretAlias:" + name)) { if (log.isDebugEnabled()) { log.debug("Secret Alias Found : " + name); } if (secretResolver != null && secretResolver.isInitialized()) { if (log.isDebugEnabled()) { log.debug("SecretResolver is initialized "); } if (secretResolver.isTokenProtected(name)) { if (log.isDebugEnabled()) { log.debug("SecretResolver [" + name + "] is token protected"); } value = secretResolver.resolve(name); if (log.isDebugEnabled()) { log.debug("SecretResolver [" + name + "] is decrypted properly"); } } } } System.setProperty(name, value); } }
From source file:org.socraticgrid.account.util.PropertyAccessor.java
/** * This method returns the set of keys in a property file. * * @param sPropertyFile The name of the property file. * @return An enumeration of property keys in the property file. * @throws PropertyAccessException This is thrown if an error occurs accessing the property. *//* www . ja va 2s. c o m*/ public static final Set<String> getPropertyNames(String sPropertyFile) throws PropertyAccessException { Set<String> setPropNames = null; // Make sure everything is in a good state. //----------------------------------------- checkEnvVarSet(); stringIsValid("getPropertyNames", "sPropertyFile", sPropertyFile); checkForRefreshAndLoad(sPropertyFile); Properties oProps = m_hAllProps.get(sPropertyFile); if (oProps != null) { setPropNames = oProps.stringPropertyNames(); } return setPropNames; }
From source file:org.springframework.test.context.support.TestPropertySourceUtils.java
/** * Convert the supplied <em>inlined properties</em> (in the form of <em>key-value</em> * pairs) into a map keyed by property name, preserving the ordering of property names * in the returned map./*w w w .j a va 2 s . c o m*/ * <p>Parsing of the key-value pairs is achieved by converting all pairs * into <em>virtual</em> properties files in memory and delegating to * {@link Properties#load(java.io.Reader)} to parse each virtual file. * <p>For a full discussion of <em>inlined properties</em>, consult the Javadoc * for {@link TestPropertySource#properties}. * @param inlinedProperties the inlined properties to convert; potentially empty * but never {@code null} * @return a new, ordered map containing the converted properties * @since 4.1.5 * @throws IllegalStateException if a given key-value pair cannot be parsed, or if * a given inlined property contains multiple key-value pairs * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]) */ public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) { Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null"); Map<String, Object> map = new LinkedHashMap<>(); Properties props = new Properties(); for (String pair : inlinedProperties) { if (!StringUtils.hasText(pair)) { continue; } try { props.load(new StringReader(pair)); } catch (Exception ex) { throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex); } Assert.state(props.size() == 1, () -> "Failed to load exactly one test environment property from [" + pair + "]"); for (String name : props.stringPropertyNames()) { map.put(name, props.getProperty(name)); } props.clear(); } return map; }
From source file:org.socraticgrid.account.util.PropertyAccessor.java
/** * This creates a new properties class with a full copy of all of the * properties.//from ww w . j av a 2 s . c o m * * @param oProps The property file that is to be copied. * @return The copy that is returned. * @throws gov.hhs.fha.nhinc.properties.PropertyAccessException This exception is thrown if * it cannot load the property file for some reason. */ private static Properties deepCopyProperties(Properties oProps) throws PropertyAccessException { Properties oRetProps = new Properties(); Set<String> setKeys = oProps.stringPropertyNames(); Iterator<String> iterKeys = setKeys.iterator(); while (iterKeys.hasNext()) { String sKey = iterKeys.next(); String sValue = oProps.getProperty(sKey); if (sValue != null) { sValue = sValue.trim(); } oRetProps.put(sKey, sValue); } return oRetProps; }
From source file:org.itracker.web.util.ImportExportUtilities.java
/** * Write the properties to simple XML tags * @param writer/*from w ww .j a va2 s .com*/ * @param tags * @throws IOException */ private static void addPropertyTags(XMLWriter writer, Properties tags) throws IOException { DocumentFactory factory = getDocumentFactory(); for (String tag : tags.stringPropertyNames()) { Element el = factory.createElement(tag); el.setText(tags.getProperty(tag)); writer.write(el); } }
From source file:org.itracker.web.util.ImportExportUtilities.java
/** * Write the properties to simple CDATA tags * @param writer/* w ww . ja v a 2s. c o m*/ * @param tags * @throws IOException */ private static void addCdataPropertyTags(XMLWriter writer, Properties tags) throws IOException { DocumentFactory factory = getDocumentFactory(); for (String tag : tags.stringPropertyNames()) { Element el = factory.createElement(tag); el.add(factory.createCDATA(tags.getProperty(tag))); writer.write(el); } }
From source file:com.gs.obevo.db.impl.core.jdbc.JdbcDataSourceFactory.java
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url, Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClass.getName()); dataSource.setUrl(url);// w w w . j a va2 s.c om dataSource.setUsername(credential.getUsername()); dataSource.setPassword(credential.getPassword()); // connection pool settings dataSource.setInitialSize(numThreads); dataSource.setMaxActive(numThreads); // keep the connections open if possible; only close them via the removeAbandonedTimeout feature dataSource.setMaxIdle(numThreads); dataSource.setMinIdle(0); dataSource.setRemoveAbandonedTimeout(300); dataSource.setConnectionInitSqls(initSqls.castToList()); if (extraConnectionProperties != null) { for (String key : extraConnectionProperties.stringPropertyNames()) { dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key)); } } return dataSource; }
From source file:com.mnt.base.util.BaseConfiguration.java
public static Map<String, String> loadKeyValuePairs(InputStream in) { Map<String, String> keyPairs = new HashMap<String, String>(); if (in != null) { Properties prop = new Properties(); try {/* w w w . ja v a 2 s. c o m*/ prop.load(in); } catch (IOException e) { log.error("error while load keyvalue pairs to properties.", e); } finally { try { in.close(); } catch (IOException e) { log.error("error while close the properties file: ", e); } } for (String key : prop.stringPropertyNames()) { keyPairs.put(key, prop.getProperty(key)); } } return keyPairs; }
From source file:com.netscape.cms.servlet.csadmin.CertUtil.java
/** * reads from the admin cert profile caAdminCert.profile and determines the algorithm as follows: * * 1. First gets list of allowed algorithms from profile (constraint.params.signingAlgsAllowed) * If entry does not exist, uses entry "ca.profiles.defaultSigningAlgsAllowed" from CS.cfg * If that entry does not exist, uses basic default * * 2. Gets default.params.signingAlg from profile. * If entry does not exist or equals "-", selects first algorithm in allowed algorithm list * that matches CA signing key type/*ww w . ja v a2 s . c o m*/ * Otherwise returns entry if it matches signing CA key type. * * @throws EBaseException * @throws IOException * @throws FileNotFoundException */ public static String getAdminProfileAlgorithm(IConfigStore config) throws EBaseException, FileNotFoundException, IOException { String caSigningKeyType = config.getString("preop.cert.signing.keytype", "rsa"); String pfile = config.getString("profile.caAdminCert.config"); Properties props = new Properties(); props.load(new FileInputStream(pfile)); Set<String> keys = props.stringPropertyNames(); Iterator<String> iter = keys.iterator(); String defaultAlg = null; String[] algsAllowed = null; while (iter.hasNext()) { String key = iter.next(); if (key.endsWith("default.params.signingAlg")) { defaultAlg = props.getProperty(key); } if (key.endsWith("constraint.params.signingAlgsAllowed")) { algsAllowed = StringUtils.split(props.getProperty(key), ","); } } if (algsAllowed == null) { //algsAllowed not defined in profile, use a global setting algsAllowed = StringUtils.split(config.getString("ca.profiles.defaultSigningAlgsAllowed", "SHA256withRSA,SHA256withEC,SHA1withDSA"), ","); } if (ArrayUtils.isEmpty(algsAllowed)) { throw new EBaseException("No allowed signing algorithms defined."); } if (StringUtils.isNotEmpty(defaultAlg) && !defaultAlg.equals("-")) { // check if the defined default algorithm is valid if (!isAlgorithmValid(caSigningKeyType, defaultAlg)) { throw new EBaseException("Administrator cert cannot be signed by specfied algorithm." + "Algorithm incompatible with signing key"); } for (String alg : algsAllowed) { if (defaultAlg.trim().equals(alg.trim())) { return defaultAlg; } } throw new EBaseException("Administrator Certificate cannot be signed by the specified algorithm " + "as it is not one of the allowed signing algorithms. Check the admin cert profile."); } // no algorithm specified. Pick the first allowed algorithm. for (String alg : algsAllowed) { if (isAlgorithmValid(caSigningKeyType, alg)) return alg; } throw new EBaseException("Admin certificate cannot be signed by any of the specified possible algorithms." + "Algorithm is incompatible with the CA signing key type"); }
From source file:fr.ens.biologie.genomique.eoulsan.it.ITFactory.java
/** * Evaluate properties.//from w w w . j a v a2 s . co m * @param rawProps the raw props * @return the properties * @throws EoulsanException if the evaluation expression from value failed. */ private static Properties evaluateProperties(final Properties rawProps) throws EoulsanException { final Properties props = new Properties(); final int pos = IT.PREFIX_ENV_VAR.length(); // Extract environment variable for (final String propertyName : rawProps.stringPropertyNames()) { if (propertyName.startsWith(IT.PREFIX_ENV_VAR)) { // Evaluate property final String evalPropValue = evaluateExpressions(rawProps.getProperty(propertyName), true); // Put in constants map CONSTANTS.put(propertyName.substring(pos), evalPropValue); } } // Evaluate property for (final String propertyName : rawProps.stringPropertyNames()) { final String propertyValue = evaluateExpressions(rawProps.getProperty(propertyName), true); // Set property props.setProperty(propertyName, propertyValue); } return props; }