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:de.micromata.genome.logging.spi.FileLogConfigurationDAOImpl.java

@Override
protected void buildPattern() {
    Properties p = loadProperties();
    if (p == null) {
        return;//from www .j a v a 2s .com
    }
    List<Pair<String, Integer>> npattern = new ArrayList<>();
    for (Map.Entry<Object, Object> me : p.entrySet()) {
        String pattern = Objects.toString(me.getKey(), StringUtils.EMPTY);
        String v = Objects.toString(me.getValue(), StringUtils.EMPTY);
        LogLevel ll = LogLevel.valueOf(v);
        int ilev = ll.getLevel();
        if (pattern.equals(THRESHOLD_NAME) == true) {

            setMaxThreshold(ilev);
        } else {
            npattern.add(new Pair<String, Integer>(pattern, ilev));
        }
    }
    Collections.sort(npattern, new Comparator<Pair<String, Integer>>() {

        /**
         * @param o1 the object1
         * @param o2 the object2
         * @return the compare result
         */
        @Override
        public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
            return o2.getFirst().length() - o1.getFirst().length();
        }
    });
    List<Pair<Matcher<String>, Integer>> ncpattern = new ArrayList<Pair<Matcher<String>, Integer>>();
    for (Pair<String, Integer> pp : npattern) {
        ncpattern.add(new Pair<Matcher<String>, Integer>(matcherFactory.createMatcher(pp.getFirst()),
                pp.getSecond()));
    }
    synchronized (this) {
        pattern = ncpattern;
    }
}

From source file:org.apache.kylin.common.BackwardCompatibilityConfig.java

private void init(InputStream is) {
    if (is == null)
        return;//from ww  w  .jav  a 2 s  .com

    Properties props = new Properties();
    try {
        props.load(is);
    } catch (IOException e) {
        logger.error("", e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    for (Entry<Object, Object> kv : props.entrySet()) {
        String key = (String) kv.getKey();
        String value = (String) kv.getValue();

        if (key.equals(value))
            continue; // no change

        if (value.contains(key))
            throw new IllegalStateException("New key '" + value + "' contains old key '" + key
                    + "' causes trouble to repeated find & replace");

        if (value.endsWith("."))
            old2newPrefix.put(key, value);
        else
            old2new.put(key, value);
    }
}

From source file:com.impetus.kundera.persistence.EntityManagerFactoryBuilder.java

/**
 * Builds up EntityManagerFactory for a given persistenceUnitName and
 * overriding properties./*from  w  w w .  j a va 2s.  c om*/
 * 
 * @param persistenceUnitName
 *            the persistence unit name
 * @param override
 *            the override
 * @return the entity manager factory
 */
public EntityManagerFactory buildEntityManagerFactory(String persistenceUnitName,
        Map<Object, Object> override) {
    Properties props = new Properties();
    // Override properties

    KunderaMetadata kunderaMetadata = KunderaMetadata.INSTANCE;
    PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata()
            .getPersistenceUnitMetadata(persistenceUnitName);

    Properties metadataProperties = puMetadata.getProperties();
    // Make sure, it's empty or Unmodifiable
    override = override == null ? Collections.EMPTY_MAP : Collections.unmodifiableMap(override);

    // Take all from Metadata and override with supplied map
    for (Map.Entry<Object, Object> entry : metadataProperties.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();

        if (override.containsKey(key)) {
            value = override.get(key);
        }
        props.put(key, value);
    }

    // Now take all the remaining ones from override
    for (Map.Entry<Object, Object> entry : override.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();

        if (!props.containsKey(key)) {
            props.put(key, value);
        }
    }

    LOG.info("Building EntityManagerFactory for name: " + puMetadata.getPersistenceUnitName()
            + ", and Properties:" + props);
    return new EntityManagerFactoryImpl(puMetadata, props);
}

From source file:org.aon.esolutions.appconfig.client.web.SystemPropertiesListener.java

private void loadPropsFromClasspath(ServletContext sc) {
    String propertiesLocationProp = sc.getInitParameter("classpath.file.location");

    Properties systemProps = System.getProperties();
    Properties loadedProps = new Properties();
    ClassPathResource appConfigResource = new ClassPathResource(propertiesLocationProp);
    if (appConfigResource.exists()) {

        try {//from   www .  j  a va2  s.  c o m
            loadedProps.load(appConfigResource.getInputStream());

            for (Map.Entry<Object, Object> e : loadedProps.entrySet()) {
                if (systemProps.containsKey(e.getKey()) == false)
                    systemProps.put(e.getKey(), e.getValue());
            }
        } catch (Exception e) {
            logger.error("Error loading properties", e);
        }
    }
}

From source file:org.alloy.metal.xml.merge.MergeContext.java

/**
* Examines the properties file for an entry that contains the passed in component id string and returns its key
*
* to ignore.//from  w w  w.  j a  v a2  s . co m
*
* @param componentName
* @param props
* @return
*/
private String findComponentKey(String componentIdStr, Properties props) {
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof String) {
            String valueStr = (String) value;
            if (valueStr.contains(componentIdStr)) {
                Object key = entry.getKey();
                if (key instanceof String) {
                    return (String) key;
                }
            }
        }
    }
    return null;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.util.ManifestHelper.java

private Manifest createManifestInstance(final Properties buildMetaDataProperties) {
    final Manifest manifest = new Manifest();
    final Attributes attributes = fetchAttributes(manifest);
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    for (final Map.Entry<Object, Object> entry : buildMetaDataProperties.entrySet()) {
        final String key = ObjectUtils.toString(entry.getKey(), null);
        if (key.length() > MANIFEST_KEY_MAX_LENGTH) {
            continue;
        }/*from   w  ww .j  av a2  s. c o m*/

        final String normalizedKey = normalize(key);
        final String value = ObjectUtils.toString(entry.getValue(), null);

        attributes.putValue(normalizedKey, value);
    }

    return manifest;
}

From source file:org.apache.geode.internal.net.SocketCreator.java

/**
 * Used to read the properties from console. AgentLauncher calls this method directly & ignores
 * gemfire.properties. CacheServerLauncher and SystemAdmin call this through
 * {@link #readSSLProperties(Map)} and do NOT ignore gemfire.properties.
 * //from ww  w .j ava 2  s  .c  o m
 * @param env Map in which the properties are to be read from console.
 * @param ignoreGemFirePropsFile if <code>false</code> existing gemfire.properties file is read,
 *        if <code>true</code>, properties from gemfire.properties file are ignored.
 */
public static void readSSLProperties(Map<String, String> env, boolean ignoreGemFirePropsFile) {
    Properties props = new Properties();
    DistributionConfigImpl.loadGemFireProperties(props, ignoreGemFirePropsFile);
    for (Object entry : props.entrySet()) {
        Map.Entry<String, String> ent = (Map.Entry<String, String>) entry;
        // if the value of ssl props is empty, read them from console
        if (ent.getKey().startsWith(DistributionConfig.SSL_SYSTEM_PROPS_NAME)
                || ent.getKey().startsWith(DistributionConfig.SYS_PROP_NAME)) {
            String key = ent.getKey();
            if (key.startsWith(DistributionConfig.SYS_PROP_NAME)) {
                key = key.substring(DistributionConfig.SYS_PROP_NAME.length());
            }
            if (ent.getValue() == null || ent.getValue().trim().equals("")) {
                GfeConsoleReader consoleReader = GfeConsoleReaderFactory.getDefaultConsoleReader();
                if (!consoleReader.isSupported()) {
                    throw new GemFireConfigException(
                            "SSL properties are empty, but a console is not available");
                }
                if (key.toLowerCase().contains("password")) {
                    char[] password = consoleReader.readPassword("Please enter " + key + ": ");
                    env.put(key, PasswordUtil.encrypt(new String(password), false));
                } else {
                    String val = consoleReader.readLine("Please enter " + key + ": ");
                    env.put(key, val);
                }

            }
        }
    }
}

From source file:org.gvnix.dynamic.configuration.roo.addon.config.PropertiesListDynamicConfiguration.java

/**
 * {@inheritDoc}/*from  w  ww .  ja v  a2s  .co  m*/
 */
@Override
public DynPropertyList read() {

    DynPropertyList dynProps = new DynPropertyList();
    try {

        // Get the property files to read from resources
        String resources = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, ""), "");
        List<FileDetails> files = getFiles(resources);
        for (FileDetails file : files) {

            String path = file.getCanonicalPath();
            MutableFile mutableFile = fileManager.updateFile(path);

            // If managed file not exists, nothing to do
            if (mutableFile != null) {

                Properties props = new Properties();
                props.load(mutableFile.getInputStream());
                for (Entry<Object, Object> prop : props.entrySet()) {

                    dynProps.add(new DynProperty(setKeyValue(prop.getKey().toString(), path),
                            prop.getValue().toString()));
                }
            }

        }

    } catch (IOException ioe) {

        throw new IllegalStateException(ioe);
    }

    return dynProps;
}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.LocalVelocityConfigurer.java

