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:org.ow2.parserve.PARServeEngine.java

/**
 * Creates all configuration data related to Rserve
 *
 * @return//from   w  w  w  . jav  a  2s . co m
 * @throws IOException
 */
private static RServeConf createConfig() throws IOException {
    long timeout = -1;
    boolean debug = false;
    boolean daemon = false;
    String login = null;
    String password = null;
    int rServePort = PARSERVE_RSERVE_PORT;
    Properties rServeProperties = null;
    Properties rEnvProperties = null;
    if (rServePropertyFile.exists()) {
        rServeProperties = new Properties();
        rServeProperties.load(new FileReader(rServePropertyFile));
        Set<String> propNames = rServeProperties.stringPropertyNames();
        // filter properties starting with "R." or special properties
        for (String key : propNames) {
            if (key.startsWith("R.")) {
                String newkey = key.substring(2);
                if (rEnvProperties == null) {
                    rEnvProperties = new Properties();
                }
                rEnvProperties.put(newkey, rServeProperties.remove(key));
            } else if (key.equals("rserve.daemon")) {
                daemon = Boolean.parseBoolean((String) rServeProperties.remove(key));
                rServeProperties.remove(key);
            } else if (key.equals("rserve.debug")) {
                debug = Boolean.parseBoolean((String) rServeProperties.remove(key));
                rServeProperties.remove(key);
            } else if (key.equals("port")) {
                rServePort = Integer.parseInt((String) rServeProperties.get("port"));
            } else if (key.equals("rserve.login")) {
                login = (String) rServeProperties.remove(key);
            } else if (key.equals("rserve.password")) {
                password = (String) rServeProperties.remove(key);
            } else if (key.equals("rserve.timeout")) {
                timeout = Long.parseLong((String) rServeProperties.remove(key));
            }
        }
    }
    return new RServeConf(null, rServePort, login, password, timeout, daemon, debug, rServeProperties,
            rEnvProperties);
}

From source file:net.sourceforge.czt.gnast.Gnast.java

/**
 * Returns a property list of all the properties in <code>props</code>
 * that start with the given <code>prefix</code>, but with the prefix
 * removed. That is, a property named Foo is in the returned property
 * list if and only if the value of <code>prefix</code> concatenated
 * with Foo is contained in <code>props</code>. Furthermore, the values
 * of both properties are equal./*from  w  w w.ja va2s  .c  o m*/
 *
 * @param prefix 
 * @param props 
 * @return should never be <code>null</code>.
 */
public static Map<String, Object> removePrefix(String prefix, Properties props) {
    Map<String, Object> result = new HashMap<String, Object>();
    for (String prop : props.stringPropertyNames()) {
        if (prop.startsWith(prefix)) {
            result.put(prop.substring(prefix.length()), props.getProperty(prop));
        }
    }
    return result;
}

From source file:no.eris.applet.AppletViewer.java

private static Map<String, String> readConfig(String configPropFile, boolean convertKeyToLowerCase) {
    Properties p = new Properties();
    try {//from  w  w w . ja va  2 s  . com
        p.load(AppletViewer.class.getResourceAsStream(configPropFile));
        Map<String, String> m = new HashMap<String, String>();
        for (String key : p.stringPropertyNames()) {
            if (convertKeyToLowerCase)
                m.put(key.toLowerCase(), p.getProperty(key));
            else
                m.put(key, p.getProperty(key));
        }
        return m;
    } catch (IOException e) {
        throw new IllegalStateException("Couldn't load properties from " + configPropFile, e);
    }
}

From source file:fr.ens.biologie.genomique.eoulsan.it.ITFactory.java

/**
 * Load configuration file in properties object.
 * @param configurationFile configuration file
 * @return properties//from w w w.j av a 2 s.c o m
 * @throws IOException if an error occurs when reading file.
 * @throws EoulsanException if an error occurs evaluate value property.
 */
private static Properties loadProperties(final File configurationFile) throws IOException, EoulsanException {

    // TODO Replace properties by treeMap to use constant in set environment
    // variables
    final Properties rawProps = new Properties();
    final Properties props;

    checkExistingStandardFile(configurationFile, "test configuration file");

    // Load configuration file
    rawProps.load(newReader(configurationFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING)));

    props = evaluateProperties(rawProps);

    // Check include
    final String includeOption = props.getProperty(INCLUDE_CONF_KEY);

    if (includeOption != null) {
        // Check configuration file
        final File otherConfigurationFile = new File(includeOption);

        checkExistingStandardFile(otherConfigurationFile, "configuration file doesn't exist");

        // Load configuration in global configuration
        final Properties rawPropsIncludedConfigurationFile = new Properties();
        rawPropsIncludedConfigurationFile
                .load(newReader(otherConfigurationFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING)));

        final Properties newProps = evaluateProperties(rawPropsIncludedConfigurationFile);

        for (final String propertyName : newProps.stringPropertyNames()) {

            // No overwrite property from includes file configuration
            if (props.containsKey(propertyName)) {
                continue;
            }

            props.put(propertyName, newProps.getProperty(propertyName));
        }
    }

    // Add default value
    addDefaultProperties(props);

    return props;
}

