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:com.glaf.jbpm.connection.DruidConnectionProvider.java

public void configure(Properties props) {
    Properties properties = new Properties();
    properties.putAll(props);/*ww  w .  ja  v  a  2s  .  c  o  m*/

    for (Iterator<Object> ii = props.keySet().iterator(); ii.hasNext();) {
        String key = (String) ii.next();
        if (key.startsWith("druid.")) {
            String newKey = key.substring(6);
            properties.put(newKey, props.get(key));
        }
    }

    Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(properties);
    log.info("Connection properties: " + PropertiesHelper.maskOut(connectionProps, Environment.PASS));

    String jdbcDriverClass = properties.getProperty(Environment.DRIVER);
    String jdbcUrl = properties.getProperty(Environment.URL);

    log.info("Druid using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl);

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

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

    try {

        Integer maxPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXACTIVE, properties);
        Integer maxStatements = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXSTATEMENTS, properties);

        Integer timeBetweenEvictionRuns = PropertiesHelper
                .getInteger(ConnectionConstants.PROP_TIMEBETWEENEVICTIONRUNS, properties);

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

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

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

        if (timeBetweenEvictionRuns == null) {
            timeBetweenEvictionRuns = 60;
        }

        if (maxWait == null) {
            maxWait = 60;
        }

        String dbUser = properties.getProperty(Environment.USER);
        String dbPassword = properties.getProperty(Environment.PASS);

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

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

        ds = new DruidDataSource();

        DruidDataSourceFactory.config(ds, properties);
        ds.setConnectProperties(properties);
        ds.setDriverClassName(jdbcDriverClass);
        ds.setUrl(jdbcUrl);
        ds.setUsername(dbUser);
        ds.setPassword(dbPassword);

        ds.setInitialSize(1);
        ds.setMinIdle(3);
        ds.setMaxActive(maxPoolSize);
        ds.setMaxWait(maxWait * 1000L);

        ds.setConnectionErrorRetryAttempts(30);
        ds.setDefaultAutoCommit(true);

        ds.setTestOnReturn(false);
        ds.setTestOnBorrow(false);
        ds.setTestWhileIdle(false);

        if (StringUtils.isNotEmpty(validationQuery)) {
            log.debug("validationQuery:" + validationQuery);
            ds.setValidationQuery(validationQuery);
            ds.setTestWhileIdle(true);// ??????
        }

        ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns * 1000L);// ??
        ds.setMinEvictableIdleTimeMillis(1000L * 60L * 120L);// ????

        if (maxStatements != null) {
            ds.setPoolPreparedStatements(true);
            ds.setMaxOpenPreparedStatements(maxStatements);
            ds.setMaxPoolPreparedStatementPerConnectionSize(200);
        }

        ds.setRemoveAbandoned(false);// ? true/false
        ds.setRemoveAbandonedTimeout(7200);// 120
        ds.setLogAbandoned(true);// ?

        ds.init();
    } catch (Exception e) {
        log.error("could not instantiate Druid connection pool", e);
        throw new RuntimeException("Could not instantiate Druid connection pool", e);
    }

    String i = properties.getProperty(Environment.ISOLATION);
    if (i == null) {
        isolation = null;
    } else {
        isolation = new Integer(i);
    }

}

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

