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.springmodules.cache.interceptor.flush.AbstractFlushingInterceptor.java

/**
 * @throws FatalCacheException/*from w  w w.j a v  a  2s  . co m*/
 *           if the cache provider facade is <code>null</code>.
 * 
 * @see InitializingBean#afterPropertiesSet()
 * @see #onAfterPropertiesSet()
 */
public final void afterPropertiesSet() throws FatalCacheException {
    if (cacheProviderFacade == null) {
        throw new FatalCacheException("The cache provider facade should not be null");
    }

    if (flushingModels == null || flushingModels.isEmpty()) {
        return;
    }

    CacheModelValidator validator = cacheProviderFacade.modelValidator();

    if (flushingModels instanceof Properties) {
        PropertyEditor editor = cacheProviderFacade.getFlushingModelEditor();
        Properties properties = (Properties) flushingModels;
        Map newFlushingModels = new HashMap();

        String id = null;

        try {
            for (Iterator i = properties.keySet().iterator(); i.hasNext();) {
                id = (String) i.next();

                String property = properties.getProperty(id);
                editor.setAsText(property);
                Object flushingModel = editor.getValue();
                validator.validateFlushingModel(flushingModel);

                newFlushingModels.put(id, flushingModel);
            }
        } catch (Exception exception) {
            throw new FatalCacheException(
                    "Unable to create the flushing model with id " + StringUtils.quote(id), exception);
        }

        setFlushingModels(newFlushingModels);

    } else {
        String id = null;

        try {
            for (Iterator i = flushingModels.keySet().iterator(); i.hasNext();) {
                id = (String) i.next();
                Object flushingModel = flushingModels.get(id);
                validator.validateFlushingModel(flushingModel);
            }
        } catch (Exception exception) {
            throw new FatalCacheException("Unable to validate flushing model with id " + StringUtils.quote(id),
                    exception);
        }
    }

    onAfterPropertiesSet();
}

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>/some/path/node.prop</code> or
 * <code>/some/path/node.@type</code>.
 *//*from w  w w  .  j  a va  2  s  . c  om*/
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;
        // explicitly enforce certain syntax
        if (!orgKey.startsWith("/")) {
            throw new IllegalArgumentException("Missing trailing '/' for key: " + orgKey);
        }
        if (StringUtils.countMatches(orgKey, ".") > 1) {
            throw new IllegalArgumentException("Key must not contain more than one '.': " + orgKey);
        }
        if (orgKey.contains("@") && !orgKey.contains(".@")) {
            throw new IllegalArgumentException("Key containing '@' must be preceded by a '.': " + orgKey);
        }
        // if this is a node definition (no property)
        String newKey = orgKey;

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.removeStart(keySuffix, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + ".@type")) {
                    cleaned.put(path + ".@type", NodeTypes.ContentNode.NAME);
                }
                continue;
            }
            throw new IllegalArgumentException(
                    "Key for a path (everything without a '.' is considered to be a path) must not contain a value ('='): "
                            + orgKey);
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:com.netspective.sparx.navigate.NavigationControllerServletOptions.java

public String toString() {
    StringBuffer result = new StringBuffer();
    Properties props = setProperties(new Properties(), null, true);
    for (Iterator i = props.keySet().iterator(); i.hasNext();) {
        String propName = (String) i.next();
        String propValue = props.getProperty(propName);
        result.append(propName + " = " + propValue + "\n");
    }//from w  w  w.  j  a va 2  s .  co m
    return result.toString();
}

From source file:org.yamj.common.tools.PropertyTools.java

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
        throws BeansException {
    super.processProperties(beanFactory, props);

    PROPERTIES.clear();//from  w w  w .j  av a2 s.  co m
    for (Object key : props.keySet()) {
        String keyStr = key.toString();
        String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
        PROPERTIES.put(keyStr, valueStr);
    }

    LOG.info("Loaded {} properties", PROPERTIES.size());
}

From source file:org.apache.openjpa.jdbc.schema.DBCPDriverDataSource.java

