Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

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

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

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

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

    Assert.notNull(properties);

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

    // filter ignore keys out
    for (Enumeration enm = properties.keys(); enm.hasMoreElements();) {
        String key = (String) enm.nextElement();
        if (key.startsWith(prefix)) {
            excluded.put(key, properties.get(key));
        }
    }

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

From source file:com.flozano.socialauth.AuthProviderFactory.java

private static AuthProvider getProvider(final String id, final String fileName, final ClassLoader classLoader)
        throws Exception {
    Properties props = new Properties();
    AuthProvider provider;/*from w ww .  j  a va2s .c  o  m*/
    ClassLoader loader = null;
    if (classLoader != null) {
        loader = classLoader;
    } else {
        loader = AuthProviderFactory.class.getClassLoader();
    }
    try {
        InputStream in = loader.getResourceAsStream(fileName);
        props.load(in);
        for (Object key : props.keySet()) {
            String str = key.toString();
            if (str.startsWith("socialauth.")) {
                String val = str.substring("socialauth.".length());
                registerProvider(val, Class.forName(props.get(str).toString()));
            }
        }
    } catch (NullPointerException ne) {
        throw new FileNotFoundException(fileName + " file is not found in your class path");
    } catch (IOException ie) {
        throw new IOException("Could not load configuration from " + fileName);
    }

    provider = loadProvider(id, props);
    return provider;
}

From source file:com.turn.griffin.utils.GriffinConsumer.java

private static ConsumerConfig createConsumerConfig(String zkAddress, String groupId, Properties userProps) {
    Properties props = new Properties();
    props.put("zookeeper.connect", zkAddress);
    props.put("zookeeper.session.timeout.ms", "30000");
    props.put("zookeeper.connection.timeout.ms", "30000");
    props.put("zookeeper.sync.time.ms", "6000");

    props.put("group.id", groupId);

    props.put("auto.commit.enable", "true");
    props.put("auto.commit.interval.ms", "300000"); // 5 min
    props.put("rebalance.backoff.ms", "20000");

    /* Add user specified properties */
    /* Should be the last line to allow overriding any of the properties above */
    props.putAll(userProps);/*  w  w  w .j av  a 2s .  c  o m*/

    /* A hack to set the consumer offset to zero if the user specified smallest offset */
    if ("smallest".equals(props.get("auto.offset.reset"))) {
        ZkUtils.maybeDeletePath(zkAddress, new ZKGroupDirs(groupId).consumerGroupDir());
    }
    return new ConsumerConfig(props);
}

From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java

public static boolean proxyExists() {
    Properties prop = System.getProperties();
    if (prop.get("http.proxyHost") != null && prop.get("http.proxyPort") != null)
        return true;

    if (proxy != null) {
        String proxyHost = proxy.getProxyHost();
        int proxyPort = proxy.getProxyPort();

        if (proxyHost != null && proxyPort > 0)
            return true;
    }/*from   w ww  .  j  a v  a  2 s  .c  om*/
    return false;
}

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());
    }//www.j a v a  2 s. 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:com.halseyburgund.roundware.server.RWHttpManager.java

public static String doGet(String page, Properties props) throws Exception {
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT_MSEC);
    HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT_MSEC);

    HttpClient httpClient = new DefaultHttpClient(httpParams);

    StringBuilder uriBuilder = new StringBuilder(page);

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;// w ww.  j  av  a2 s.  co  m

    uriBuilder.append('?');

    while (enumProps.hasMoreElements()) {
        key = enumProps.nextElement().toString();
        value = props.get(key).toString();
        uriBuilder.append(key);
        uriBuilder.append('=');
        uriBuilder.append(java.net.URLEncoder.encode(value));
        if (enumProps.hasMoreElements()) {
            uriBuilder.append('&');
        }
    }

    if (D) {
        RWHtmlLog.i(TAG, "GET request: " + uriBuilder.toString(), null);
    }

    HttpGet request = new HttpGet(uriBuilder.toString());
    HttpResponse response = httpClient.execute(request);

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

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        response.getEntity().writeTo(ostream);
        RWHtmlLog.e(TAG, "GET ERROR: " + ostream.toString(), null);

        throw new Exception(HTTP_POST_FAILED + 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
    }

    if (D) {
        RWHtmlLog.i(TAG, "GET response: " + sbResponse.toString(), null);
    }

    return sbResponse.toString();
}

From source file:com.halseyburgund.rwframework.core.RWHttpManager.java

public static String doGet(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);

    StringBuilder uriBuilder = new StringBuilder(page);

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;/*from   w w  w .j a  v a2s  . co  m*/

    uriBuilder.append('?');

    while (enumProps.hasMoreElements()) {
        key = enumProps.nextElement().toString();
        value = props.get(key).toString();
        uriBuilder.append(key);
        uriBuilder.append('=');
        uriBuilder.append(java.net.URLEncoder.encode(value));
        if (enumProps.hasMoreElements()) {
            uriBuilder.append('&');
        }
    }

    if (D) {
        Log.d(TAG, "GET request: " + uriBuilder.toString(), null);
    }

    HttpGet request = new HttpGet(uriBuilder.toString());
    HttpResponse response = httpClient.execute(request);

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

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        response.getEntity().writeTo(ostream);
        Log.e(TAG, "GET ERROR: " + 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
    }

    if (D) {
        Log.d(TAG, "GET response: " + sbResponse.toString(), null);
    }

    return sbResponse.toString();
}

From source file:com.dtolabs.rundeck.ExpandRunServer.java

/**
 * Return the input with embedded property references expanded
 *
 * @param properties the properties to select form
 * @param input      the input/* ww w .  j a  va2  s  .com*/
 *
 * @return string with references expanded
 */
public static String expandProperties(final Properties properties, final String input) {
    final Pattern pattern = Pattern.compile(PROPERTY_PATTERN);
    final Matcher matcher = pattern.matcher(input);
    final StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        final String match = matcher.group(1);
        if (null != properties.get(match)) {
            matcher.appendReplacement(sb, Matcher.quoteReplacement(properties.getProperty(match)));
        } else {
            matcher.appendReplacement(sb, Matcher.quoteReplacement(matcher.group(0)));
        }
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:net.cliseau.composer.config.format.PropertiesConfig.java

/**
 * Make a path absolute with respect to a particular configuration.
 *
 * @param props Properties object holding the full configuration.
 * @param path Possibly relative path to be made absolute.
 *//*from  w w  w. j a v  a2  s .  c o  m*/
private static String makeAbsolute(final Properties props, final String path)
        throws MissingConfigurationException {
    File f = new File(path);
    if (f.isAbsolute()) // absolute paths are simply returned
        return f.getPath();
    else { // relative paths must be made absolute using on a chosen base directory
        // note that the "basedir" property is set in the constructor
        // of the class
        return (new File((File) props.get("basedir"), f.getPath())).getPath();
    }
}

From source file:com.ailk.oci.ocnosql.tools.load.single.SingleColumnImportTsv.java

private static Map<String, String> getProperty() {
    Map<String, String> map = null;
    try {/*  w w w  .ja  v  a 2 s  . c o m*/
        String conf_Path = SingleColumnImportTsv.class.getClassLoader().getResource(CONF_FILE).getPath();

        File file = new File(conf_Path);
        Properties prop = new Properties();
        prop.load(new FileReader(file));

        map = new HashMap<String, String>();
        for (Object key : prop.keySet()) {
            map.put((String) key, (String) prop.get(key));
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return map;
}