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:org.jzkit.a2j.codec.util.OIDRegConfigurator.java

public static void load(OIDRegister reg, String config_file_name) {

    InputStream is = null;/*w ww.ja v a  2  s . c o  m*/
    InputStream defaults_is = null;
    Properties p = null;

    // OIDRegister reg = OIDRegister.getRegister();

    try {
        // read from top of any classpath entry
        is = OIDRegConfigurator.class.getResourceAsStream(config_file_name);
        p = new Properties();

        if (is != null) {
            p.load(is);
        }

        for (Enumeration en = p.keys(); en.hasMoreElements();) {
            String key = (String) en.nextElement();

            try {
                String oid_name = key.substring(key.indexOf('.'), key.length());

                // Every entry in the file must have an OID
                if (key.startsWith("oid")) {
                    String oid_string = p.getProperty("oid" + oid_name);
                    String entry_name = p.getProperty("name" + oid_name);
                    String codec_name = p.getProperty("codec" + oid_name);
                    Object the_codec = null;

                    log.debug("processing " + oid_string + "," + entry_name + "," + codec_name);

                    try {
                        if (codec_name != null) {
                            Class codec_class = Class.forName(codec_name);
                            Method get_codec_method = codec_class.getMethod("getCodec", null);
                            the_codec = get_codec_method.invoke(null, null);
                        }
                    } catch (java.lang.ClassNotFoundException cnfe) {
                        log.error("Unable to find codec class : " + codec_name);
                    }

                    reg.register_oid(new OIDRegisterEntry(oid_name.substring(1, oid_name.length()), oid_string,
                            entry_name, the_codec));
                }
            } catch (StringIndexOutOfBoundsException sbe) {
                log.error("Problem loading register", sbe);
            } catch (Exception e) {
                log.error("Problem loading register", e);
            }
        }
    } catch (Exception e) {
        log.error("Problem loading register", e);
    }
}

From source file:org.messic.service.MessicMain.java

/**
 * Get the Felix configuration based on the config.properties stored at ./felix/conf folder
 * /*from ww  w  .jav a2 s  .c o  m*/
 * @return Map<String,String/> configuration properties
 */
private static Map<String, String> getFelixConfig() {
    Map<String, String> config = new HashMap<String, String>();
    // config.put("org.osgi.framework.bootdelegation", "sun.*,com.sun.*");
    Properties p = new Properties();
    try {
        p.load(new FileInputStream(new File("./felix/conf/config.properties")));
        Enumeration<Object> keys = p.keys();
        while (keys.hasMoreElements()) {
            String key = "" + keys.nextElement();
            String value = p.getProperty(key);
            config.put(key, value);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return config;
}

From source file:org.squale.welcom.struts.plugin.Welcom.java

/**
 * Ecrit la config de la JVM//from w ww. java2  s.  c  o m
 */
public static void dumpConfigJVM() {

    if (Util.isTrue(WelcomConfigurator.getMessage(WelcomConfigurator.DEBUG_CONFIG_JVM))) {
        final Properties p = System.getProperties();
        final Enumeration enumeration = p.keys();

        while (enumeration.hasMoreElements()) {
            final String key = (String) enumeration.nextElement();
            logStartup.info(key + " : " + p.getProperty(key));
        }
    }

}

From source file:net.padlocksoftware.padlock.license.LicenseImpl.java

protected static Set<String> propertyNames(Properties p) {
    Set<String> set = new HashSet<String>();

    Enumeration<Object> e = p.keys();
    while (e.hasMoreElements()) {
        set.add(e.nextElement().toString());
    }/*w w w .j  av  a 2 s.c o m*/

    return set;
}

From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java

private static void validateEclipseCsMetaPropFile(File file, String pkg, Set<Class<?>> pkgModules)
        throws Exception {
    Assert.assertTrue("'checkstyle-metadata.properties' must exist in eclipsecs in inside " + pkg,
            file.exists());/*  w ww  .  j  a v  a2  s. c om*/

    final Properties prop = new Properties();
    prop.load(new FileInputStream(file));

    final Set<Object> properties = new HashSet<>(Collections.list(prop.keys()));

    for (Class<?> module : pkgModules) {
        final String moduleName = module.getSimpleName();

        Assert.assertTrue(moduleName + " requires a name in eclipsecs properties " + pkg,
                properties.remove(moduleName + ".name"));
        Assert.assertTrue(moduleName + " requires a desc in eclipsecs properties " + pkg,
                properties.remove(moduleName + ".desc"));

        final Set<String> moduleProperties = getFinalProperties(module);

        for (String moduleProperty : moduleProperties) {
            Assert.assertTrue(
                    moduleName + " requires the property " + moduleProperty + " in eclipsecs properties " + pkg,
                    properties.remove(moduleName + "." + moduleProperty));
        }
    }

    for (Object property : properties) {
        Assert.fail("Unknown property found in eclipsecs properties " + pkg + ": " + property);
    }
}

From source file:com.openideals.android.net.HttpManager.java

public static String doPost(String serviceEndpoint, Properties props) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();

    HttpPost request = new HttpPost(serviceEndpoint);
    HttpResponse response = null;/*w  w  w .  ja  v a 2 s  .  c  o  m*/
    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));

        Log.i(TAG, "adding nvp:" + key + "=" + value);
    }

    UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

    Log.i(TAG, uf.toString());

    request.setEntity(uf);

    request.setHeader("Content-Type", POST_MIME_TYPE);

    Log.i(TAG, "http post request: " + request.toString());

    // 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);
        Log.e(TAG, ostream.toString());

        return null;
    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

        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:info.guardianproject.net.http.HttpManager.java

