Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

In this page you can find the example usage for java.util Properties stringPropertyNames.

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:com.eternitywall.ots.OtsCli.java

private static HashMap<String, String> readSignature(String file) throws Exception {
    Path path = Paths.get(file);

    if (!path.toFile().exists()) {
        throw new Exception();
    }/*from w w w  .ja v  a 2s  .c  om*/

    Properties properties = new Properties();
    properties.load(new FileInputStream(file));
    HashMap<String, String> privateUrls = new HashMap<>();

    for (String key : properties.stringPropertyNames()) {
        String value = properties.getProperty(key);
        privateUrls.put(key, value);
    }

    return privateUrls;
}

From source file:adalid.commons.velocity.VelocityAid.java

public static String[] sortedPropertyNames(Properties properties) {
    String[] names = new String[properties.stringPropertyNames().size()];
    properties.stringPropertyNames().toArray(names);
    Arrays.sort(names);/*from  ww w .j  ava  2  s . c o m*/
    return names;
}

From source file:org.apache.stratos.adc.mgt.utils.CartridgeConfigFileReader.java

/**
 * //  www.  j  a v  a2s  .c om
 * Reads cartridge-config.properties file and assign properties to system
 * properties
 * 
 */
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");
    }

    for (String name : properties.stringPropertyNames()) {
        String value = properties.getProperty(name);
        System.setProperty(name, value);
    }
}

From source file:org.cloudfoundry.identity.varz.VarzEndpoint.java

/**
 * @param properties// w ww  .j  a v a2s  .  c  o  m
 * @return new properties with no plaintext passwords
 */
public static Properties hidePasswords(Properties properties) {
    Properties result = new Properties();
    result.putAll(properties);
    for (String key : properties.stringPropertyNames()) {
        if (isPassword(key)) {
            result.put(key, "#");
        }
    }
    return result;
}

From source file:org.cloudfoundry.identity.varz.VarzEndpoint.java

/**
 * Extract a Map from some properties by removing a prefix from the key names.
 * /*w ww . ja  v  a 2  s  . co  m*/
 * @param properties the properties to use
 * @param prefix the prefix to strip from key names
 * @return a map of String values
 */
public static Map<String, ?> getMapFromProperties(Properties properties, String prefix) {
    Map<String, Object> result = new HashMap<String, Object>();
    for (String key : properties.stringPropertyNames()) {
        if (key.startsWith(prefix)) {
            String name = key.substring(prefix.length());
            result.put(name, properties.getProperty(key));
        }
    }
    return result;
}

From source file:net.sf.jasperreports.eclipse.util.FileUtils.java

public static String getPropertyAsString(Properties prop) {
    StringBuffer str = new StringBuffer();
    for (String key : prop.stringPropertyNames()) {
        str.append(key).append("=").append(stringConvert(prop.getProperty(key), false, true)) //$NON-NLS-1$
                .append("\n"); //$NON-NLS-1$
    }//from w w w .j a va  2  s.  c o  m
    return str.toString();
}

From source file:org.openecomp.sdnc.sli.aai.AAIRequest.java

public static void setProperties(Properties props, AAIService aaiService) {
    AAIRequest.configProperties = props;
    AAIRequest.aaiService = aaiService;/*from   w w  w  .  j  av  a 2  s .com*/

    try {
        URL url = null;
        Bundle bundle = FrameworkUtil.getBundle(AAIServiceActivator.class);
        if (bundle != null) {
            BundleContext ctx = bundle.getBundleContext();
            if (ctx == null)
                return;

            url = ctx.getBundle().getResource(AAIService.PATH_PROPERTIES);
        } else {
            url = aaiService.getClass().getResource("/aai-path.properties");
        }

        InputStream in = url.openStream();
        Reader reader = new InputStreamReader(in, "UTF-8");

        Properties properties = new Properties();
        properties.load(reader);
        LOG.info("loaded " + properties.size());

        Set<String> keys = properties.stringPropertyNames();

        int index = 0;
        Set<String> resourceNames = new TreeSet<String>();

        for (String key : keys) {
            String[] tags = key.split("\\|");
            for (String tag : tags) {
                if (!resourceNames.contains(tag)) {
                    resourceNames.add(tag);
                    tagValues.put(tag, Integer.toString(++index));
                }
            }
            BitSet bs = new BitSet(256);
            for (String tag : tags) {
                String value = tagValues.get(tag);
                Integer bitIndex = Integer.parseInt(value);
                bs.set(bitIndex);
            }
            String path = properties.getProperty(key);
            LOG.info(String.format("bitset %s\t\t%s", bs.toString(), path));
            bitsetPaths.put(bs, path);
        }
        LOG.info("loaded " + resourceNames.toString());
    } catch (Exception e) {
        LOG.error("Caught exception", e);
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

@Nonnull
public static String makeQueryStringForURI(@Nullable final Properties properties) {
    if (properties == null || properties.isEmpty()) {
        return ""; //NOI18N
    }//from   w  ww.  j av  a  2 s  .  c  om
    final StringBuilder buffer = new StringBuilder();

    for (final String k : properties.stringPropertyNames()) {
        try {
            final String encodedKey = URLEncoder.encode(k, "UTF-8"); //NOI18N
            final String encodedValue = URLEncoder.encode(properties.getProperty(k), "UTF-8"); //NOI18N

            if (buffer.length() > 0) {
                buffer.append('&');
            }
            buffer.append(encodedKey).append('=').append(encodedValue);
        } catch (UnsupportedEncodingException ex) {
            LOGGER.error("Can't encode URI query", ex); //NOI18N
            throw new Error("Unexpected exception, can't find UTF-8 charset!"); //NOI18N
        }
    }
    return buffer.toString();
}

From source file:com.tesora.dve.common.PEFileUtils.java

private static Properties encrypt(Properties props) throws PEException {
    // we are going to iterate over all properties looking for any that
    // contain the string "password"
    for (String key : props.stringPropertyNames()) {
        if (StringUtils.containsIgnoreCase(key, "password")) {
            String value = props.getProperty(key);

            if (!StringUtils.isBlank(value)) {
                props.setProperty(key, PECryptoUtils.encrypt(value));
            }//from www.j a  va  2 s. co m
        }
    }
    return props;
}

From source file:com.tesora.dve.common.PEFileUtils.java

private static Properties decrypt(Properties props) throws PEException {
    // we are going to iterate over all properties looking for any that
    // contain the string "password"
    for (String key : props.stringPropertyNames()) {
        if (StringUtils.containsIgnoreCase(key, "password")) {
            String value = props.getProperty(key);

            if (!StringUtils.isBlank(value)) {
                props.setProperty(key, PECryptoUtils.decrypt(value));
            }/*from  ww w.jav a  2s.  co m*/
        }
    }
    return props;
}