Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

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

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:org.owasp.webgoat.i18n.LabelProvider.java

/**
 * <p>getLabels.</p>//ww w. j ava  2  s .  c o  m
 * Returns a merged map of all the labels for a specified language or the
 * default language, if the given language is not supported
 *
 * @param locale The Locale to get all the labels for
 * @return A Map of all properties with their values
 */
public Map<String, String> getLabels(Locale locale) {
    Properties messages = labels.getMessages(locale);
    messages.putAll(pluginLabels.getMessages(useLocaleOrFallbackToEnglish(locale)));
    Map<String, String> labelsMap = new HashMap<>();
    for (Map.Entry<Object, Object> entry : messages.entrySet()) {
        if (entry.getKey() != null && entry.getValue() != null) {
            labelsMap.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return labelsMap;
}

From source file:com.elasticgrid.amazon.boot.Bootstrapper.java

/**
 * This method translate EC2 lauch parameters into {@link Properties} which can be used through
 * all Elastic Grid code./*from w ww  . j a v  a2 s.  c om*/
 *
 * @param launchParameters the EC2 launch parameters
 * @return the Elastic Grid parameters
 * @throws IOException if the metadata can't be fetched
 */
private Properties translateProperties(Properties launchParameters) throws IOException {
    // translate properties
    Properties egParameters = new Properties();
    for (Map.Entry property : launchParameters.entrySet()) {
        String key = (String) property.getKey();
        if (LAUNCH_PARAMETER_ACCESS_ID.equals(key))
            egParameters.put(EC2Configuration.AWS_ACCESS_ID, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_ACCESS_ID))
            System.err.println("The Amazon Access ID could not be retrieved!");
        if (LAUNCH_PARAMETER_SECRET_KEY.equals(key))
            egParameters.put(EC2Configuration.AWS_SECRET_KEY, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_SECRET_KEY))
            System.err.println("The Amazon Secret Key could not be retrieved!");
        if (LAUNCH_PARAMETER_CLUSTER_NAME.equals(key))
            egParameters.put(EC2Configuration.EG_CLUSTER_NAME, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_CLUSTER_NAME))
            System.err.println("The name of the cluster could not be retrieved!");
        if (LAUNCH_PARAMETER_DROP_BUCKET.equals(key))
            egParameters.put(EC2Configuration.EG_DROP_BUCKET, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_DROP_BUCKET))
            System.err.println("The name of the Amazon S3 drop bucket could not be retrieved!");
        if (LAUNCH_PARAMETER_OVERRIDES_URL.equals(key))
            egParameters.put(EC2Configuration.EG_OVERRIDES_BUCKET, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_OVERRIDES_URL))
            egParameters.put(EC2Configuration.EG_OVERRIDES_BUCKET, "");
        if (LAUNCH_PARAMETER_EC2_SECURED.equals(key))
            egParameters.put(EC2Configuration.AWS_EC2_SECURED, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_SECURED))
            egParameters.put(EC2Configuration.AWS_EC2_SECURED, Boolean.TRUE.toString());
        if (LAUNCH_PARAMETER_SQS_SECURED.equals(key))
            egParameters.put(EC2Configuration.AWS_SQS_SECURED, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_SQS_SECURED))
            egParameters.put(EC2Configuration.AWS_SQS_SECURED, Boolean.TRUE.toString());
        if (LAUNCH_PARAMETER_EC2_KEYPAIR.equals(key))
            egParameters.put(EC2Configuration.AWS_EC2_KEYPAIR, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_KEYPAIR))
            System.err.println("The Amazon keypair name could not be retrieved!");
        /*
        else
        egParameters.put(EC2Configuration.AWS_EC2_KEYPAIR, EC2Utils.getInstanceMetadata("keypair"));    // todo: check the value of the metadata property
        */
        if (LAUNCH_PARAMETER_EC2_AMI32.equals(key))
            egParameters.put(EC2Configuration.AWS_EC2_AMI32, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_AMI32))
            System.err.println("The 32 bits AMI ID could not be retrieved!");
        if (LAUNCH_PARAMETER_EC2_AMI64.equals(key))
            egParameters.put(EC2Configuration.AWS_EC2_AMI64, property.getValue());
        else if (!launchParameters.containsKey(LAUNCH_PARAMETER_EC2_AMI64))
            System.err.println("The 64 bits AMI ID could not be retrieved!");

        if (LAUNCH_PARAMETER_YUM_PACKAGES.equals(key))
            egParameters.put(EC2Configuration.REDHAT_YUM_PACKAGES, property.getValue());
    }
    return egParameters;
}

