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:com.halseyburgund.rwframework.core.RWHttpManager.java

public static String doPost(String page, Properties props, int timeOutSec) throws Exception {
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000);

    HttpClient httpClient = new DefaultHttpClient(httpParams);

    HttpPost request = new HttpPost(page);
    HttpResponse response = null;//from www  .j  a va 2 s . c  om
    HttpEntity entity = null;

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    while (enumProps.hasMoreElements()) {
        key = (String) enumProps.nextElement();
        value = (String) props.get(key);
        nvps.add(new BasicNameValuePair(key, value));
    }

    UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
    request.setEntity(uf);
    request.setHeader("Content-Type", POST_MIME_TYPE);

    // Post, check and show the result (not really spectacular, but works):
    response = httpClient.execute(request);
    entity = response.getEntity();

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

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        entity.writeTo(ostream);

        Log.e(TAG, "Error status code = " + status, null);
        Log.e(TAG, ostream.toString(), null);
        throw new HttpException(String.valueOf(status));
    } else {
        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

        return sbResponse.toString();
    }
}

From source file:org.globus.gatekeeper.jobmanager.AbstractJobManager.java

public static void setGlobusProperties(Map map) {
    String key = null;//  w  ww.  j  a  v a 2  s. co m
    Properties props = System.getProperties();
    Enumeration e = props.keys();
    while (e.hasMoreElements()) {
        key = (String) e.nextElement();
        if (key.regionMatches(true, 0, "GLOBUS", 0, 6)) {
            map.put(key, props.getProperty(key));
        }
    }
}

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

public static String encodeJson(Properties props) {
    JSONObject jsonObject = new JSONObject();
    Enumeration<?> e = props.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = props.getProperty(key);
        jsonObject.put(key, value);//from ww  w.j av  a2s  .  com
    }
    String content = jsonObject.toJSONString();
    String key = SystemProperties.getDefaultSecurityKey();
    content = SecurityUtils.encode(key, content);
    return content;
}

From source file:it.txt.access.capability.revocation.test.RevocationServiceTest.java

@SuppressWarnings("rawtypes")
private static void setConfigurationData(String path) {
    try {//from  w w w .  ja  v a2  s  .c  o  m
        // Build a properties file for student.
        File file = new File(path);
        file.createNewFile();
        Properties properties = new Properties();
        properties.load(new FileInputStream(file));
        Enumeration e = properties.keys();
        while (e.hasMoreElements()) {
            Object obj = e.nextElement();
            System.setProperty(obj.toString(), properties.getProperty(obj.toString()));
        }

    } catch (IOException ex) {
        System.out.println(ex.toString());
    }

}

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

public static Properties getTemplateProperties(String name) {
    if (name == null) {
        return null;
    }/*  w w  w.j av  a2  s.c  om*/
    if (jdbcTemplateProperties.isEmpty()) {
        init();
    }
    logger.debug("name:" + name);
    Properties props = jdbcTemplateProperties.get(name);
    Properties p = new Properties();
    Enumeration<?> e = props.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = props.getProperty(key);
        p.put(key, value);
    }
    return p;
}

From source file:org.conf4j.service.ConfServiceInstance.java

