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.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase.java

private final void createCache(final boolean client, final CacheFactory factory) {
    synchronized (JUnit4CacheTestCase.class) {
        try {//w  w  w .j  a v  a 2 s .com
            System.setProperty(GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
            InternalCache newCache;
            if (client) {
                System.setProperty(GEMFIRE_PREFIX + "locators", "");
                System.setProperty(GEMFIRE_PREFIX + MCAST_PORT, "0");
                newCache = (InternalCache) new ClientCacheFactory(getSystem().getProperties()).create();
            } else {
                if (factory == null) {
                    newCache = (InternalCache) CacheFactory.create(getSystem());
                } else {
                    Properties config = getSystem().getProperties();
                    for (Map.Entry entry : config.entrySet()) {
                        factory.set((String) entry.getKey(), (String) entry.getValue());
                    }
                    newCache = (InternalCache) factory.create();
                }
            }
            cache = newCache;

        } catch (CacheExistsException e) {
            Assert.fail("the cache already exists", e); // TODO: remove error handling

        } catch (RuntimeException ex) {
            throw ex;

        } catch (Exception ex) {
            Assert.fail("Checked exception while initializing cache??", ex);

        } finally {
            System.clearProperty(GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
            System.clearProperty(GEMFIRE_PREFIX + "locators");
            System.clearProperty(GEMFIRE_PREFIX + MCAST_PORT);
        }
    }
}

From source file:org.netxilia.api.impl.storage.DataSourceConfigurationServiceImpl.java

@Override
public List<WorkbookId> findAllWorkbooksConfigurationsForDatasource(DataSourceConfigurationId id)
        throws StorageException {
    init();//from  ww w.j a va  2 s. c  o  m
    Properties props = loadWorkbookToDataSourceFile();
    List<WorkbookId> list = new ArrayList<WorkbookId>();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        WorkbookId workbookId = new WorkbookId(entry.getKey().toString());
        DataSourceConfigurationId cfgId = new DataSourceConfigurationId(entry.getValue().toString());
        if (id.equals(cfgId)) {
            list.add(workbookId);
        }
    }
    return list;
}

From source file:com.agimatec.validation.jsr303.ConstraintDefaults.java

private Map<String, Class[]> loadDefaultConstraints(String resource) {
    Properties constraintProperties = new Properties();
    final ClassLoader classloader = getClassLoader();
    InputStream stream = classloader.getResourceAsStream(resource);
    if (stream != null) {
        try {/*from   w ww.jav a  2s.c om*/
            constraintProperties.load(stream);
        } catch (IOException e) {
            log.error("cannot load " + resource, e);
        }
    } else {
        log.warn("cannot find " + resource);
    }
    Map<String, Class[]> loadedConstraints = new HashMap();
    for (Map.Entry entry : constraintProperties.entrySet()) {

        StringTokenizer tokens = new StringTokenizer((String) entry.getValue(), ", ");
        LinkedList classes = new LinkedList();
        while (tokens.hasMoreTokens()) {
            final String eachClassName = tokens.nextToken();

            Class constraintValidatorClass = SecureActions.run(new PrivilegedAction<Class>() {
                public Class run() {
                    try {
                        return Class.forName(eachClassName, true, classloader);
                    } catch (ClassNotFoundException e) {
                        log.error("Cannot find class " + eachClassName, e);
                        return null;
                    }
                }
            });

            if (constraintValidatorClass != null)
                classes.add(constraintValidatorClass);

        }
        loadedConstraints.put((String) entry.getKey(), (Class[]) classes.toArray(new Class[classes.size()]));

    }
    return loadedConstraints;
}

From source file:com.liferay.portal.configuration.ConfigurationImpl.java

public Properties getProperties() {

    // For some strange reason, componentProperties.getProperties() returns
    // values with spaces after commas. So a property setting of "xyz=1,2,3"
    // actually returns "xyz=1, 2, 3". This can break applications that
    // don't expect that extra space. However, getting the property value
    // directly through componentProperties returns the correct value. This
    // method fixes the weird behavior by returing properties with the
    // correct values.

    Properties properties = new Properties();

    ComponentProperties componentProperties = getComponentProperties();

    Properties componentPropertiesProperties = componentProperties.getProperties();

    for (Map.Entry<Object, Object> entry : componentPropertiesProperties.entrySet()) {

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

        properties.setProperty(key, value);
    }//from w w w. ja  v a 2  s.co  m

    return properties;
}

From source file:org.apache.ddlutils.TestDatabaseWriterBase.java

/**
 * Initializes the test datasource and the platform.
 *//*w w w  .  java  2s.co  m*/
private void init() {
    // the data source won't change during the tests, hence
    // it is static and needs to be initialized only once
    if (_dataSource != null) {
        return;
    }

    Properties props = getTestProperties();

    try {
        String dataSourceClass = props.getProperty(DATASOURCE_PROPERTY_PREFIX + "class",
                BasicDataSource.class.getName());

        _dataSource = (DataSource) Class.forName(dataSourceClass).newInstance();

        for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            String propName = (String) entry.getKey();

            if (propName.startsWith(DATASOURCE_PROPERTY_PREFIX)
                    && !propName.equals(DATASOURCE_PROPERTY_PREFIX + "class")) {
                BeanUtils.setProperty(_dataSource, propName.substring(DATASOURCE_PROPERTY_PREFIX.length()),
                        entry.getValue());
            }
        }
    } catch (Exception ex) {
        throw new DatabaseOperationException(ex);
    }

    _databaseName = props.getProperty(DDLUTILS_PLATFORM_PROPERTY);
    if (_databaseName == null) {
        // property not set, then try to determine
        _databaseName = new PlatformUtils().determineDatabaseType(_dataSource);
        if (_databaseName == null) {
            throw new DatabaseOperationException(
                    "Could not determine platform from datasource, please specify it in the jdbc.properties via the ddlutils.platform property");
        }
    }
}

