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.apache.stratos.cloud.controller.iaases.docker.DockerPartitionValidator.java

private void updateOtherProperties(IaasProvider updatedIaasProvider, Properties properties) {
    for (Object property : properties.keySet()) {
        if (property instanceof String) {
            String key = (String) property;
            updatedIaasProvider.setProperty(key, properties.getProperty(key));
            if (log.isDebugEnabled()) {
                log.debug("Added property " + key + " to the IaasProvider.");
            }/*from   www  .j a  va  2  s.co  m*/
        }
    }
}

From source file:org.apache.hadoop.hive.ql.exec.mr.ExecDriver.java

/**
 * Given a Hive Configuration object - generate a command line fragment for passing such
 * configuration information to ExecDriver.
 *//*w w w.  j a  v a 2 s . co  m*/
public static String generateCmdLine(HiveConf hconf, Context ctx) throws IOException {
    HiveConf tempConf = new HiveConf();
    Path hConfFilePath = new Path(ctx.getLocalTmpPath(), JOBCONF_FILENAME);
    OutputStream out = null;

    Properties deltaP = hconf.getChangedProperties();
    boolean hadoopLocalMode = ShimLoader.getHadoopShims().isLocalMode(hconf);
    String hadoopSysDir = "mapred.system.dir";
    String hadoopWorkDir = "mapred.local.dir";

    for (Object one : deltaP.keySet()) {
        String oneProp = (String) one;

        if (hadoopLocalMode && (oneProp.equals(hadoopSysDir) || oneProp.equals(hadoopWorkDir))) {
            continue;
        }
        tempConf.set(oneProp, hconf.get(oneProp));
    }

    // Multiple concurrent local mode job submissions can cause collisions in
    // working dirs and system dirs
    // Workaround is to rename map red working dir to a temp dir in such cases
    if (hadoopLocalMode) {
        tempConf.set(hadoopSysDir, hconf.get(hadoopSysDir) + "/" + Utilities.randGen.nextInt());
        tempConf.set(hadoopWorkDir, hconf.get(hadoopWorkDir) + "/" + Utilities.randGen.nextInt());
    }

    try {
        out = FileSystem.getLocal(hconf).create(hConfFilePath);
        tempConf.writeXml(out);
    } finally {
        if (out != null) {
            out.close();
        }
    }
    return " -jobconffile " + hConfFilePath.toString();
}

From source file:org.apache.stratos.cloud.controller.iaases.gce.GCEPartitionValidator.java

private void updateOtherProperties(IaasProvider updatedIaasProvider, Properties properties) {
    for (Object property : properties.keySet()) {
        if (property instanceof String) {
            String key = (String) property;
            updatedIaasProvider.setProperty(key, properties.getProperty(key));
            if (log.isDebugEnabled()) {
                log.debug(String.format("Added [property] %s to the IaasProvider.", key));
            }//  w w w. ja va2 s .c o  m
        }
    }
}

From source file:com.aquest.emailmarketing.web.config.PropertiesUtil.java

@Override
protected void loadProperties(final Properties props) throws IOException {
    super.loadProperties(props);
    for (final Object key : props.keySet()) {
        properties.put((String) key, props.getProperty((String) key));
    }/*  ww w . jav a2  s  .com*/
}

From source file:net.theblackchamber.crypto.util.SecurePropertiesUtils.java

/**
 * Utility which will take an existing Properties file on disk and replace
 * any -unencrypted values with encrypted.<br>
 * //  w  w w  .jav  a2  s  . co  m
 * @param clearProperties
 *            Un-encrypted properties file to be secured
 * @param keyPath
 *            Path to the keystore file.
 * @param keyPass
 *            Password to be used to open and secure the Keystore password.
 * @param keyEntry
 *            Entry name of the key to use from the keystore.
 * @param retainCrytoConfigProperties
 *            Boolean to indicate if the encryption field parameters should
 *            be stored in the resulting SecureProperties file. True they
 *            will be, False they wont.
 * @return
 * @throws FileNotFoundException
 *             Properties file not found on disk.
 * @throws IOException
 *             Error reading/writing From the clear properties or to the
 *             secure properties
 * @throws KeyStoreException
 *             Error accessing or using the keystore.
 */
public static SecureProperties encryptPropertiesFile(File clearProperties, String keyPath, String keyPass,
        String keyEntry, boolean retainCrytoConfigProperties)
        throws FileNotFoundException, IOException, KeyStoreException {

    // Save filename/Path
    String propertiesFilePath = clearProperties.getPath();

    // Create new SecureProperties
    SecureProperties sProperties = new SecureProperties();

    // Open clear properties file and load it
    Properties cProperties = new Properties();
    FileInputStream fis = new FileInputStream(clearProperties);
    cProperties.load(fis);
    fis.close();

    // Ensure the encryption parameters are not empty.
    if (StringUtils.isEmpty(ENTRY_NAME_PROPERTY_KEY) || StringUtils.isEmpty(KEY_PATH_PROPERTY_KEY)
            || StringUtils.isEmpty(KEYSTORE_PASSWORD_PROPERTY_KEY)) {
        throw new KeyStoreException("Unable to configure due to missing configurations");
    }

    // Loop over clear properties and construct new SecureProperties object
    // First add crypto entries this will initialize the encryption support.
    sProperties.setProperty(ENTRY_NAME_PROPERTY_KEY, keyEntry);
    sProperties.setProperty(KEYSTORE_PASSWORD_PROPERTY_KEY, keyPass);
    sProperties.setProperty(KEY_PATH_PROPERTY_KEY, keyPath);

    for (Object key : cProperties.keySet()) {

        String keyStr = (String) key;
        if (!StringUtils.equals(keyStr, ENTRY_NAME_PROPERTY_KEY)
                && !StringUtils.equals(keyStr, KEYSTORE_PASSWORD_PROPERTY_KEY)
                && !StringUtils.equals(keyStr, KEY_PATH_PROPERTY_KEY)) {
            sProperties.setProperty(keyStr, cProperties.getProperty(keyStr));
        }

    }

    if (!retainCrytoConfigProperties) {
        // Remove the crypto entries from the secure file. Since its passed
        // in...
        sProperties.remove(ENTRY_NAME_PROPERTY_KEY);
        sProperties.remove(KEYSTORE_PASSWORD_PROPERTY_KEY);
        sProperties.remove(KEY_PATH_PROPERTY_KEY);
    }

    // Delete original file from disk
    clearProperties.delete();

    // Write SecureProperties out in its place
    OutputStream fos = new FileOutputStream(new File(propertiesFilePath));
    sProperties.store(fos, "File Encrypted by SecurePropertiesUtils");
    fos.flush();
    fos.close();

    // Return completed SecureProperties object
    return sProperties;

}

