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:info.magnolia.importexport.DataTransporter.java

/**
 * Deprecated.//from  w w  w . ja v a  2  s  .  c  om
 * @param properties
 * @param repositoryName
 * @deprecated since 4.0 - use the PropertiesImportExport class instead.
 */
public static void importProperties(Properties properties, String repositoryName) {
    for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String value = (String) properties.get(key);

        String name = StringUtils.substringAfterLast(key, ".");
        String path = StringUtils.substringBeforeLast(key, ".").replace('.', '/');
        Content node = ContentUtil.getContent(repositoryName, path);
        if (node != null) {
            try {
                NodeDataUtil.getOrCreate(node, name).setValue(value);
                node.save();
            } catch (RepositoryException e) {
                log.error("can't set property " + key, e);
            }
        }
    }

}

From source file:de.hybris.platform.b2b.mock.MockitoTenant.java

private static Map<String, String> loadRawConfigFile() throws IOException {
    final Properties tempProps = new Properties();
    // 1. first, try to load the following files
    final PlatformConfig config = Utilities.getPlatformConfig();
    ConfigUtil.loadRuntimeProperties(tempProps, config);
    // 3. all system properties have the highest priority
    for (final Map.Entry entry : System.getProperties().entrySet()) {
        tempProps.put(entry.getKey(), ((String) entry.getValue()).trim());
    }//from   www.  ja v  a  2 s .c  om
    // do trimming etc.
    final Map<String, String> props = new HashMap<String, String>();
    for (final Iterator<?> it = tempProps.keySet().iterator(); it.hasNext();) {
        final String key = (String) it.next();
        String value = tempProps.getProperty(key);
        int idx = value.indexOf('#');
        if (idx > 0) {
            if (value.charAt(idx - 1) == ('\\')) {
                idx = -1; // wenn escaped, dann nicht!
            }
        }
        if (idx > 0) {
            value = value.substring(0, idx);
        }
        value = value.trim();
        value = value.replace("\\#", "#");
        value = value.replace("{tab}", "\t");
        // if( value!=null && value.length()>1) value=value.trim();
        // value = Config.trim( value, "\t".toCharArray() );
        props.put(key, value);
    }
    return props;
}

From source file:de.dal33t.powerfolder.util.ConfigurationLoader.java

/**
 * Merges the give pre configuration properties into the target config
 * properties. It can be choosen if existing keys in the target properties
 * should be replaced or not.//from   w w w.  ja va 2  s  .  c o  m
 *
 * @param preConfig
 *            the pre config
 * @param targetConfig
 *            the config file to set the pre-configuration values into.
 * @param replaceExisting
 *            if existing key/value pairs will be overwritten by pairs of
 *            pre config.
 * @return the number of merged entries.
 */
private static int mergeConfigs(Properties preConfig, Properties targetConfig, boolean replaceExisting) {
    Reject.ifNull(preConfig, "PreConfig is null");
    Reject.ifNull(targetConfig, "TargetConfig is null");
    int n = 0;
    for (Object obj : preConfig.keySet()) {
        String key = (String) obj;
        String value = preConfig.getProperty(key);
        if (!targetConfig.containsKey(key) || replaceExisting) {
            Object oldValue = targetConfig.setProperty(key, value);
            if (!key.startsWith(PREFERENCES_PREFIX) && !value.equals(oldValue)) {
                n++;
            }
            LOG.finer("Preconfigured " + key + "=" + value);
        }
    }
    if (n > 0) {
        LOG.fine(n + " default configurations set");
    } else {
        LOG.finer("No additional default configurations set");
    }
    return n;
}

From source file:de.dal33t.powerfolder.util.ConfigurationLoader.java

/**
 * PUBLIC because of tests. DO NOT USE. Use
 * {@link #merge(Properties, Properties, Preferences, boolean)} instead.
 * <p>//  www. j a  v  a2 s  .c o  m
 * Merges the give pre configuration properties into the target preferences.
 * It can be choosen if existing keys in the target preferences should be
 * replaced or not. Will only set those values from preConfig where the key
 * begins with "pref." and cut it off. "pref.xxx=true" will be set to
 * "xxx=true" in preferences.
 *
 * @param preConfig
 *            the pre config
 * @param targetPreferences
 *            the preferences to set the pre-configuration values into.
 * @param replaceExisting
 *            if existing key/value pairs will be overwritten by pairs of
 *            pre config.
 * @return the number of merged entries.
 */
public static int mergePreferences(Properties preConfig, Preferences targetPreferences,
        boolean replaceExisting) {
    Reject.ifNull(preConfig, "PreConfig is null");
    Reject.ifNull(targetPreferences, "TargetPreferences is null");
    int n = 0;
    for (Object obj : preConfig.keySet()) {
        String key = (String) obj;
        String value = preConfig.getProperty(key);
        if (!key.startsWith(PREFERENCES_PREFIX)) {
            continue;
        } else {
            key = key.substring(PREFERENCES_PREFIX.length(), key.length());
        }
        boolean entryMissing = "-XXWEIRED-DEFAULT-VALUE"
                .equals(targetPreferences.get(key, "-XXWEIRED-DEFAULT-VALUE"));
        if (entryMissing || replaceExisting) {
            targetPreferences.put(key, value);
            n++;
            LOG.finer("Preconfigured " + key + "=" + value);
        }
    }
    if (n > 0) {
        LOG.fine(n + " default preferences set");
    } else {
        LOG.finer("No additional default preferences set");
    }
    return n;
}