/**
 * Case-insensitive search of the given properties for the given key.
 * @param props//from   ww  w  .j  a  va 2 s.com
 * @param key
 * @param defaultKey
 * @return Key name as found in properties or the given defaultKey if it was not found.
 */
private String hasKey(Properties props, String key, String defaultKey) {
    if (props != null && key != null) {
        for (Iterator<Object> itr = props.keySet().iterator(); itr.hasNext();) {
            String entry = (String) itr.next();
            if (key.equalsIgnoreCase(entry))
                return entry;
        }
    }
    return defaultKey;
}

From source file:com.fer.hr.olap.query.QuerySerializer.java

private Element appendProperties(Element rootElement) {
    Element props = new Element("Properties");
    Properties p = this.query.getProperties();
    if (p != null && !p.isEmpty()) {
        for (Object key : p.keySet()) {
            Element pe = new Element("Property");
            String k = key.toString();
            String v = p.getProperty(k);
            pe.setAttribute("name", k);
            pe.setAttribute("value", v);
            props.addContent(pe);//from w  ww  . j a  v a  2 s. c  o m
        }
    }
    rootElement.addContent(props);
    return rootElement;
}

From source file:org.apache.ode.store.hib.DbConfStoreConnectionFactory.java

public DbConfStoreConnectionFactory(DataSource ds, Properties initialProps, boolean createDatamodel,
        String txFactoryClassName) {
    _ds = ds;/*from  www  .  ja  v  a  2 s.c om*/

    // Don't want to pollute original properties
    Properties properties = new Properties();
    for (Object prop : initialProps.keySet()) {
        properties.put(prop, initialProps.get(prop));
    }

    __log.debug("using data source: " + ds);
    _dataSources.put(_guid, ds);

    if (createDatamodel) {
        properties.put(Environment.HBM2DDL_AUTO, "create-drop");
    }

    // Note that we don't allow the following properties to be overriden by the client.
    if (properties.containsKey(Environment.CONNECTION_PROVIDER))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.CONNECTION_PROVIDER);
    if (properties.containsKey(Environment.TRANSACTION_MANAGER_STRATEGY))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.TRANSACTION_MANAGER_STRATEGY);
    if (properties.containsKey(Environment.SESSION_FACTORY_NAME))
        __log.warn("Ignoring user-specified Hibernate property: " + Environment.SESSION_FACTORY_NAME);

    properties.put(SessionManager.PROP_GUID, _guid);
    properties.put(Environment.CONNECTION_PROVIDER, DataSourceConnectionProvider.class.getName());
    properties.put(Environment.TRANSACTION_MANAGER_STRATEGY, HibernateTransactionManagerLookup.class.getName());
    properties.put(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JTATransactionFactory");
    properties.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");

    if (__log.isDebugEnabled())
        __log.debug("Store connection properties: " + properties);

    initTxMgr(txFactoryClassName);
    SessionManager.registerTransactionManager(_guid, _txMgr);

    _sessionFactory = getDefaultConfiguration().setProperties(properties).buildSessionFactory();
}

From source file:kenh.xscript.Environment.java

/**
 * Load element packages from system properties.
 * If system property has name starts with <code>kenh.xscript.element.packages</code>,
 * it will be loaded by xScript.// w  w  w  .ja  v a 2 s  .com
 */
private void loadElementPackages_SystemProperties() {
    Properties p = System.getProperties();
    Set keys = p.keySet();
    for (Object key_ : keys) {
        if (key_ instanceof String) {
            String key = (String) key_;
            if (StringUtils.startsWith(key, ELEMENTS_PATH_PREFIX + ".")) {
                String name = StringUtils.substringAfter(key, ELEMENTS_PATH_PREFIX + ".");
                String funcPackage = p.getProperty(key);
                setElementPackage(name, funcPackage);
            }
        }
    }
}

From source file:com.redhat.rhn.common.conf.test.ConfigTest.java

public void testNamespaceProperties() throws Exception {
    Properties prop = c.getNamespaceProperties("web");
    assertTrue(prop.size() >= 8);/*w ww .j  a  v a2s .  co m*/
    for (Iterator i = prop.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        assertTrue(key.startsWith("web"));
    }
}

