Example usage for java.util Properties keys

List of usage examples for java.util Properties keys

Introduction

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

Prototype

@Override
    public Enumeration<Object> keys() 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle resource = ResourceBundle.getBundle("Messages", Locale.UK);

    Properties properties = convertResourceBundleToProperties(resource);

    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = (String) properties.get(key);
        System.out.println(key + " = " + value);
    }/*from  www. j  ava2  s  . c  o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties config = new Properties();
    config.load(new FileInputStream("conf-file.pros"));

    Enumeration en = config.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        System.out.println(key + ":" + config.get(key));
    }/*  w ww. j a v a  2s.c  o  m*/
}

From source file:Main.java

/**
 * Copies all elements from <code>properties</code> into the given <code>result</code>.
 * @param properties/*w  w  w .j  a  v a2  s.  c  o  m*/
 * @param result
 */
public static void putAll(Properties properties, Map<String, String> result) {
    for (Enumeration<Object> keys = properties.keys(); keys.hasMoreElements();) {
        String key = (String) keys.nextElement();
        result.put(key, properties.getProperty(key));
    }
}

From source file:Main.java

/**
 * Fix properties keys./*from w  ww  .  j  av a2 s .  c o  m*/
 *
 * @param prop
 *            the prop
 */
public static void fixPropertiesKeys(final Properties prop) {
    final Enumeration<Object> keys = prop.keys();
    while (keys.hasMoreElements()) {
        final String currentKey = (String) keys.nextElement();
        final String fixedKey = fixPropertyKey(currentKey);
        final String value = prop.getProperty(currentKey);
        prop.remove(currentKey);
        prop.setProperty(fixedKey, value);
    }
}

From source file:Main.java

public static Transformer setStdTransParamsProps(final Transformer renderer, final Properties params) {
    if (params != null) {
        for (Enumeration<Object> e = params.keys(); e.hasMoreElements();) {

            String localkey = (String) e.nextElement();
            String val = params.getProperty(localkey);
            renderer.setParameter(localkey, val);
        }// w  ww. j  ava2s . c om
    }
    return renderer;
}

From source file:Main.java

public static void saveAttributesToNode(Node node, Properties props) {
    Document doc = node.getOwnerDocument();
    Element elem;// www. ja  va  2  s. com
    Enumeration keys = props.keys();
    Enumeration elems = props.elements();
    while (keys.hasMoreElements()) {
        String s;
        s = keys.nextElement().toString() + "=" + elems.nextElement().toString();
        addTextTag(node, TAG_ATTR, s);
    }

}

From source file:org.sonar.application.ConfigurationUtils.java

static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
    Properties result = new Properties();
    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = (String) properties.get(key);
        String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}");
        result.setProperty(key, interpolatedValue);
    }/*from www.  jav  a  2s  .co m*/
    return result;
}

From source file:Main.java

/**
 * Converts a Properties object into a Map.
 * /*w  ww.jav  a 2 s  .c  o m*/
 * @param properties
 *            set of string key-value pairs
 * @returns map of key-value pairs (never null)
 */
public static Map<String, String> getMapFromProperties(Properties props) {
    Map<String, String> map = new HashMap<String, String>();

    if (props != null) {
        Enumeration<Object> e = props.keys();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            map.put(s, props.getProperty(s));
        }
    }

    return map;
}

From source file:Main.java

/**
 * All the standard parameters must be set in the properties file
 * //from  w  w  w  .j a va  2 s. c o  m
 * @param renderer
 * @param params
 * @return
 */
public static Transformer setStdTransParamsProps(Transformer renderer, Properties params) {

    // log.severe("setStdTransParamsProps params = "+params);

    if (params != null) {
        for (Enumeration e = params.keys(); e.hasMoreElements();) {

            String localkey = (String) e.nextElement();
            String val = params.getProperty(localkey);
            renderer.setParameter(localkey, val);
        }
    }
    return renderer;
}

From source file:org.apache.ojb.broker.util.XmlHelper.java

/**
 * Appends an XML-string with serialized configuration attributes to the specified buffer.
 * Used when serializing {@link org.apache.ojb.broker.metadata.AttributeContainer} attributes.
 * @param buf the string buffer to append to
 * @param prefix the line prefix (ie indent) or null for no prefix
 * @param attributeProperties the properties object holding attributes to be serialized
 * (null-safe)/*from  w w w .  j av a 2s.co m*/
 */
public static void appendSerializedAttributes(final StringBuffer buf, final String prefix,
        final Properties attributeProperties) {
    if (attributeProperties != null) {
        final Enumeration keys = attributeProperties.keys();
        while (keys.hasMoreElements()) {
            final String key = (String) keys.nextElement();
            final String value = attributeProperties.getProperty(key);
            if (prefix != null) {
                buf.append(prefix);
            }
            buf.append("<attribute attribute-name=\"").append(key);
            buf.append("\" attribute-value=\"").append(value);
            buf.append("\"/>");
            buf.append(XML_EOL);
        }
    }
}