private static final void initFile(ESource source, ConfValueMap conf, String settingKey, ConfValue filePath)
        throws ConfServiceException {
    if (filePath == null)
        return;/*  ww w . j  a  va  2  s  .c o  m*/
    final Properties properties = new Properties();
    try {
        final ConfValueEvaluator evaluator = new ConfValueEvaluator(false);
        final InputStream is = new FileInputStream(
                MacroProcessor.replaceProperties(filePath.getValue(false), conf, settingKey, evaluator));
        try {
            properties.load(is);
        } finally {
            is.close();
        }
    } catch (IOException e) {
        // do nothing
    } catch (MacroParsingException e) {
        throw new ConfServiceException(e.getMessage(), e);
    }
    final Enumeration<?> e = properties.keys();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        final String value = properties.getProperty(name);
        name = normalise(name, source, value);
        if (!isConfigElement(name))
            throw new ConfServiceException(
                    VARIABLE_0_NOT_DECLARED_AS_CONFELEMENTS_MEMBER.format(new String[] { name }));
        conf.put(name, value, source);
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.EncodingComboBoxModel.java

public static EncodingComboBoxModel createDefaultModel(final Locale locale, boolean includeNull) {
    final EncodingComboBoxModel ecb = new EncodingComboBoxModel(locale);
    if (includeNull) {
        ecb.addEncodingUnchecked(null, "");
    }// www . j  a  va2s.  co m
    final String availEncs = getAvailableEncodings();
    final boolean allEncodings = availEncs.equalsIgnoreCase(AVAILABLE_ENCODINGS_ALL);

    if (allEncodings || availEncs.equals(AVAILABLE_ENCODINGS_FILE)) {
        final String encFile = getEncodingsDefinitionFile();
        final InputStream in = ObjectUtilities.getResourceAsStream(encFile, EncodingComboBoxModel.class);
        if (in == null) {
            final Messages messages = new Messages(locale, SwingCommonModule.BUNDLE_NAME,
                    ObjectUtilities.getClassLoader(SwingCommonModule.class));
            logger.warn(messages.getString("EncodingComboBoxModel.WARN_ENCODING_FILE_NOT_FOUND", encFile)); //$NON-NLS-1$
        } else {
            try {
                // final Properties defaultEncodings = getDefaultEncodings();
                final Properties encDef = new Properties();
                final BufferedInputStream bin = new BufferedInputStream(in);
                try {
                    encDef.load(bin);
                } finally {
                    bin.close();
                }
                final Enumeration en = encDef.keys();
                while (en.hasMoreElements()) {
                    final String enc = (String) en.nextElement();
                    // if not set to "true"
                    if ("true".equalsIgnoreCase(encDef.getProperty(enc, "false"))) { //$NON-NLS-1$ //$NON-NLS-2$
                        // if the encoding is disabled ...
                        ecb.addEncoding(enc, ecb.getEncodingDescription(enc));
                    }
                }
            } catch (IOException e) {
                final Messages messages = new Messages(locale, SwingCommonModule.BUNDLE_NAME,
                        ObjectUtilities.getClassLoader(SwingCommonModule.class));
                logger.warn(
                        messages.getString("EncodingComboBoxModel.WARN_ERROR_READING_ENCODING_FILE") + encFile, //$NON-NLS-1$
                        e);
            }
        }
    }
    return ecb;
}

From source file:org.apache.pig.impl.util.Utils.java

/**
 * Method to apply pig properties to JobConf (replaces properties with
 * resulting jobConf values)./*from   w w w  .j a v  a2  s .  c  o m*/
 *
 * @param conf JobConf with appropriate hadoop resource files
 * @param properties Pig properties that will override hadoop properties;
 * properties might be modified
 */
public static void recomputeProperties(JobConf jobConf, Properties properties) {
    // We need to load the properties from the hadoop configuration
    // We want to override these with any existing properties we have.
    if (jobConf != null && properties != null) {
        // set user properties on the jobConf to ensure that defaults
        // and deprecation is applied correctly
        Enumeration<Object> propertiesIter = properties.keys();
        while (propertiesIter.hasMoreElements()) {
            String key = (String) propertiesIter.nextElement();
            String val = properties.getProperty(key);
            // We do not put user.name, See PIG-1419
            if (!key.equals("user.name")) {
                jobConf.set(key, val);
            }
        }
        // clear user defined properties and re-populate
        properties.clear();
        Iterator<Map.Entry<String, String>> iter = jobConf.iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> entry = iter.next();
            properties.put(entry.getKey(), entry.getValue());
        }
    }
}

From source file:org.alfresco.config.AlfrescoPropertiesPersister.java

private void strip(Properties props) {
    for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();) {
        String key = (String) keys.nextElement();
        String val = StringUtils.trimTrailingWhitespace(props.getProperty(key));
        if (logger.isTraceEnabled()) {
            logger.trace("Trimmed trailing whitespace for property " + key + " = " + val);
        }/*from   ww w . j  a  v a2  s  . co m*/
        props.setProperty(key, val);
    }
}

From source file:org.alfresco.reporting.processor.PropertyProcessor.java

public static void propertyLogger(final String description, final Properties p) {
    if (logger.isDebugEnabled())
        logger.debug("PropertyLogger: " + description);
    Enumeration<Object> keys = p.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = p.getProperty(key, "-");
        if (logger.isDebugEnabled())
            logger.debug("  entry: " + key + "=" + value);
    }//from w  w w . ja  v a 2s .com
}