From source file:com.centurylink.mdw.services.util.AuthUtils.java

private static synchronized JWTVerifier createCustomTokenVerifier(String algorithmName, String issuer) {
    JWTVerifier tempVerifier = verifierCustom.get(issuer);
    if (tempVerifier == null) {
        Properties props = null;
        if (customProviders == null) {
            props = PropertyManager.getInstance().getProperties(PropertyNames.MDW_JWT);
            customProviders = new HashMap<>();
            for (String pn : props.stringPropertyNames()) {
                String[] pnParsed = pn.split("\\.", 4);
                if (pnParsed.length == 4) {
                    String issuer_name = pnParsed[2];
                    String attrname = pnParsed[3];
                    Properties issuerSpec = customProviders.get(issuer_name);
                    if (issuerSpec == null) {
                        issuerSpec = new Properties();
                        customProviders.put(issuer_name, issuerSpec);
                    }//from w w  w  . ja v  a 2s  . c om
                    String v = props.getProperty(pn);
                    issuerSpec.put(attrname, v);
                }
            }
        }

        props = customProviders.get(getCustomProviderGroupName(issuer));

        if (props == null) {
            logger.severe("Exception creating Custom JWT Verifier for " + issuer + " - Missing 'key' Property");
            return null;
        }

        String propAlg = props.getProperty(PropertyNames.MDW_JWT_ALGORITHM);
        if (StringHelper.isEmpty(algorithmName)
                || (!StringHelper.isEmpty(propAlg) && !algorithmName.equals(propAlg))) {
            String message = "Exception creating Custom JWT Verifier - ";
            message = StringHelper.isEmpty(algorithmName) ? "Missing 'alg' claim in JWT"
                    : ("Mismatch algorithm with specified Property for " + issuer);
            logger.severe(message);
            return null;
        }
        String key = System.getenv("MDW_JWT_" + getCustomProviderGroupName(issuer).toUpperCase() + "_KEY");
        if (StringHelper.isEmpty(key)) {
            if (!algorithmName.startsWith("HS")) { // Only allow use of Key in MDW properties for asymmetric algorithms
                key = props.getProperty(PropertyNames.MDW_JWT_KEY);
                if (StringHelper.isEmpty(key)) {
                    logger.severe("Exception creating Custom JWT Verifier for " + issuer
                            + " - Missing 'key' Property");
                    return null;
                }
            } else {
                logger.severe("Could not find properties for JWT issuer " + issuer);
                return null;
            }
        }

        try {
            maxAge = PropertyManager.getIntegerProperty(PropertyNames.MDW_AUTH_TOKEN_MAX_AGE, 0) * 1000L;

            Algorithm algorithm = null;
            Method algMethod = null;
            if (algorithmName.startsWith("HS")) { // HMAC
                String methodName = "HMAC" + algorithmName.substring(2);
                algMethod = Algorithm.none().getClass().getMethod(methodName, String.class);
                algorithm = (Algorithm) algMethod.invoke(Algorithm.none(), key);
            } else if (algorithmName.startsWith("RS")) { // RSA
                String methodName = "RSA" + algorithmName.substring(2);
                byte[] publicBytes = Base64.decodeBase64(key.getBytes());
                X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicBytes);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                PublicKey pubKey = keyFactory.generatePublic(keySpec);
                algMethod = Algorithm.none().getClass().getMethod(methodName, RSAPublicKey.class,
                        RSAPrivateKey.class);
                algorithm = (Algorithm) algMethod.invoke(Algorithm.none(), pubKey, null);
            } else {
                logger.severe(
                        "Exception creating Custom JWT Verifier - Unsupported Algorithm: " + algorithmName);
                return null;
            }

            String subject = props.getProperty(PropertyNames.MDW_JWT_SUBJECT);

            Verification tmp = JWT.require(algorithm).withIssuer(issuer);
            tmp = StringHelper.isEmpty(subject) ? tmp : tmp.withSubject(subject);
            tempVerifier = tmp.build();
            verifierCustom.put(issuer, tempVerifier);
        } catch (IllegalArgumentException | NoSuchAlgorithmException | NoSuchMethodException | SecurityException
                | IllegalAccessException | InvocationTargetException | InvalidKeySpecException e) {
            logger.severeException("Exception creating Custom JWT Verifier for " + issuer, e);
        }
    }
    return tempVerifier;
}

