Example usage for java.util Properties keySet

List of usage examples for java.util Properties keySet

Introduction

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

Prototype

@Override
    public Set<Object> keySet() 

Source Link

Usage

From source file:org.alfresco.grid.GridProperties.java

/**
 * Helper method to reduce the code duplication.
 * Reads the properties file(s) for the hub/node configuration and returns it as an {@link String} array
 *
 * @param role {@link String} The role for the grid. Can be hub or node.
 * @return An array of {@link String} property keys and values
 * @throws Exception Throws an {@link IOException} if the properties file cannot be found or
 * An {@link Exception} if property key has an invalid format
 *//*from  ww w.j  ava2s .co m*/
private static String[] getProperties(String role, int... gridPort) {
    if (role == null || role.isEmpty()) {
        throw new IllegalArgumentException("Role for the grid is required");
    }
    List<String> propertyKeysAndValues = new ArrayList<String>();
    Properties properties = new Properties();
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    // Load the properties
    String propertyPath = PROPERTY_FOLDER + role + PROPERTY_SUFFIX;
    try {
        properties.load(loader.getResourceAsStream(propertyPath));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Unable to load main property file %s", propertyPath), e);
    }
    // Load the local properties to override the existing ones
    String localPropertyPath = PROPERTY_FOLDER + role + PROPERTY_LOCAL_SUFFIX;
    InputStream localProperty = loader.getResourceAsStream(localPropertyPath);
    if (localProperty != null) {
        try {
            properties.load(localProperty);
        } catch (IOException e) {
            logger.error(String.format("Unable to load local property file: %s ", localPropertyPath), e);
        }
    }
    if (gridPort.length > 0) {
        properties.setProperty("hub.url.port", String.valueOf(gridPort[0]));
    }

    Set<Object> keys = properties.keySet();
    for (Object object : keys) {
        String key = (String) object;
        if (key.startsWith(PROPERTY_PREFIX)) {
            String parameter = key.split(PROPERTY_PREFIX)[1];
            if (StringUtils.isBlank(parameter)) {
                throw new RuntimeException("The property '" + key + "' does not have a valid format.");
            }
            String propertyKey = CMD_PARAMETER_PREFIX + parameter;
            String propertyValue = StrSubstitutor.replace(properties.getProperty(key), properties);
            propertyKeysAndValues.add(propertyKey);
            propertyKeysAndValues.add(propertyValue);
        }
    }
    return propertyKeysAndValues.toArray(new String[propertyKeysAndValues.size()]);
}

From source file:de.micromata.genome.util.runtime.StdLocalSettingsLoader.java

protected void loadSystemProperties(LocalSettings ls) {
    Properties props = System.getProperties();
    for (Object k : props.keySet()) {
        String key = (String) k;
        ls.getMap().put(key, props.getProperty(key));
    }//from  w w w  .j  a  v a 2  s .  co  m
}

From source file:com.liusoft.dlog4j.db.DataSourceConnectionProvider.java

/**
 * Initialize the datasource//from  w  w w  .j a  va 2  s.co m
 * @param props
 * @throws HibernateException
 */
protected synchronized void initDataSource(Properties props) throws HibernateException {
    String dataSourceClass = null;
    Properties new_props = new Properties();
    Iterator keys = props.keySet().iterator();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        //System.out.println(key+"="+props.getProperty(key));
        if (ENCODING_KEY.equalsIgnoreCase(key)) {
            encoding = "true".equalsIgnoreCase(props.getProperty(key));
            useProxy = true;
        } else if (DATASOURCE_KEY.equalsIgnoreCase(key)) {
            dataSourceClass = props.getProperty(key);
        } else if (key.startsWith(BASE_KEY)) {
            String value = props.getProperty(key);
            value = StringUtils.replace(value, "{DLOG4J}", Globals.WEBAPP_PATH);
            new_props.setProperty(key.substring(BASE_KEY.length()), value);
        }
    }
    if (dataSourceClass == null)
        throw new HibernateException("Property 'dscp.datasource' no defined.");
    try {
        dataSource = (DataSource) Class.forName(dataSourceClass).newInstance();
        BeanUtils.populate(dataSource, new_props);
    } catch (Exception e) {
        throw new HibernateException(e);
    }
}

From source file:org.apache.stratos.cloud.controller.validate.AWSEC2PartitionValidator.java

private void updateOtherProperties(IaasProvider updatedIaasProvider, Properties properties) {
    Iaas updatedIaas;//  w  ww  .  j a va2s .co  m
    try {
        updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider);

        for (Object property : properties.keySet()) {
            if (property instanceof String) {
                String key = (String) property;
                if (!Scope.zone.toString().equals(key)) {
                    updatedIaasProvider.setProperty(key, properties.getProperty(key));
                    if (log.isDebugEnabled()) {
                        log.debug("Added property " + key + " to the IaasProvider.");
                    }
                }
            }
        }
        updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider);
        updatedIaas.setIaasProvider(updatedIaasProvider);
    } catch (InvalidIaasProviderException ignore) {
    }

}