From source file:net.jawr.web.resource.bundle.locale.message.grails.GrailsBundleMessageSource.java

/**
 * Returns all the messages//from w  ww.  j a  va2s . c  om
 * 
 * @return all the messages
 */
public Properties getAllMessages(Locale locale) {

    Properties props = new Properties();
    Properties mergedProps = null;
    if (locale == null) {
        locale = Locale.getDefault();
    }
    mergedProps = getMergedProperties(locale).getProperties();

    Set<Entry<Object, Object>> entries = mergedProps.entrySet();
    for (Entry<Object, Object> entry : entries) {
        String key = (String) entry.getKey();
        if (LocaleUtils.matchesFilter(key, filters)) {

            try {
                // Use the property encoding of the file
                String msg = getMessage(key, new Object[0], locale);

                // When war is deployed, the resource bundle are encoded in ISO 8859-1
                // and otherwise in UTF-8 
                // Check the following link for more detail https://grails.org/Internationalization
                if (!warDeployed) {
                    msg = new String(msg.getBytes(CHARSET_ISO_8859_1), CHARSET_UTF_8);
                }

                props.put(key, msg);
            } catch (NoSuchMessageException e) {
                // This is expected, so it's OK to have an empty catch
                // block.
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Message key [" + key + "] not found.");
            } catch (UnsupportedEncodingException e) {
                LOGGER.warn("Unable to convert value of message bundle associated to key '" + key
                        + "' because the charset is unknown");
            }
        }
    }
    return props;
}

From source file:nl.strohalm.cyclos.struts.CyclosMessageResources.java

private synchronized void reload(final Properties newProperties) {
    properties = LoggedUser.runAsSystem(new Callable<Properties>() {
        @Override// w ww . ja v  a2  s  . c o m
        public Properties call() throws Exception {
            // First, read the English properties, to ensure defaults
            final Properties properties = translationMessageService.readFile(Locale.US);
            // Then load all properties from DB
            final Properties dbProperties = newProperties == null
                    ? translationMessageService.exportAsProperties()
                    : newProperties;
            for (final Map.Entry<Object, Object> entry : dbProperties.entrySet()) {
                final String key = (String) entry.getKey();
                final String value = (String) entry.getValue();
                if (StringUtils.isNotEmpty(value)) {
                    properties.setProperty(key, value);
                }
            }
            return properties;
        }
    });

    // Clear the Struts cache
    formats.clear();
}

From source file:com.liferay.portal.spring.hibernate.PortalHibernateConfiguration.java

protected Configuration newConfiguration() {
    Configuration configuration = new Configuration();

    try {/*from  w w w.  j a va 2 s  .c  o m*/
        String[] resources = getConfigurationResources();

        for (String resource : resources) {
            try {
                readResource(configuration, resource);
            } catch (Exception e2) {
                if (_log.isWarnEnabled()) {
                    _log.warn(e2, e2);
                }
            }
        }

        configuration.setProperties(PropsUtil.getProperties());

        if (Validator.isNull(PropsValues.HIBERNATE_DIALECT)) {
            String dialect = determineDialect();

            configuration.setProperty("hibernate.dialect", dialect);
        }

        DB db = DBFactoryUtil.getDB();

        String dbType = db.getType();

        if (dbType.equals(DB.TYPE_HYPERSONIC)) {
            //configuration.setProperty("hibernate.jdbc.batch_size", "0");
        }
    } catch (Exception e1) {
        _log.error(e1, e1);
    }

    Properties hibernateProperties = getHibernateProperties();

    if (hibernateProperties != null) {
        for (Map.Entry<Object, Object> entry : hibernateProperties.entrySet()) {

            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            configuration.setProperty(key, value);
        }
    }

    return configuration;
}