From source file:ca.gnewton.lusql.core.LuSqlMain.java

static void explainPlugin() throws ClassNotFoundException, NoSuchMethodException, InstantiationException,
        IllegalAccessException, java.lang.reflect.InvocationTargetException {
    String[] explain = getExplainPlugins();
    for (int i = 0; i < explain.length; i++) {
        Class<?> docSourceClass = Class.forName(explain[i]);
        Constructor<? extends Object> constructor = docSourceClass.getConstructor();
        Plugin plugin = (Plugin) constructor.newInstance();
        String pluginType = "Plugin";
        if (plugin instanceof DocFilter)
            pluginType = "Filter";
        else if (plugin instanceof DocSource)
            pluginType = "Source";
        if (plugin instanceof DocSink)
            pluginType = "Sink";
        Properties ex = plugin.explainProperties();
        log.info(explain[i]);/*from w  w w.j ava  2 s  . com*/
        log.info("Description: " + plugin.description());

        if (ex == null) {
            System.err.println("\tNo properties");
            return;
        }
        Iterator<Object> it = ex.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            log.info("Property: " + key + ": " + ex.get(key));
        }

    }
}

From source file:org.apache.stratos.cloud.controller.iaases.ec2.EC2PartitionValidator.java

private void updateProperties(IaasProvider updatedIaasProvider, Properties properties) {
    for (Object property : properties.keySet()) {
        if (property instanceof String) {
            String key = (String) property;
            updatedIaasProvider.setProperty(key, properties.getProperty(key));
            if (log.isDebugEnabled()) {
                log.debug(String.format("Added [property] %s to the IaasProvider.", key));
            }/*from  www .  ja  v  a  2 s  .c om*/
        }
    }
}

From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java

/**
  * Resolves any placeholders in the supplied properties map, preferring the use of
  * previously set System properties over the current property map contents for
  * placeholder substitution.//from  ww  w.  j a v  a  2 s  .c  om
  * <p>
  * Also sets any resolved properties as System properties, if no System
  * property by that name already exists.
  * 
  * @param properties the merged context properties
  */
public static void processProperties(final Properties properties, String placeholderPrefix,
        String placeholderSuffix) {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix);
    PropertyPlaceholderHelper.PlaceholderResolver resolver = new PropertyPlaceholderHelper.PlaceholderResolver() {
        @Override
        public String resolvePlaceholder(String placeholderName) {
            // SYSTEM_PROPERTIES_MODE_OVERRIDE means we look at previously set
            // system properties in preference to properties defined in our file
            String value = System.getProperty(placeholderName);
            if (value == null)
                value = properties.getProperty(placeholderName);
            return value;
        }
    };

    for (Object key : properties.keySet()) {
        String propertyName = (String) key;
        // get the value from the map
        String propertyValue = properties.getProperty(propertyName);
        // resolve it against system properties then other properties in the
        // passed-in Properties
        String resolvedValue = helper.replacePlaceholders(propertyValue, resolver);

        // set back into passed-in Properties if changed
        if (!ObjectUtils.nullSafeEquals(propertyValue, resolvedValue)) {
            properties.setProperty(propertyName, resolvedValue);
        }

        // set into System properties if not already set
        setProperty(propertyName, resolvedValue);
    }
}

From source file:fish.payara.maven.plugins.micro.processor.SystemPropAppendProcessor.java

private Element[] constructElementsForSystemProperties() {
    List<Element> elements = new ArrayList<>();
    Properties properties = System.getProperties();
    for (Object key : properties.keySet()) {
        Element element = element(name("line"), escapeJava(key + "=" + properties.get(key)));
        elements.add(element);/*from   w  w w  .  j  ava 2  s. co m*/
    }
    return elements.toArray(new Element[elements.size()]);
}

From source file:com.example.journal.env.JournalEnvironmentPostProcessor.java

private void contributeDefaults(Map<String, Object> defaults, Resource resource) {
    if (resource.exists()) {
        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(resource);
        yamlPropertiesFactoryBean.afterPropertiesSet();
        Properties p = yamlPropertiesFactoryBean.getObject();
        for (Object k : p.keySet()) {
            String key = k.toString();
            defaults.put(key, p.get(key));
        }/* w w w . java 2s. c  o  m*/
    }
}