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.springweb.core.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 2s  . co  m
    String mode = System.getProperty(PRODUCTION_MODE);
    if (StringUtils.isEmpty(mode)) {
        String str = mergeProperties.getProperty(PRODUCTION_MODE);
        mode = str != null ? str : "ONLINE";
    }
    properties.put(PRODUCTION_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);
                } else {
                    throw new RuntimeException("impossible empty property for " + realKey);
                }
            }
        }
    }
    return properties;
}

From source file:org.apache.cassandra.locator.PropertyFileSnitch.java

public void reloadConfiguration(boolean isUpdate) throws ConfigurationException {
    HashMap<InetAddress, String[]> reloadedMap = new HashMap<>();
    String[] reloadedDefaultDCRack = null;

    Properties properties = new Properties();
    try (InputStream stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME)) {
        properties.load(stream);/*from   w  w w.j a  va 2  s. co m*/
    } catch (Exception e) {
        throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
    }

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        if ("default".equals(key)) {
            String[] newDefault = value.split(":");
            if (newDefault.length < 2)
                reloadedDefaultDCRack = new String[] { "default", "default" };
            else
                reloadedDefaultDCRack = new String[] { newDefault[0].trim(), newDefault[1].trim() };
        } else {
            InetAddress host;
            String hostString = StringUtils.remove(key, '/');
            try {
                host = InetAddress.getByName(hostString);
            } catch (UnknownHostException e) {
                throw new ConfigurationException("Unknown host " + hostString, e);
            }
            String[] token = value.split(":");
            if (token.length < 2)
                token = new String[] { "default", "default" };
            else
                token = new String[] { token[0].trim(), token[1].trim() };
            reloadedMap.put(host, token);
        }
    }
    if (reloadedDefaultDCRack == null && !reloadedMap.containsKey(FBUtilities.getBroadcastAddress()))
        throw new ConfigurationException(String.format(
                "Snitch definitions at %s do not define a location for "
                        + "this node's broadcast address %s, nor does it provides a default",
                SNITCH_PROPERTIES_FILENAME, FBUtilities.getBroadcastAddress()));

    if (isUpdate && !livenessCheck(reloadedMap, reloadedDefaultDCRack))
        return;

    if (logger.isTraceEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<InetAddress, String[]> entry : reloadedMap.entrySet())
            sb.append(entry.getKey()).append(':').append(Arrays.toString(entry.getValue())).append(", ");
        logger.trace("Loaded network topology from property file: {}",
                StringUtils.removeEnd(sb.toString(), ", "));
    }

    defaultDCRack = reloadedDefaultDCRack;
    endpointMap = reloadedMap;
    if (StorageService.instance != null) // null check tolerates circular dependency; see CASSANDRA-4145
    {
        if (isUpdate)
            StorageService.instance.updateTopology();
        else
            StorageService.instance.getTokenMetadata().invalidateCachedRings();
    }

    if (gossipStarted)
        StorageService.instance.gossipSnitchInfo();
}

From source file:org.xdi.oxauth.BaseTest.java

@BeforeSuite
public void initTestSuite(ITestContext context) throws FileNotFoundException, IOException {
    SecurityProviderUtility.installBCProvider();

    Reporter.log("Invoked init test suite method \n", true);

    String propertiesFile = context.getCurrentXmlTest().getParameter("propertiesFile");
    if (StringHelper.isEmpty(propertiesFile)) {
        propertiesFile = "target/test-classes/testng.properties";
    }/*from  w  ww. j ava 2s  . c o m*/

    // Load test paramters
    //propertiesFile = "/Users/JAVIER/IdeaProjects/oxAuth/Client/target/test-classes/testng.properties";
    FileInputStream conf = new FileInputStream(propertiesFile);
    Properties prop = new Properties();
    prop.load(conf);

    Map<String, String> parameters = new HashMap<String, String>();
    for (Entry<Object, Object> entry : prop.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();

        if (StringHelper.isEmptyString(key) || StringHelper.isEmptyString(value)) {
            continue;
        }
        parameters.put(key.toString(), value.toString());
    }

    // Overrided test paramters
    context.getSuite().getXmlSuite().setParameters(parameters);
}

From source file:net.firejack.platform.model.config.hibernate.HibernateFactoryBean.java