/**
 * Prepare the VelocityEngine instance and return it.
 *
 * @return the VelocityEngine instance//from   www .ja va2 s.co m
 * @throws java.io.IOException if the config file wasn't found
 * @throws org.apache.velocity.exception.VelocityException
 *                             on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
    VelocityEngine velocityEngine = new VelocityEngine();
    Properties props = new Properties();

    // Merge local properties if set.
    if (!this.velocityProperties.isEmpty()) {
        props.putAll(this.velocityProperties);
    }

    // Apply properties to VelocityEngine.
    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        if (!(entry.getKey() instanceof String)) {
            throw new IllegalArgumentException(
                    "Illegal property key [" + entry.getKey() + "]: only Strings allowed");
        }
        velocityEngine.setProperty((String) entry.getKey(), entry.getValue());
    }

    initResourceLoader(velocityEngine);

    try {
        // Perform actual initialization.
        velocityEngine.init();
    } catch (IOException ex) {
        throw ex;
    } catch (VelocityException ex) {
        throw ex;
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
        throw new VelocityException(ex.getMessage());
    }

    return velocityEngine;
}

From source file:nl.strohalm.cyclos.services.customization.TranslationMessageServiceImpl.java

private void insertAll(final Properties properties) {
    final CacheCleaner cacheCleaner = new CacheCleaner(fetchService);
    for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
        final String key = (String) entry.getKey();
        final String value = (String) entry.getValue();
        final TranslationMessage translationMessage = new TranslationMessage();
        translationMessage.setKey(key);/*  ww  w.ja  va2 s. c  o m*/
        translationMessage.setValue(value);

        try {
            // Try to load first
            final TranslationMessage existing = translationMessageDao.load(key);
            // Existing - update
            existing.setValue(value);
            translationMessageDao.update(existing, false);
        } catch (final EntityNotFoundException e) {
            // Not found - insert
            translationMessageDao.insert(translationMessage);
        }
        // Clear the entity cache to avoid an explosion of messages in cache
        cacheCleaner.clearCache();
    }
}