From source file:com.glaf.core.jdbc.connection.HikariCPConnectionProvider.java

public void configure(Properties props) throws RuntimeException {
    Properties properties = new Properties();

    for (Iterator<?> ii = props.keySet().iterator(); ii.hasNext();) {
        String key = (String) ii.next();
        properties.put(key, props.get(key));
        if (key.startsWith("hikari.")) {
            String newKey = key.substring(7);
            properties.put(newKey, props.get(key));
        }/*from  ww w  .ja v a2s  .c o  m*/
    }

    String jdbcDriverClass = properties.getProperty(DBConfiguration.JDBC_DRIVER);
    String jdbcUrl = properties.getProperty(DBConfiguration.JDBC_URL);
    Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(properties);

    log.info("HikariCP using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl);
    log.info("Connection properties: " + PropertiesHelper.maskOut(connectionProps, "password"));

    autocommit = PropertiesHelper.getBoolean(DBConfiguration.JDBC_AUTOCOMMIT, properties);
    log.info("autocommit mode: " + autocommit);

    if (jdbcDriverClass == null) {
        log.warn("No JDBC Driver class was specified by property " + DBConfiguration.JDBC_DRIVER);
    } else {
        try {
            Class.forName(jdbcDriverClass);
        } catch (ClassNotFoundException cnfe) {
            try {
                ClassUtils.classForName(jdbcDriverClass);
            } catch (Exception e) {
                String msg = "JDBC Driver class not found: " + jdbcDriverClass;
                log.error(msg, e);
                throw new RuntimeException(msg, e);
            }
        }
    }

    try {

        String validationQuery = properties.getProperty(ConnectionConstants.PROP_VALIDATIONQUERY);

        Integer initialPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_INITIALSIZE, properties);
        Integer minPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MINACTIVE, properties);
        Integer maxPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXACTIVE, properties);
        if (initialPoolSize == null && minPoolSize != null) {
            properties.put(ConnectionConstants.PROP_INITIALSIZE, String.valueOf(minPoolSize).trim());
        }

        Integer maxWait = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXWAIT, properties);

        if (maxPoolSize == null) {
            maxPoolSize = 50;
        }

        String dbUser = properties.getProperty(DBConfiguration.JDBC_USER);
        String dbPassword = properties.getProperty(DBConfiguration.JDBC_PASSWORD);

        if (dbUser == null) {
            dbUser = "";
        }

        if (dbPassword == null) {
            dbPassword = "";
        }

        HikariConfig config = new HikariConfig();
        config.setDriverClassName(jdbcDriverClass);
        config.setJdbcUrl(jdbcUrl);
        config.setUsername(dbUser);
        config.setPassword(dbPassword);
        config.setMaximumPoolSize(maxPoolSize);
        config.setDataSourceProperties(properties);
        if (StringUtils.isNotEmpty(validationQuery)) {
            config.setConnectionTestQuery(validationQuery);
        }
        if (maxWait != null) {
            config.setConnectionTimeout(maxWait * 1000L);
        }

        config.setMaxLifetime(1000L * 3600 * 8);

        String isolationLevel = properties.getProperty(DBConfiguration.JDBC_ISOLATION);
        if (isolationLevel == null) {
            isolation = null;
        } else {
            isolation = new Integer(isolationLevel);
            log.info("JDBC isolation level: " + DBConfiguration.isolationLevelToString(isolation.intValue()));
        }

        if (StringUtils.isNotEmpty(isolationLevel)) {
            config.setTransactionIsolation(isolationLevel);
        }

        ds = new HikariDataSource(config);

    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("could not instantiate HikariCP connection pool", ex);
        throw new RuntimeException("Could not instantiate HikariCP connection pool", ex);
    }

    Connection conn = null;
    try {
        conn = ds.getConnection();
        if (conn == null) {
            throw new RuntimeException("HikariCP connection pool can't get jdbc connection");
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    } finally {
        JdbcUtils.close(conn);
    }

}