public static String doPost(String serviceEndpoint, Properties props) throws Exception {

    DefaultHttpClient httpClient = new SocksHttpClient();

    HttpPost request = new HttpPost(serviceEndpoint);
    HttpResponse response = null;//from  www  . ja va 2  s.co  m
    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));

        Log.i(TAG, "adding nvp:" + key + "=" + value);
    }

    UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

    Log.i(TAG, uf.toString());

    request.setEntity(uf);

    request.setHeader("Content-Type", POST_MIME_TYPE);

    Log.i(TAG, "http post request: " + request.toString());

    // 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);
        Log.e(TAG, ostream.toString());

        return null;
    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

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

public static String uploadFile(String page, Properties properties, String fileParam, String file,
        int timeOutSec) throws Exception {
    if (D) {/*from  w w w .j  a va 2  s  .  c  om*/
        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.lsc.Configuration.java

/**
 * Set the new properties/*  www  . j a  va  2  s  .  c  om*/
 * @param prefix the prefix or null
 * @param props the news properties
 * @throws ConfigurationException
 */
public static void setProperties(String prefix, Properties props) throws ConfigurationException {
    Enumeration<Object> propsEnum = props.keys();
    PropertiesConfiguration conf = Configuration.getConfiguration();
    while (propsEnum.hasMoreElements()) {
        String key = (String) propsEnum.nextElement();
        conf.setProperty((prefix != null ? prefix + "." : "") + key, props.getProperty(key));
    }
    conf.save();
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.PropertiesUtil.java

/**
 * Filter/Eliminate keys that have a value that starts with the given prefix.
 * //  w  w w. j a v  a  2s  . c om
 * @param properties
 * @param prefix
 * @return
 */
public static Properties filterValuesStartingWith(Properties properties, String prefix) {
    if (!StringUtils.hasText(prefix))
        return EMPTY_PROPERTIES;

    Assert.notNull(properties);
    Properties excluded = (properties instanceof OrderedProperties ? new OrderedProperties()
            : new Properties());

    for (Enumeration enm = properties.keys(); enm.hasMoreElements();) {
        String key = (String) enm.nextElement();
        String value = properties.getProperty(key);
        if (value.startsWith(prefix)) {
            excluded.put(key, value);
        }
    }

    for (Enumeration enm = excluded.keys(); enm.hasMoreElements();) {
        properties.remove(enm.nextElement());
    }
    return excluded;
}