From source file:com.baidu.cc.spring.ConfigCenterPropertyPlaceholderConfigurer.java

/**
 * log out loaded properties.<br>//from  w  w w. j  a  va2  s.  co m
 * For safety consider all value will print out only include partial string.
 * example a result "key=jdbcpassword" will finally print out as "key=jdbcpa..."
 * 
 * @param props properties to log out
 */
protected void doLogLoadedProperties(Properties props) {

    Iterator<Entry<Object, Object>> iterator = props.entrySet().iterator();
    StringBuilder logContent = new StringBuilder();
    logContent.append("Loaded property list:\n");
    while (iterator.hasNext()) {
        Entry<Object, Object> next = iterator.next();
        logContent.append(next.getKey()).append("=");

        String value = String.valueOf(next.getValue());
        if (value == null) {
            logContent.append("\n");
            continue;
        }

        int length = value.length();
        if (length < 2) {
            logContent.append("...");
        } else {
            int sub = length / 2;
            logContent.append(StringUtils.substring(value, 0, sub));
            logContent.append("...");
        }

        logContent.append("\n");

    }

    LOGGER.info(logContent);
}

From source file:org.apache.falcon.oozie.process.ProcessExecutionWorkflowBuilder.java

protected void propagateEntityProperties(CONFIGURATION conf, List<String> paramList) {
    Properties entityProperties = getEntityProperties(entity);

    // Propagate user defined properties to job configuration
    final List<org.apache.falcon.oozie.workflow.CONFIGURATION.Property> configuration = conf.getProperty();

    // Propagate user defined properties to pig script as macros
    // passed as parameters -p name=value that can be accessed as $name
    for (Entry<Object, Object> entry : entityProperties.entrySet()) {
        org.apache.falcon.oozie.workflow.CONFIGURATION.Property configProperty = new org.apache.falcon.oozie.workflow.CONFIGURATION.Property();
        configProperty.setName((String) entry.getKey());
        configProperty.setValue((String) entry.getValue());
        configuration.add(configProperty);

        paramList.add(entry.getKey() + "=" + entry.getValue());
    }/*  w  w  w.  j ava  2  s.  c o m*/
}

From source file:fr.inrialpes.exmo.align.service.HTTPTransport.java

/**
 * Override this to customize the server.
 *
 * (By default, this delegates to serveFile() and allows directory listing.)
 *
 * @param uri:   Percent-decoded URI without parameters, for example "/index.cgi"
 * @param method:   "GET", "POST" etc./*from   ww  w .  ja  v  a  2s. co m*/
 * @param parms:   Parsed, percent decoded parameters from URI and, in case of POST, data.
 * @param header:   Header entries, percent decoded
 * @return an HTTP response made of these elements (see @class Response for details)
 */