From source file:com.microsoft.tfs.core.util.CodePageMapping.java

private static String[] getSystemPropertyKeys(final String keyPrefix) {
    final List<String> propertyKeyList = new ArrayList<String>();
    final Properties systemProperties = System.getProperties();

    for (final Iterator<Object> i = systemProperties.keySet().iterator(); i.hasNext();) {
        final String key = (String) i.next();

        if (key.startsWith(keyPrefix + ".")) //$NON-NLS-1$
        {/*from  w  w w.java  2  s. c  om*/
            final String keyConfigurationPart = key.substring(keyPrefix.length() + 2);
            propertyKeyList.add(keyConfigurationPart);
        }
    }

    return propertyKeyList.toArray(new String[propertyKeyList.size()]);
}

From source file:com.leclercb.taskunifier.gui.main.Main.java

private static void loadLookAndFeel() throws Exception {
    // jGoodies//from   w  w  w  .j  av  a  2 s.c  o m
    Properties jgoodies = new Properties();
    jgoodies.load(Resources.class.getResourceAsStream("themes_jgoodies.properties"));

    for (Object key : jgoodies.keySet()) {
        LookAndFeelUtils.addLookAndFeel(new DefaultLookAndFeelDescriptor(
                "jGoodies - " + jgoodies.getProperty(key.toString()), key.toString()));
    }

    // jTattoo
    Properties jtattoo = new Properties();
    jtattoo.load(Resources.class.getResourceAsStream("themes_jtattoo.properties"));

    for (Object key : jtattoo.keySet()) {
        LookAndFeelUtils.addLookAndFeel(new JTattooLookAndFeelDescriptor(
                "jTattoo - " + jtattoo.getProperty(key.toString()), key.toString()));
    }
}

From source file:com.whizzosoftware.hobson.rest.v1.JSONMarshaller.java

public static JSONObject createTaskJSON(HobsonRestContext ctx, HobsonTask task, boolean details,
        boolean properties) {
    JSONObject json = new JSONObject();
    json.put("name", task.getName());
    json.put("type", task.getType().toString());
    JSONObject links = new JSONObject();
    links.put("self", ctx.getApiRoot() + new Template(TaskResource.PATH)
            .format(createDoubleEntryMap(ctx, "providerId", task.getProviderId(), "taskId", task.getId())));
    json.put("links", links);

    if (details) {
        json.put("provider", task.getProviderId());
        json.put("conditions", task.getConditions());
        json.put("actions", task.getActions());
    }/*from  w ww .  ja va2s  . c  o m*/

    if (properties) {
        Properties p = task.getProperties();
        if (p != null && p.size() > 0) {
            JSONObject props = new JSONObject();
            for (Object o : p.keySet()) {
                String key = o.toString();
                props.put(o.toString(), p.get(key));
            }
            json.put("properties", props);
        }
    }

    return json;
}

From source file:de.xwic.sandbox.base.model.util.ConfigurationUtil.java

/**
 *
 *///  ww w .  ja va  2  s . co m
public static void reloadConfiguration() {
    // load product configuration
    File path = new File(SandboxModelConfig.getWebRootDirectory(), "config");
    Setup setup;
    try {
        setup = XmlConfigLoader.loadSetup(path.toURI().toURL());
    } catch (Exception e) {
        log.error("Error loading product configuration", e);
        throw new RuntimeException("Error loading product configuration: " + e, e);
    }

    // merge server specific settings
    InputStream in = null;
    Properties srvProp = new Properties();
    try {
        File serverPropertiesFile = new File(SandboxModelConfig.getWebRootDirectory(),
                "WEB-INF/server.properties");
        if (!serverPropertiesFile.exists()) {
            throw new RuntimeException("server.properties not found.");
        }
        in = new FileInputStream(serverPropertiesFile);
        if (in != null) {
            srvProp.load(in);
            for (Object prop : srvProp.keySet()) {
                String key = (String) prop;
                setup.setProperty(key, srvProp.getProperty(key));
            }
        }
    } catch (Exception e) {
        log.error("Error loading Server properties", e);
        throw new RuntimeException("Error loading Server properties", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (final IOException e) {
                log.error("Failed to close the input stream!", e);
            }
        }
    }

    ConfigurationManager.setSetup(setup);
    log.info("Configuration loaded: " + setup.getAppTitle() + " version " + setup.getVersion());
}

From source file:disko.DU.java

public static void loadSystemProperties(File discoPropertiesFile) {
    if (discoPropertiesFile.exists()) {
        FileInputStream in = null;
        try {/* w  ww.j a  v a 2 s . c  o  m*/
            in = new FileInputStream(discoPropertiesFile);
            Properties props = new Properties();
            props.load(in);
            System.getProperties().putAll(props);
            System.out.println("Disco Properties [" + discoPropertiesFile.getAbsolutePath() + "]:");
            System.out.println("==============================================");
            for (Object name : props.keySet())
                System.out.println(name + "=" + props.getProperty((String) name));
            System.out.println("==============================================");
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (Throwable t) {
            }
        }
    }
}

From source file:mas.MAS.java

private static String generateURL(String url_org, Properties prop) {
    String url = url_org + "?";
    for (Object k : prop.keySet()) {
        String key = (String) k;
        String val = prop.getProperty(key);
        url = url + key + "=" + val + "&";
    }//from ww  w  .j  ava 2  s .  c  o m
    return url.substring(0, url.length() - 1);
}