private void findDatabase() {
    List<String> xaDomains = new ArrayList<String>();

    String xa = ConfigContainer.get("xa");
    if (StringUtils.isNotBlank(xa)) {
        Collections.addAll(xaDomains, xa.split(";"));
    }//  w w w  . ja va2s .  c o m

    Properties properties = ConfigContainer.getProperties();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        String[] strings = key.split("\\.");
        if (strings.length == 3 && strings[0].equals("db")) {
            Database database = databases.get(strings[1]);
            if (database == null) {
                database = new Database();
                databases.put(strings[1], database);
            }
            if (strings[2].equals("type")) {
                database.setType(DatabaseName.valueOf(value));
            } else if (strings[2].equals("domains")) {
                List<String> domains = Arrays.asList(value.split(";"));
                database.setDomains(domains);
                for (String domain : domains) {
                    if (domain.split("\\.").length == 3)
                        database.setRoot(true);
                }
            } else if (strings[2].equals("url")) {
                database.setUrl(value);
            } else if (strings[2].equals("username")) {
                database.setUsername(value);
            } else if (strings[2].equals("password")) {
                database.setPassword(value);
            }
        }
    }

    Map<String, HibernateSupport> stories = context.getBeansOfType(HibernateSupport.class);

    for (Database database : databases.values()) {
        if (database.isRoot())
            database.setStores(stories.values());
        for (Iterator<Map.Entry<String, HibernateSupport>> iterator = stories.entrySet().iterator(); iterator
                .hasNext();) {
            Map.Entry<String, HibernateSupport> supportEntry = iterator.next();
            HibernateSupport support = supportEntry.getValue();
            if (database.addStore(support)) {
                iterator.remove();
            }
        }
    }

    if (xaDomains.size() > 1) {
        for (Iterator<Map.Entry<String, Database>> iterator = databases.entrySet().iterator(); iterator
                .hasNext();) {
            Map.Entry<String, Database> entry = iterator.next();
            List<String> domains = new ArrayList<String>(entry.getValue().getDomains());

            for (Iterator<String> stringIterator = domains.iterator(); stringIterator.hasNext();) {
                if (xaDomains.contains(stringIterator.next())) {
                    xaDatabases.put(entry.getKey(), entry.getValue());
                    stringIterator.remove();
                }
            }

            if (domains.isEmpty())
                iterator.remove();
        }
    }
}

From source file:alluxio.shell.command.MountCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI alluxioPath = new AlluxioURI(args[0]);
    AlluxioURI ufsPath = new AlluxioURI(args[1]);
    MountOptions options = MountOptions.defaults();

    String propertyFile = cl.getOptionValue('P');
    if (propertyFile != null) {
        Properties cmdProps = new Properties();
        try (InputStream inStream = new FileInputStream(propertyFile)) {
            cmdProps.load(inStream);//from ww w.  ja va 2 s.  c om
        } catch (IOException e) {
            throw new IOException("Unable to load property file: " + propertyFile);
        }

        if (!cmdProps.isEmpty()) {
            // Use the properties from the properties file for the mount options.
            Map<String, String> properties = new HashMap<>();
            for (Map.Entry<Object, Object> entry : cmdProps.entrySet()) {
                properties.put(entry.getKey().toString(), entry.getValue().toString());
            }
            options.setProperties(properties);
            System.out.println("Using properties from file: " + propertyFile);
        }
    }

    if (cl.hasOption("readonly")) {
        options.setReadOnly(true);
    }

    if (cl.hasOption("shared")) {
        options.setShared(true);
    }

    mFileSystem.mount(alluxioPath, ufsPath, options);
    System.out.println("Mounted " + ufsPath + " at " + alluxioPath);
    return 0;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createEnvElement(final Element runtime) {
    final Element parent = document.createElement("env");

    final Properties sorted = SortedProperties.createSorted(buildMetaDataProperties);
    final String matchPrefix = Constant.MAVEN_EXECUTION_PROPERTIES_PREFIX + '.';
    for (final Map.Entry<Object, Object> entry : sorted.entrySet()) {
        final String key = String.valueOf(entry.getKey());
        if (key.startsWith(matchPrefix)) {
            final String value = String.valueOf(entry.getValue());
            final Element env = createValueElement("var", value, parent);
            if (env != null) {
                env.setAttribute(GI_NAME, key);
            }//from   w w w .  j  av a2  s . co m
        }
    }

    if (parent.hasChildNodes()) {
        runtime.appendChild(parent);
    }
}