public void configure(Properties props) {
    Properties properties = new Properties();
    properties.putAll(props);/*from www . ja va 2s  . c  o m*/

    for (Iterator<Object> ii = props.keySet().iterator(); ii.hasNext();) {
        String key = (String) ii.next();
        if (key.startsWith("druid.")) {
            String newKey = key.substring(6);
            properties.put(newKey, props.get(key));
        }
    }

    Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(properties);
    log.info("Connection properties: " + PropertiesHelper.maskOut(connectionProps, "password"));

    String jdbcDriverClass = properties.getProperty("jdbc.driver");
    String jdbcUrl = properties.getProperty("jdbc.url");

    log.info("Druid using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl);

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

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

    try {

        Integer maxPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXACTIVE, properties);
        Integer maxStatements = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXSTATEMENTS, properties);

        Integer timeBetweenEvictionRuns = PropertiesHelper
                .getInteger(ConnectionConstants.PROP_TIMEBETWEENEVICTIONRUNS, properties);

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

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

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

        if (timeBetweenEvictionRuns == null) {
            timeBetweenEvictionRuns = 60;
        }

        if (maxWait == null) {
            maxWait = 60;
        }

        String dbUser = properties.getProperty("jdbc.user");
        String dbPassword = properties.getProperty("jdbc.password");

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

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

        ds = new DruidDataSource();

        DruidDataSourceFactory.config(ds, properties);
        ds.setConnectProperties(properties);
        ds.setDriverClassName(jdbcDriverClass);
        ds.setUrl(jdbcUrl);
        ds.setUsername(dbUser);
        ds.setPassword(dbPassword);

        ds.setInitialSize(1);
        ds.setMinIdle(3);
        ds.setMaxActive(maxPoolSize);
        ds.setMaxWait(maxWait * 1000L);

        ds.setConnectionErrorRetryAttempts(30);
        ds.setDefaultAutoCommit(true);

        ds.setTestOnReturn(false);
        ds.setTestOnBorrow(false);
        ds.setTestWhileIdle(false);

        if (StringUtils.isNotEmpty(validationQuery)) {
            log.debug("validationQuery:" + validationQuery);
            ds.setValidationQuery(validationQuery);
            ds.setTestWhileIdle(true);// ??????
        }

        ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns * 1000L);// ??
        ds.setMinEvictableIdleTimeMillis(1000L * 60L * 120L);// ????

        if (maxStatements != null) {
            ds.setPoolPreparedStatements(true);
            ds.setMaxOpenPreparedStatements(maxStatements);
            ds.setMaxPoolPreparedStatementPerConnectionSize(200);
        }

        ds.setRemoveAbandoned(false);// ? true/false
        ds.setRemoveAbandonedTimeout(7200);// 120
        ds.setLogAbandoned(true);// ?

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

    String i = properties.getProperty("jdbc.isolation");
    if (i == null) {
        isolation = null;
    } else {
        isolation = new Integer(i);
    }

}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 */// w  w w.ja v a2 s .c  o  m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

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

        // 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", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:it.txt.ens.authorisationService.test.IntegrationTest.java

@Test
public void test2() throws Exception {

    //configure and start the ENS
    ServiceReference<ConfigurationAdmin> configAdminSR = context.getServiceReference(ConfigurationAdmin.class);
    assertNotNull("No service reference found for " + ConfigurationAdmin.class.getName(), configAdminSR);
    ConfigurationAdmin configAdmin = context.getService(configAdminSR);
    assertNotNull("No instance found for " + ConfigurationAdmin.class.getName(), configAdminSR);

    File file = new File(System.getProperty(CONFIG_FILE_PROPERTY));
    FileInputStream stream = new FileInputStream(file);
    Properties p = new Properties();
    try {/*from ww w  .j  a v  a2s.c  o  m*/
        p.load(stream);
    } finally {
        if (stream != null)
            stream.close();
    }
    Dictionary<String, Object> prop = new Hashtable<String, Object>(p.size());

    for (Object key : p.keySet()) {
        if (key.equals(PropertiesKeys.CONFIGURATION_FILE_PATH_ATTRIBUTE))
            prop.put((String) key, p.getProperty((String) key));
        else if (key.equals(PropertiesKeys.ENS_GUI_ATTRIBUTE))
            prop.put((String) key, Boolean.parseBoolean(p.getProperty((String) key)));
        else if (key.equals(PropertiesKeys.THREAD_POOL_SIZE_ATTRIBUTE))
            prop.put((String) key, Integer.parseInt(p.getProperty((String) key)));
        else
            continue;
    }
    Configuration config = configAdmin.getConfiguration(ENSAuthorisationServiceMS.SERVICE_PID);
    config.update(prop);

    Thread.sleep(60000);

    //delete the configuration
    config.delete();
}

From source file:jfs.sync.JFSFileProducerManager.java

/**
 * Registers all factories and sets the default factory.
 *//*  w  w  w .  j  a  v a2 s .  c  o m*/
