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:com.callidusrobotics.irc.scheduler.ScriptJob.java

@Override
public void executeDelegate(JobExecutionContext context) throws JobExecutionException {
    if (gse == null) {
        return;// w ww  .  j a v a 2s.c  om
    }

    script = data.getString(SCRIPT_KEY);
    System.out.println("executing script '" + script + "'...");

    // Set each property as a variable binding for the script engine
    Binding binding = new Binding();
    Properties properties = bot.getProperties();
    for (Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        binding.setVariable(key, value);
    }

    // Add the list of users in the channel as a variable binding for the script engine
    binding.setVariable("USERS", bot.getUsers());

    // Add the bot's version as a variable binding for the script engine
    binding.setVariable("VERSION", NaNoBot.getImplementationVersion());

    try {
        gse.run(script, binding);
    } catch (ResourceException | ScriptException e) {
        throw new JobExecutionException(e);
    }

    // Persist the variable bindings back into the bot's properties
    @SuppressWarnings("unchecked")
    Map<Object, Object> bindingVariables = (Map<Object, Object>) binding.getVariables();
    for (Entry<Object, Object> entry : bindingVariables.entrySet()) {
        String key = (String) entry.getKey();

        if (key.equals("MESSAGE") || key.equals("USERS") || key.equals("VERSION") || key.startsWith("_")) {
            continue;
        }

        String value = entry.getValue() == null ? "" : entry.getValue().toString();
        bot.getProperties().setProperty(key, value);
    }

    // Send the script's message to the channel
    if (binding.hasVariable("MESSAGE")) {
        String message = (String) binding.getVariable("MESSAGE");
        if (!StringUtils.isBlank(message)) {
            bot.sendMessageToChannel(message);
        }
    }
}

From source file:org.carewebframework.api.property.mock.MockPropertyService.java

/**
 * Constructor to allow initialization of property values from a property file. A property
 * values are assumed local unless the property name is prefixed with "global.". You may specify
 * an instance name by appending to the property name a "\" followed by the instance name. For
 * example:/*from w ww .  j  a v  a  2  s . co m*/
 * 
 * <pre>
 *  prop1 = value1
 *  global.prop2 = value2
 *  prop3\inst3 = value3
 *  global.prop4\inst4 = value4
 * </pre>
 * 
 * @param resource Property file resource.
 * @throws IOException IO exception.
 */
public MockPropertyService(Resource resource) throws IOException {
    Properties props = PropertiesLoaderUtils.loadProperties(resource);

    for (Entry<?, ?> entry : props.entrySet()) {
        String key = (String) entry.getKey();
        String value = StringEscapeUtils.unescapeJava((String) entry.getValue());
        boolean global = key.startsWith("global.");
        key = global ? key.substring(7) : key;

        if (!key.contains(delim)) {
            key += delim;
        }

        (global ? global_map : local_map).put(key, value);
    }
}

From source file:org.yamj.core.configuration.ConfigService.java

@Required
public void setCoreProperties(Properties properties) {
    for (Entry<Object, Object> entry : properties.entrySet()) {
        cachedProperties.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
    }/*from w ww .  j av  a 2s . c  o m*/
}

From source file:net.mindengine.blogix.web.BlogixServlet.java