From source file:org.apache.zeppelin.spark.IUberSparkInterpreterTest.java

@Test
public void emptyConfigurationVariablesOnlyForNonSparkProperties() {
    Properties intpProperty = repl.getProperty();
    SparkConf sparkConf = repl.getSparkContext().getConf();
    for (Object oKey : intpProperty.keySet()) {
        String key = (String) oKey;
        String value = (String) intpProperty.get(key);
        repl.logger.debug(String.format("[%s]: [%s]", key, value));
        if (key.startsWith("spark.") && value.isEmpty()) {
            assertTrue(String.format("configuration starting from 'spark.' should not be empty. [%s]", key),
                    !sparkConf.contains(key) || !sparkConf.get(key).isEmpty());
        }// www .  j  a v  a 2  s.  com
    }
}

From source file:de.tobiyas.racesandclasses.commands.debug.CommandExecutor_RaceDebug.java

private long runDebugScan() {
    long startTime = System.currentTimeMillis();
    plugin.getDebugLogger().log("------------------------------------------------------------------");
    plugin.getDebugLogger().log("Running Full debug Scan");

    Properties props = System.getProperties();
    plugin.getDebugLogger().log("============System Properties============");
    for (Object objProp : props.keySet()) {
        String prop = (String) objProp;
        String value = props.getProperty(prop);
        plugin.getDebugLogger().log("Property: " + prop + " value: " + value);
    }/*from   w w  w .j  av a  2s.com*/

    long timeTook = System.currentTimeMillis() - startTime;
    plugin.getDebugLogger().log("Full debug scan finished. It took: " + timeTook + "ms.");
    plugin.getDebugLogger().log("------------------------------------------------------------------");

    return timeTook;
}

From source file:com.github.jrh3k5.plugin.maven.l10n.data.AbstractMessagesPropertiesParser.java

/**
 * Load the message keys of the translation file.
 * /*from   ww  w. ja v  a2s.c o  m*/
 * @return A {@link Set} of {@link String} objects representing the keys of the messages file.
 * @throws IOException
 *             If any errors occur while reading the messages file.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Set<String> getTranslationKeys(File messagesFile) throws IOException {
    final Properties properties = new Properties();
    try (final InputStream inputStream = new FileInputStream(messagesFile)) {
        properties.load(inputStream);
        return (Set) properties.keySet();
    }
}

From source file:org.acegisecurity.intercept.method.MethodDefinitionSourceEditor.java

public void setAsText(String s) throws IllegalArgumentException {
    MethodDefinitionMap source = new MethodDefinitionMap();

    if ((s == null) || "".equals(s)) {
        // Leave value in property editor null
    } else {/*  w w w  .  j  a  va  2s  . c  o m*/
        // Use properties editor to tokenize the string
        PropertiesEditor propertiesEditor = new PropertiesEditor();
        propertiesEditor.setAsText(s);

        Properties props = (Properties) propertiesEditor.getValue();

        // Now we have properties, process each one individually
        List mappings = new ArrayList();

        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String value = props.getProperty(name);

            MethodDefinitionSourceMapping mapping = new MethodDefinitionSourceMapping();
            mapping.setMethodName(name);

            String[] tokens = StringUtils.commaDelimitedListToStringArray(value);

            for (int i = 0; i < tokens.length; i++) {
                mapping.addConfigAttribute(tokens[i].trim());
            }

            mappings.add(mapping);
        }
        source.setMappings(mappings);
    }

    setValue(source);
}

From source file:org.apache.openaz.xacml.std.pap.StdPDPPIPConfig.java

public boolean initialize(Properties properties) {
    boolean classnameSeen = false;
    for (Object key : properties.keySet()) {
        if (key.toString().startsWith(this.id + ".")) {
            if (logger.isDebugEnabled()) {
                logger.debug("Found: " + key);
            }/*from   ww w  .  j av  a 2 s.co m*/
            if (key.toString().equals(this.id + ".name")) {
                this.name = properties.getProperty(key.toString());
            } else if (key.toString().equals(this.id + ".description")) {
                this.description = properties.getProperty(key.toString());
            } else if (key.toString().equals(this.id + ".classname")) {
                this.classname = properties.getProperty(key.toString());
                classnameSeen = true;
            }
            // all properties, including the special ones located above, are included in the properties
            // list
            this.config.put(key.toString(), properties.getProperty(key.toString()));
        }
    }
    return classnameSeen;
}

From source file:webim.WebimConfig.java

public WebimConfig() {
    Properties prop = new Properties();
    try {/*  w w w.j a v a 2s  .  com*/
        prop.load(getClass().getResourceAsStream("/webim/Webim.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    Set<Object> keys = prop.keySet();
    for (Iterator<Object> it = keys.iterator(); it.hasNext();) {
        String key = (String) it.next();
        String value = prop.getProperty(key);
        key = key.substring("webim.".length());
        if ("true".equals(value) || "false".equals(value)) {
            data.put(key, Boolean.valueOf(value));
        } else {
            data.put(key, value);
        }
    }
}