@SuppressWarnings("unchecked")
private JFSFileProducerManager() {
    factories = new HashMap<String, JFSFileProducerFactory>();
    Properties p = new Properties();
    ClassLoader classLoader = this.getClass().getClassLoader();
    try {
        p.load(classLoader.getResourceAsStream("producers.properties"));
    } catch (Exception e) {
        log.error("JFSFileProducerManager()", e);
    } // try/catch
    for (Object property : p.keySet()) {
        String className = "" + property;
        if (className.startsWith("jfs.sync.")) {
            if ("on".equals(p.getProperty(className))) {
                try {
                    Class<JFSFileProducerFactory> c = (Class<JFSFileProducerFactory>) classLoader
                            .loadClass(className);
                    Constructor<JFSFileProducerFactory> constructor = c.getConstructor(new Class<?>[0]);
                    JFSFileProducerFactory factory = constructor.newInstance(new Object[0]);
                    String name = factory.getName();
                    factories.put(name, factory);
                } catch (Exception e) {
                    log.error("JFSFileProducerManager()", e);
                } // try/catch
            } // if
        } // if
    } // for
    defaultFactory = factories.get(JFSLocalFileProducerFactory.SCHEME_NAME);
}

From source file:com.bluexml.side.framework.alfresco.commons.configurations.PropertiesConfiguration.java

protected void loadResource(Resource r) {
    if (r.exists()) {
        Properties properties = new Properties();
        try {//from w ww.j a  va2  s. c om
            properties.load(r.getInputStream());
            logger.info("Load Properties form Resource " + r);
        } catch (IOException e) {
            logger.error("Unexpected error loading property file \"" + r.getFilename() + "\" ", e);
        }
        if (isValidePropertiesResource(properties)) {
            for (Object property : properties.keySet()) {
                String key = (String) property;
                String value = (String) properties.getProperty(key);
                dictionary.put(key, value);
            }
        }
    } else {
        logger.info("Resource do not exists :" + r.getDescription());
    }
}

From source file:at.gv.egiz.pdfas.lib.settings.Settings.java

private Map<String, String> getValuesPrefix(String prefix, Properties props) {
    Iterator<Object> keyIterator = props.keySet().iterator();
    Map<String, String> valueMap = new HashMap<String, String>();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next().toString();

        if (key.startsWith(prefix)) {
            valueMap.put(key, props.getProperty(key));
        }//from   w  ww.j  a  v a2 s  .c om
    }

    if (valueMap.isEmpty()) {
        return null;
    }

    return valueMap;
}

From source file:org.esgf.web.SearchConfigurationController.java

/**
 * This method gives a response to a request (called by esgf-web-fe/web/scripts/esgf/solr.js) for the facets defined in the file facets.properties.  
 * The logic places all facets (delimited by a ; for the time being) into a json array, where it is parsed in solr.js
 * //from ww  w.ja v a  2 s  .  c o  m
 * @return String Json representation of the facet array
 * 
 * @throws IOException
 * @throws JSONException
 * @throws ParserConfigurationException
 */
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody String doGet() throws IOException, ParserConfigurationException, JSONException {

    Properties properties = new Properties();
    //String propertiesFile = WRITEABLE_SEARCHCONFIG_FILE;

    String propertiesFile = SEARCHCONFIG_PROPERTIES_FILE;

    SearchConfiguration searchConfig = new SearchConfiguration();

    try {
        properties.load(new FileInputStream(propertiesFile));

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

            String value = (String) properties.get(key);

            //grab the globus online parameter
            if (key.equals("enableGlobusOnline")) {
                searchConfig.setEnableGlobusOnline(value);
            }
        }

    } catch (FileNotFoundException fe) {

        System.out.println("---------------------------------------------------------------------");
        System.out.println("Search Configuration file not found.  Setting the following defaults:");
        System.out.println("\tGlobus Online Enabled: " + searchConfig.getEnableGlobusOnline());
        System.out.println("---------------------------------------------------------------------");
    } catch (Exception e) {
        e.printStackTrace();
    }

    String json = searchConfig.toJSON();

    return json;

}

From source file:com.laex.j2objc.ToObjectiveCDelegate.java