private void loadSupportedMimeTypes() {
    supportedMimeTypes = new HashMap<String, String>();
    try {//  w  ww .j  a v  a2 s.c o  m
        File file = BlogixFileUtils.findFile("conf/supported-mime-types.cfg");
        Properties props = new Properties();
        props.load(new FileReader(file));

        Set<Entry<Object, Object>> entrySet = props.entrySet();
        for (Entry<Object, Object> entry : entrySet) {
            supportedMimeTypes.put(entry.getKey().toString().trim(), entry.getValue().toString().trim());
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:org.dspace.webmvc.theme.ThemeChangeInterceptor.java

public void setMappings(Properties mappings) {
    for (Map.Entry entry : mappings.entrySet()) {
        try {/*from   www  . j  a  va2  s . c  o  m*/
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            if (key != null && value != null) {
                ThemeMapEntry themeMapEntry = new ThemeMapEntry();

                if (key.startsWith(VIEW_PREFIX)) {
                    themeMapEntry.mapType = MapType.VIEW;
                    key = key.substring(VIEW_PREFIX.length());
                } else if (key.startsWith(URL_PREFIX)) {
                    themeMapEntry.mapType = MapType.URL;
                    key = key.substring(URL_PREFIX.length());
                } else if (key.startsWith(CONTROLLER_PREFIX)) {
                    themeMapEntry.mapType = MapType.CONTROLLER;
                    key = key.substring(CONTROLLER_PREFIX.length());
                }

                themeMapEntry.path = key;
                themeMapEntry.themeName = value;

                themeMappings.add(themeMapEntry);
            }
        } catch (ClassCastException cce) {
            // TODO Debug log class cast
        }
    }
}

From source file:net.cnmconsulting.spring.config.PropertiesFactoryBean.java

/**
 * This method scans for property values that are marked as encrypted
 * and decryptes those values.//from   w w w .ja v a2  s.c  o m
 * 
 * Template method that subclasses may override to construct the object
 * returned by this factory. The default implementation returns the plain
 * merged Properties instance.
 * <p>
 * Invoked on initialization of this FactoryBean in case of a shared
 * singleton; else, on each {@link #getObject()} call.
 * 
 * @return the object returned by this factory
 * @throws IOException
 *             if an exception occured during properties loading
 * @deprecated as of Spring 3.0, in favor of {@link #createProperties()}
 */
@Deprecated
protected Object createInstance() throws IOException {
    Properties props = mergeProperties();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {

        if ((entry.getValue() instanceof String)) {

            String value = (String) entry.getValue();
            if (PropertyValueEncryptionUtils.isEncryptedValue(value)) {
                String decrypted = PropertyValueEncryptionUtils.decrypt(value, this.stringEncryptor);
                props.put(entry.getKey(), decrypted);
            }
        }
    }

    return props;

}

From source file:org.obiba.magma.datasource.mongodb.MongoDBDatasourceFactory.java

public URI getUri() {
    try {/*from  w ww . j  a va 2  s  . c  o m*/
        URIBuilder uriBuilder = new URIBuilder(url);
        if (!Strings.isNullOrEmpty(username)) {
            if (Strings.isNullOrEmpty(password)) {
                uriBuilder.setUserInfo(username);
            } else {
                uriBuilder.setUserInfo(username, password);
            }
        }
        Properties prop = readOptions();
        for (Map.Entry<Object, Object> entry : prop.entrySet()) {
            uriBuilder.addParameter(entry.getKey().toString(), entry.getValue().toString());
        }
        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new RuntimeException("Cannot create MongoDB URI", e);
    }
}

From source file:hoptoad.HoptoadNoticeBuilder.java

protected void environment(Properties properties) {
    for (Entry<Object, Object> property : properties.entrySet()) {
        this.environment.put(property.getKey().toString(), property.getValue());
    }//from  w  ww  .  j av a  2 s.  c  o m
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.PropertiesChainedRegexURLRequestMapperDAO.java

/** @see URLRequestMapperDAO#load() */
public final URLRequestMapper load() {
    final Properties p = provider.getProperties();
    final List<Entry<Object, Object>> l = new ArrayList<Entry<Object, Object>>(p.entrySet());

    Collections.sort(l, new Comparator<Entry<Object, Object>>() {
        public int compare(final Entry<Object, Object> o1, final Entry<Object, Object> o2) {
            final Long i1 = Long.parseLong(o1.getKey().toString());
            final Long i2 = Long.parseLong(o2.getKey().toString());
            return i1.compareTo(i2);
        }//from  w  w  w  .  j a  v a  2s  .  c o m
    });

    final StringBuffer sb = new StringBuffer();
    for (final Entry<Object, Object> entry : l) {
        sb.append(entry.getValue());
        sb.append('\n');
    }
    final URLRequestMapperEditor propertyEditor = new URLRequestMapperEditor();
    propertyEditor.setStripContextPath(stripContextPath);
    propertyEditor.setStripServletPath(stripServletPath);
    propertyEditor.setAsText(sb.toString());
    return (URLRequestMapper) propertyEditor.getValue();
}

From source file:com.sky.projects.pool.hbase.HbaseConnectionFactory.java

/**
 * @since 1.2.1//from   w  w  w. jav a2s . c o m
 * @param properties
 *            ??
 */
public HbaseConnectionFactory(final Properties properties) {
    this.hadoopConfiguration = new Configuration();

    for (Entry<Object, Object> entry : properties.entrySet()) {
        this.hadoopConfiguration.set((String) entry.getKey(), (String) entry.getValue());
    }
}