From source file:br.msf.commons.util.CollectionUtils.java

public static Map<String, String> asStringMap(final Map<?, ?> map) {
    if (map == null) {
        return null;
    }/*from w  ww . j a  v  a  2s .  com*/
    if (isNotEmpty(map)) {
        final Map<String, String> converted = new LinkedHashMap<>(map.size());
        if (Properties.class.isAssignableFrom(map.getClass())) {
            // Properties are a case apart, because it can have 'defaults'.
            final Properties p = (Properties) map;
            for (String key : p.stringPropertyNames()) {
                converted.put(key, p.getProperty(key));
            }
        } else {
            for (Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
                converted.put(CharSequenceUtils.toNullSafeString(entry.getKey()),
                        CharSequenceUtils.toString(entry.getValue()));
            }
        }
        return converted;
    }
    return EMPTY_MAP;
}

From source file:br.ojimarcius.commons.util.CollectionUtils.java

public static Map<String, String> asStringMap(final Map<?, ?> map) {
    if (map == null) {
        return null;
    }//from   w w  w .j  av  a2 s  .  co  m
    if (isNotEmpty(map)) {
        final Map<String, String> converted = new LinkedHashMap<String, String>(map.size());
        if (Properties.class.isAssignableFrom(map.getClass())) {
            // Properties are a case apart, because it can have 'defaults'.
            final Properties p = (Properties) map;
            for (String key : p.stringPropertyNames()) {
                converted.put(key, p.getProperty(key));
            }
        } else {
            for (Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
                converted.put(CharSequenceUtils.toNullSafeString(entry.getKey()),
                        CharSequenceUtils.toString(entry.getValue()));
            }
        }
        return converted;
    }
    return EMPTY_MAP;
}

From source file:com.yahoo.labs.samoa.utils.SamzaConfigFactory.java

private static String readKryoRegistration(String filePath) {
    FileInputStream fis = null;//from ww  w  . j av  a  2  s. co m
    Properties props = new Properties();
    StringBuilder result = new StringBuilder();
    try {
        fis = new FileInputStream(filePath);
        props.load(fis);

        boolean first = true;
        String value = null;
        for (String k : props.stringPropertyNames()) {
            if (!first)
                result.append(COMMA);
            else
                first = false;

            // Need to avoid the dollar sign as samza pass all the properties in
            // the config to containers via commandline parameters/enviroment variables
            // We might escape the dollar sign, but it's more complicated than
            // replacing it with something else
            result.append(k.trim().replace(DOLLAR_SIGN, QUESTION_MARK));
            value = props.getProperty(k);
            if (value != null && value.trim().length() > 0) {
                result.append(COLON);
                result.append(value.trim().replace(DOLLAR_SIGN, QUESTION_MARK));
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

    return result.toString();
}

From source file:org.apache.samoa.utils.SamzaConfigFactory.java

private static String readKryoRegistration(String filePath) {
    FileInputStream fis = null;// www.ja  va2 s.  c om
    Properties props = new Properties();
    StringBuilder result = new StringBuilder();
    try {
        fis = new FileInputStream(filePath);
        props.load(fis);

        boolean first = true;
        String value = null;
        for (String k : props.stringPropertyNames()) {
            if (!first)
                result.append(COMMA);
            else
                first = false;

            // Need to avoid the dollar sign as samza pass all the properties in
            // the config to containers via commandline parameters/enviroment
            // variables
            // We might escape the dollar sign, but it's more complicated than
            // replacing it with something else
            result.append(k.trim().replace(DOLLAR_SIGN, QUESTION_MARK));
            value = props.getProperty(k);
            if (value != null && value.trim().length() > 0) {
                result.append(COLON);
                result.append(value.trim().replace(DOLLAR_SIGN, QUESTION_MARK));
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

    return result.toString();
}

From source file:org.dcm4che3.tool.probetc.ProbeTC.java

private static ArrayList<TransferCapability> loadTCFile() {
    ArrayList<TransferCapability> tcs = new ArrayList<TransferCapability>();
    Properties p = null;
    try {//from  w  ww  . j  a va  2s .  c o m
        p = CLIUtils.loadProperties("resource:sampleTCFile.properties", null);
    } catch (IOException e) {
        LOG.error("unable to load sop-classes properties file");
    }
    for (String cuid : p.stringPropertyNames()) {
        String ts = p.getProperty(cuid);
        LOG.info(ts);
        tcs.add(new TransferCapability(null, ts.split(":")[0], TransferCapability.Role.SCP,
                StringUtils.split(ts.split(":")[1], ',')));
    }
    return tcs;
}