Example usage for java.util Properties propertyNames

List of usage examples for java.util Properties propertyNames

Introduction

In this page you can find the example usage for java.util Properties propertyNames.

Prototype

public Enumeration<?> propertyNames() 

Source Link

Document

Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:Main.java

/**
 * Copy a set of properties from one Property to another.
 * /*  w  w w.  j  av  a  2s  .  c o m*/
 *
 * @param src_prop  Source set of properties to copy from.
 * @param dest_prop Dest Properties to copy into.
 *
 **/
public static void copyProperties(Properties src_prop, Properties dest_prop) {
    for (Enumeration propertyNames = src_prop.propertyNames(); propertyNames.hasMoreElements();) {
        Object key = propertyNames.nextElement();
        dest_prop.put(key, src_prop.get(key));
    }
}

From source file:io.apiman.servers.gateway_es.Starter.java

/**
 * Loads properties from a file and puts them into system properties.
 *//* w  w  w . ja  va 2s . c  o  m*/
@SuppressWarnings({ "nls", "unchecked" })
protected static void loadProperties() {
    URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties");
    if (configUrl == null) {
        throw new RuntimeException(
                "Failed to find properties file (see README.md): gateway_es-apiman.properties");
    }
    InputStream is = null;
    try {
        is = configUrl.openStream();
        Properties props = new Properties();
        props.load(is);
        Enumeration<String> names = (Enumeration<String>) props.propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String value = props.getProperty(name);
            System.setProperty(name, value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.krawler.portal.util.SystemEnv.java

public static void setProperties(Properties props) {
    Properties envProps = getProperties();

    Enumeration<String> enu = (Enumeration<String>) envProps.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();

        props.setProperty("env." + key, (String) envProps.get(key));
    }//from   w  ww  .j  a  v a 2s  .co  m
}

From source file:com.mgmtp.jfunk.core.config.ModulesLoader.java

/**
 * Loads Guice modules whose class names are specified as properties. All properties starting
 * with "module." are considered to have a fully qualified class name representing a Guice
 * module. The modules are combined and override thespecified jFunkModule.
 * /*from   ww  w  .  j  a  v a 2  s  . co m*/
 * @param propertiesFile
 *            The properties file
 * @return the combined module
 */
public static Module loadModulesFromProperties(final Module jFunkModule, final String propertiesFile)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    final List<Module> modules = Lists.newArrayList();

    LOG.debug("Using jfunk.props.file=" + propertiesFile);
    Properties props = loadProperties(propertiesFile);

    for (final Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        if (name.startsWith("module.")) {
            String className = props.getProperty(name);
            LOG.info("Loading " + name + "=" + className);
            Class<? extends Module> moduleClass = Class.forName(className).asSubclass(Module.class);
            Module module = moduleClass.newInstance();
            modules.add(module);
        }
    }
    return Modules.override(jFunkModule).with(modules);
}

From source file:Main.java

public static void mergePropertiesIntoMap(Properties props, Map map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    } else {/* w w w. java  2 s . c o  m*/
        if (props != null) {
            Enumeration en = props.propertyNames();

            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                map.put(key, props.getProperty(key));
            }
        }

    }
}

From source file:org.jboss.qa.phaser.util.XmlUtils.java

private static Element createTestsuiteElement(PhaseDefinition phaseDefinition, Throwable ex) {
    final Element elem = doc.createElement("testsuite");
    final Element propsElem = doc.createElement("properties");
    final Properties props = System.getProperties();
    if (props != null) {
        final Enumeration e = props.propertyNames();
        while (e.hasMoreElements()) {
            final String name = (String) e.nextElement();
            final Element propElement = doc.createElement("property");
            propElement.setAttribute("name", name);
            propElement.setAttribute("value", props.getProperty(name));
            propsElem.appendChild(propElement);
        }/*from   www.  j av a  2 s .  co m*/
    }
    elem.appendChild(propsElem);
    elem.setAttribute("name", phaseDefinition.getJob().getClass().toString());
    elem.setAttribute("tests", "1");
    elem.setAttribute("skipped", "0");
    elem.setAttribute("failures", "0");
    if (ex == null) {
        elem.setAttribute("errors", "0");
    } else {
        elem.setAttribute("errors", "1");
    }
    elem.appendChild(createTestCaseElement(phaseDefinition, ex));
    return elem;
}

From source file:Main.java

/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses <code>Properties.propertyNames()</code> to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be <code>null</code>)
 * @param map the target Map to merge the properties into
 *//*from w  w  w.j a va 2  s  . co m*/
@SuppressWarnings("unchecked")
public static void mergePropertiesIntoMap(Properties props, Map map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    }
    if (props != null) {
        for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            Object value = props.getProperty(key);
            if (value == null) {
                // Potentially a non-String value...
                value = props.get(key);
            }
            map.put(key, value);
        }
    }
}

From source file:com.google.enterprise.connector.otex.LivelinkConnectorFactory.java

public static LivelinkConnector getConnector(String prefix) throws RepositoryException {
    Map<String, String> p = new HashMap<String, String>();
    p.putAll(emptyProperties);/*from   w  w  w. j ava2 s  . co  m*/

    Properties system = System.getProperties();
    Enumeration<?> names = system.propertyNames();
    boolean prefixFound = false;

    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(prefix)) {
            prefixFound = true;
            LOGGER.config("PROPERTY: " + name);
            p.put(name.substring(prefix.length()), system.getProperty(name));
        }
    }

    // If there is no connector configured by this name, bail early.
    if (!prefixFound) {
        throw new RepositoryException("No javatest." + prefix + "* properties specified for connector.");
    }

    return (LivelinkConnector) instance.makeConnector(p);
}

From source file:Main.java

/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses <code>Properties.propertyNames()</code> to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be <code>null</code>)
 * @param map the target Map to merge the properties into
 *///  w w w.  jav a2 s .c om
@SuppressWarnings("unchecked")
public static void mergePropertiesIntoMap(Properties props, Map map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    }
    if (props != null) {
        for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            map.put(key, props.getProperty(key));
        }
    }
}

From source file:Main.java

/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses <code>Properties.propertyNames()</code> to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be <code>null</code>)
 * @param map the target Map to merge the properties into
 */// ww  w .j  a  v  a  2  s  .  co m
public static void mergePropertiesIntoMap(Properties props, Map<String, String> map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    }
    if (props != null) {
        for (Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            map.put(key, props.getProperty(key));
        }
    }
}