public HTTPResponse serve(String uri, String method, Properties header, Properties parms) {
    logger.debug("{} '{}'", method, uri);

    // Convert parms to parameters
    Properties params = new Properties();
    for (Entry<Object, Object> e : parms.entrySet()) {
        //logger.trace( "  PRM: '{}' = '{}'", e.getKey(), e.getValue() );
        String key = (String) e.getKey();
        if (key.startsWith("paramn")) {
            params.setProperty((String) e.getValue(), parms.getProperty("paramv" + key.substring(6)));
        } else if (!key.startsWith("paramv")) {
            params.setProperty(key, (String) e.getValue());
        }
    }
    int start = 0;
    while (start < uri.length() && uri.charAt(start) == '/')
        start++;
    int end = uri.indexOf('/', start + 1);
    String oper = "";
    if (end != -1) {
        oper = uri.substring(start, end);
        start = end + 1;
    } else {
        oper = uri.substring(start);
        start = uri.length();
    }
    logger.trace("Oper: {}", oper);

    // Content negotiation first
    String accept = header.getProperty("Accept");
    returnType = HTTPResponse.MIME_HTML;
    if (accept == null)
        accept = header.getProperty("accept");
    logger.trace("Accept header: {}", accept);
    if (accept != null && !accept.equals("")) {
        int indexRXML = accept.indexOf(HTTPResponse.MIME_RDFXML);
        if (indexRXML == -1)
            indexRXML = accept.indexOf(HTTPResponse.MIME_XML);
        int indexJSON = accept.indexOf(HTTPResponse.MIME_JSON);
        if (indexRXML != -1) {
            if (indexJSON > indexRXML || indexJSON == -1) {
                returnType = HTTPResponse.MIME_RDFXML;
            } else {
                returnType = HTTPResponse.MIME_JSON;
            }
        } else if (indexJSON != -1) {
            returnType = HTTPResponse.MIME_JSON;
        }
    }
    logger.trace("Return MIME Type: {}", returnType);
    params.setProperty("returnType", returnType);

    if (oper.equals("alid")) { // Asks for an alignment by URI
        return returnAlignment(uri, returnType);
    } else if (oper.equals("onid")) { // Asks for a network by URI
        return returnNetwork(uri, returnType);
    } else if (oper.equals("")) {
        // SHOULD BE ASSIGNED TO CONTENT NEGOCIATION AS WELL... (DEFAULT IN SERVERS)
        //return serveFile( uri, header, new File("."), true );
        HTMLAServProfile profile = null;
        for (AlignmentServiceProfile serv : services) {
            if (serv instanceof HTMLAServProfile)
                profile = (HTMLAServProfile) serv;
            break;
        }
        if (profile == null)
            profile = new HTMLAServProfile();
        return new HTTPResponse(HTTPResponse.HTTP_OK, HTTPResponse.MIME_HTML, "<html><head>"
                + HTMLAServProfile.HEADER + "</head><body>" + profile.about() + "</body></html>");
    } else {
        // Selects the relevant service for the request
        for (AlignmentServiceProfile serv : services) {
            // JE2014: oper is not anymore an operation
            // It is one of: aserv. rest. wsdl. html.
            // wsdl could be served here
            // the others would be better ( man + noo + align ) / oper
            // That should be a large change
            if (serv.accept(oper)) {
                return new HTTPResponse(HTTPResponse.HTTP_OK, returnType,
                        serv.process(uri, oper, uri.substring(start), header, params));
            }
        }
        return noManager(oper);
    }
}

From source file:org.syncany.cli.CommandLineClient.java

private String replaceVariables(String line) throws IOException {
    Properties applicationProperties = Client.getApplicationProperties();

    for (Entry<Object, Object> applicationProperty : applicationProperties.entrySet()) {
        String variableName = String.format("%%%s%%", applicationProperty.getKey());

        if (line.contains(variableName)) {
            line = line.replace(variableName, (String) applicationProperty.getValue());
        }//  ww w. j av a2s  .  c  om
    }

    return line;
}

From source file:com.glaf.core.config.MutilPropertyPlaceholderConfigurer.java

@Override
protected Properties mergeProperties() throws IOException {
    Properties mergeProperties = super.mergeProperties();
    // ????properties
    this.properties = new Properties();
    // ?,mode//from   w w  w .  j a  v a  2  s  .com
    String mode = System.getProperty(RUN_MODE);
    if (StringUtils.isEmpty(mode)) {
        String str = mergeProperties.getProperty(RUN_MODE);
        mode = str != null ? str : PRODUCTION;
    }
    LOG.info("####run mode:" + mode);
    properties.put(RUN_MODE, mode);
    String[] modes = mode.split(",");
    Set<Entry<Object, Object>> es = mergeProperties.entrySet();
    for (Entry<Object, Object> entry : es) {
        String key = (String) entry.getKey();
        int idx = key.lastIndexOf('_');
        String realKey = idx == -1 ? key : key.substring(0, idx);
        if (!properties.containsKey(realKey)) {
            Object value = null;
            for (String md : modes) {
                value = mergeProperties.get(realKey + "_" + md);
                if (value != null) {
                    properties.put(realKey, value);
                    break;
                }
            }
            if (value == null) {
                value = mergeProperties.get(realKey);
                if (value != null) {
                    properties.put(realKey, value);
                }
            }
        }
    }
    logger.debug(properties);
    return properties;
}