From source file:com.halseyburgund.rwframework.core.RWHttpManager.java

public static String uploadFile(String page, Properties properties, String fileParam, String file,
        int timeOutSec) throws Exception {
    if (D) {//w  w  w  .  ja  v  a2 s.  co  m
        Log.d(TAG, "Starting upload of file: " + file, null);
    }

    // build GET-like page name that includes the RW operation
    Enumeration<Object> enumProps = properties.keys();
    StringBuilder uriBuilder = new StringBuilder(page).append('?');
    while (enumProps.hasMoreElements()) {
        String key = enumProps.nextElement().toString();
        String value = properties.get(key).toString();
        if ("operation".equals(key)) {
            uriBuilder.append(key);
            uriBuilder.append('=');
            uriBuilder.append(java.net.URLEncoder.encode(value));
            break;
        }
    }

    if (D) {
        Log.d(TAG, "GET request: " + uriBuilder.toString(), null);
    }

    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000);

    HttpClient httpClient = new DefaultHttpClient(httpParams);
    HttpPost request = new HttpPost(uriBuilder.toString());
    RWMultipartEntity entity = new RWMultipartEntity();

    Iterator<Map.Entry<Object, Object>> i = properties.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) i.next();
        String key = (String) entry.getKey();
        String val = (String) entry.getValue();
        entity.addPart(key, val);
        if (D) {
            Log.d(TAG, "Added StringBody multipart for: '" + key + "' = '" + val + "'", null);
        }
    }

    File upload = new File(file);
    entity.addPart(fileParam, upload);
    if (D) {
        String msg = "Added FileBody multipart for: '" + fileParam + "' =" + " <'" + upload.getAbsolutePath()
                + ", " + "size: " + upload.length() + " bytes >'";
        Log.d(TAG, msg, null);
    }

    request.setEntity(entity);

    if (D) {
        Log.d(TAG, "Sending HTTP request...", null);
    }

    HttpResponse response = httpClient.execute(request);

    int st = response.getStatusLine().getStatusCode();

    if (st == HttpStatus.SC_OK) {
        StringBuffer sbResponse = new StringBuffer();
        InputStream content = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        while ((line = reader.readLine()) != null) {
            sbResponse.append(line);
        }
        content.close(); // this will also close the connection

        if (D) {
            Log.d(TAG, "Upload successful (HTTP code: " + st + ")", null);
            Log.d(TAG, "Server response: " + sbResponse.toString(), null);
        }

        return sbResponse.toString();
    } else {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        entity.writeTo(ostream);
        Log.e(TAG, "Upload failed (http code: " + st + ")", null);
        Log.e(TAG, "Server response: " + ostream.toString(), null);
        throw new HttpException(String.valueOf(st));
    }
}

From source file:org.gvnix.service.roo.addon.addon.ws.importt.WSImportOperationsImpl.java

/**
 * Compares the values of two Property instances
 * /*from  w  w w.  j  a v a2  s.com*/
 * @param one
 * @param other
 * @return
 */
private boolean propertiesEquals(Properties one, Properties other) {
    if (one.size() != other.size()) {
        return false;
    }
    Set<Entry<Object, Object>> entrySet = one.entrySet();
    Object otherValue;
    for (Entry<Object, Object> entry : entrySet) {
        otherValue = other.get(entry.getKey());
        if (otherValue == null) {
            if (entry.getValue() != null) {
                return false;
            }
        } else if (!otherValue.equals(entry.getValue())) {
            return false;
        }
    }
    return true;
}

From source file:com.zotoh.cloudapi.aws.AWSAPI.java

@Override
public void setProperties(String hint, JSONObject target, Properties props) throws JSONException {

    if ("endpoint".equals(hint)) {
        for (Map.Entry<Object, Object> en : props.entrySet()) {
            target.put("aws.endpoint." + nsb(en.getKey()), nsb(en.getValue()));
        }/*from   w  w  w.j  a  v a  2  s .c  om*/
    }

}