/**
 * Builds the command.//from   w  w  w .j av  a 2 s  .c  om
 *
 * @param display the display
 * @param prefs the prefs
 * @param project the project
 * @param resource the resource
 * @param sourcePath the source path
 * @param outputPath the output path
 * @return the string
 * @throws CoreException the core exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private String buildCommand(Display display, Map<String, String> prefs, IProject project, IResource resource,
        String sourcePath, String outputPath) throws CoreException, IOException {
    StringBuilder sb = new StringBuilder();

    // Create platform indenpendent path and append the path to the compiler
    IPath pathToCompiler = new Path(prefs.get(PreferenceConstants.PATH_TO_COMPILER))
            .append(PreferenceConstants.J2_OBJC_COMPILER);
    sb.append(pathToCompiler.toOSString()).append(" ");

    Properties classpathProps = PropertiesUtil.getClasspathEntries(project);
    if (!classpathProps.isEmpty()) {
        sb.append(PreferenceConstants.CLASSPAPTH).append(" ");
        for (Object key : classpathProps.keySet()) {
            sb.append(key).append(":");
        }
        sb.append(" ");
    }

    if (StringUtils.isEmpty(prebuiltSwitch)) {
        prebuildSwitches(display, prefs, project);
    }

    sb.append(prebuiltSwitch);

    if (resource instanceof IFile) {
        String charset = ((IFile) resource).getCharset();
        sb.append(PreferenceConstants.ENCODING).append(" ").append(charset).append(" ");
    }

    sb.append(PreferenceConstants.OUTPUT_DIR).append(" ").append(outputPath).append(" ");
    sb.append(sourcePath);

    return sb.toString();
}

From source file:com.sangupta.shire.layouts.LayoutManager.java

/**
 * Create a data model out of this {@link TemplateData} object that can be
 * used with the {@link Layout}./* ww w  .j  av a2 s  .c  o m*/
 * 
 * @param data
 *            the template data that needs to be converted
 * 
 * @return the converted data model as a {@link Map}
 * 
 * @throws <code>NullPointerException</code> if the provided
 *         {@link TemplateData} object is null
 * 
 */
private Map<String, Object> getDataModel(final TemplateData data) {
    final Map<String, Object> model = new HashMap<String, Object>();

    // site and front matter
    if (data.getSite() instanceof Map) {
        model.put("site", data.getSite());
    } else {
        Map<String, Object> siteData = new HashMap<String, Object>();
        model.put("site", siteData);
        Site site = data.getSite();

        siteData.put("url", site.getUrl());
        siteData.put("time", site.getTime());
        siteData.put("posts", site.getPosts());
        siteData.put("pages", site.getPages());
        siteData.put("relatedPosts", site.getRelatedPosts());
        siteData.put("recentPosts", site.getRecentPosts());
        siteData.put("tags", site.getTags());
        siteData.put("categories", site.getCategories());
        siteData.put("blogName", site.getBlogName());
        siteData.put("baseURL", site.getBaseURL());
        siteData.put("debug", site.isDebug());

        // merge all the properties of page front matter
        Properties matter = this.options.getConfiguration();
        if (matter != null) {
            Set<Object> keys = matter.keySet();
            for (Object obj : keys) {
                String key = (String) obj;
                String value = matter.getProperty((String) key);
                siteData.put(key, value);
            }
        }
    }

    // page and front matter
    if (data.getPage() instanceof Map) {
        model.put("page", data.getPage());
    } else {
        Map<String, Object> pageData = new HashMap<String, Object>();
        model.put("page", pageData);
        Page page = data.getPage();

        pageData.put("content", page.getContent());
        pageData.put("title", page.getTitle());
        pageData.put("url", page.getUrl());
        pageData.put("date", page.getDate());
        pageData.put("id", page.getId());
        pageData.put("tags", page.getTags());
        pageData.put("categories", page.getCategories());
        pageData.put("previousEntry", page.getPreviousEntry());
        pageData.put("nextEntry", page.getNextEntry());

        // merge all the properties of page front matter
        Properties matter = page.getFrontMatter();
        if (matter != null) {
            Set<Object> keys = matter.keySet();
            for (Object obj : keys) {
                String key = (String) obj;
                String value = matter.getProperty((String) key);
                pageData.put(key, value);
            }
        }
    }

    // paginator
    model.put("paginator", data.getPaginator());

    return model;
}