From source file:org.apache.nifi.util.FlowFileUnpackagerV1.java

protected Map<String, String> getAttributes(final TarArchiveInputStream stream) throws IOException {

    final Properties props = new Properties();
    props.loadFromXML(new NonCloseableInputStream(stream));

    final Map<String, String> result = new HashMap<>();
    for (final Entry<Object, Object> entry : props.entrySet()) {
        final Object keyObject = entry.getKey();
        final Object valueObject = entry.getValue();
        if (!(keyObject instanceof String)) {
            throw new IOException("Flow file attributes object contains key of type "
                    + keyObject.getClass().getCanonicalName() + " but expected java.lang.String");
        } else if (!(keyObject instanceof String)) {
            throw new IOException("Flow file attributes object contains value of type "
                    + keyObject.getClass().getCanonicalName() + " but expected java.lang.String");
        }//  w ww.  j  a  va 2  s . co m

        final String key = (String) keyObject;
        final String value = (String) valueObject;
        result.put(key, value);
    }

    return result;
}

From source file:eu.riscoss.datacollector.fossology.FossologyRiskDataCollector.java

/**
 * @return A map that associates a license to its type (License -> LicenseType)
 */// w w  w.  j  a  va 2s  . com
private Map<String, String> getLicenseTypes() throws IOException {
    Map<String, String> result = new HashMap<String, String>();

    Properties licenseTypes = new Properties();
    licenseTypes.load(FossologyRiskDataCollector.class.getResourceAsStream("/licenseTypes.properties"));

    for (Map.Entry e : licenseTypes.entrySet()) {
        String[] parts = ((String) e.getValue()).split(",");
        for (String license : parts) {
            result.put(license.trim(), e.getKey().toString());
        }
    }

    return result;
}

From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManager.java

protected Map<INodeType, List<Synonyms>> loadSynonyms(final InputStream stream) throws IOException {
    Map<INodeType, List<Synonyms>> result = new HashMap<INodeType, List<Synonyms>>();

    Properties properties = new Properties();
    properties.load(stream);//from   ww w . j  av a  2  s  . c  o m

    for (Entry<Object, Object> propertyEntry : properties.entrySet()) {
        Pair<INodeType, Synonyms> pair = parseSynonyms(propertyEntry);

        List<Synonyms> synonymsList = result.get(pair.getLeft());
        if (synonymsList == null) {
            synonymsList = new ArrayList<Synonyms>();

            result.put(pair.getKey(), synonymsList);
        }
        synonymsList.add(pair.getRight());
    }

    return result;
}

From source file:org.obp.DefaultDataInstrument.java

private void loadDefaultsFromResource(String resourceName) {
    Properties properties = new Properties();
    try (InputStream is = getClass().getResourceAsStream(resourceName)) {
        properties.load(is);/*  w w w .ja v  a  2  s  .co  m*/
    } catch (IOException e) {
        logger.error("unable to load properties from " + resourceName, e);
    }

    for (Map.Entry entry : properties.entrySet()) {
        logger.info(entry.getKey() + " = " + entry.getValue());
        updateReadout((String) entry.getKey(), parseValue(entry.getValue()));
    }
}

From source file:com.jkoolcloud.tnt4j.utils.Utils.java

/**
 * Get object properties that match a certain prefix. New set of keys in the
 * resulting map will exclude the prefix.
 *
 * @param prefix/*from   w  ww.jav  a 2s.co m*/
 *            prefix to be used for pattern matching
 * @param p
 *            list of properties used for patter matching
 *
 * @return a map containing only those attributes that match a prefix.
 */
public static Map<String, Object> getAttributes(String prefix, Properties p) {
    HashMap<String, Object> settings = new HashMap<String, Object>(11);
    for (Entry<Object, Object> entry : p.entrySet()) {
        String key = entry.getKey().toString();
        if (key.startsWith(prefix)) {
            settings.put(key.substring(prefix.length()), entry.getValue());
        }
    }
    return settings;
}