Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

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

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:energy.usef.core.config.AbstractConfig.java

/**
 * Returns the configuration folder of the application or for unit tests.
 *
 * @return the configuration Folder//from  ww w . jav a2  s.co  m
 */
public static String getConfigurationFolder() {
    String foldername;
    if (isDeployed()) {
        Properties localProperties = readApplicationProperties();
        String applicationName = localProperties.getProperty(APPLICATION_NAME_PROPERTY);
        foldername = DOMAIN_CONFIG_FOLDER + File.separator + applicationName + File.separator;
    } else {
        foldername = SRC_TEST_RESOURCES_FOLDER;
    }
    return foldername;
}

From source file:com.cloud.utils.PropertiesUtil.java

public static Map<String, Object> toMap(Properties props) {
    Set<String> names = props.stringPropertyNames();
    HashMap<String, Object> map = new HashMap<String, Object>(names.size());
    for (String name : names) {
        map.put(name, props.getProperty(name));
    }/*ww  w  .j a v a 2s  .  com*/

    return map;
}

From source file:com.sugarcrm.candybean.configuration.Configuration.java

public static String getPlatformValue(Properties props, String key) {
    String platform = Utils.getCurrentPlatform();
    String valueStr = props.getProperty(key);
    JSONParser parser = new JSONParser();
    try {/*from  w  ww .j  a  v a  2s  . c o  m*/
        Object valueObject = parser.parse(valueStr);
        if (valueObject instanceof Map) {
            JSONObject valueMap = (JSONObject) valueObject;
            return (String) valueMap.get(platform);
        } else {
            return valueStr;
        }
    } catch (ParseException pe) {
        return valueStr;
    }
}

From source file:bluevia.SendSMS.java

public static void sendBlueViaSMS(String user_email, String phone_number, String sms_message) {
    try {/*from   www.jav a2s  .com*/

        Properties blueviaAccount = Util.getNetworkAccount(user_email, "BlueViaAccount");
        if (blueviaAccount != null) {
            String consumer_key = blueviaAccount.getProperty("BlueViaAccount.consumer_key");
            String consumer_secret = blueviaAccount.getProperty("BlueViaAccount.consumer_secret");
            String access_key = blueviaAccount.getProperty("BlueViaAccount.access_key");
            String access_secret = blueviaAccount.getProperty("BlueViaAccount.access_secret");

            com.google.appengine.api.urlfetch.FetchOptions.Builder.doNotValidateCertificate();

            OAuthConsumer consumer = (OAuthConsumer) new DefaultOAuthConsumer(consumer_key, consumer_secret);
            consumer.setMessageSigner(new HmacSha1MessageSigner());
            consumer.setTokenWithSecret(access_key, access_secret);

            URL apiURI = new URL("https://api.bluevia.com/services/REST/SMS/outbound/requests?version=v1");
            HttpURLConnection request = (HttpURLConnection) apiURI.openConnection();

            request.setRequestProperty("Content-Type", "application/json");
            request.setRequestMethod("POST");
            request.setDoOutput(true);

            consumer.sign(request);
            request.connect();

            String smsTemplate = "{\"smsText\": {\n  \"address\": {\"phoneNumber\": \"%s\"},\n  \"message\": \"%s\",\n  \"originAddress\": {\"alias\": \"%s\"},\n}}";
            String smsMsg = String.format(smsTemplate, phone_number, sms_message, access_key);

            OutputStream os = request.getOutputStream();
            os.write(smsMsg.getBytes());
            os.flush();

            int rc = request.getResponseCode();

            if (rc == HttpURLConnection.HTTP_CREATED)
                log.info(String.format("SMS sent to %s. Text: %s", phone_number, sms_message));
            else
                log.severe(String.format("Error %d sending SMS:%s\n", rc, request.getResponseMessage()));
        } else
            log.warning("BlueVia Account seems to be not configured!");

    } catch (Exception e) {
        log.severe(String.format("Exception sending SMS: %s", e.getMessage()));
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderCatalogRdfXmlTests.java

@Parameters
public static Collection<Object[]> getAllServiceProviderCatalogUrls()
        throws IOException, ParserConfigurationException, SAXException, XPathException {
    //Checks the ServiceProviderCatalog at the specified baseUrl of the REST service in order to grab all urls
    //to other ServiceProviders contained within it, recursively.
    Properties setupProps = SetupProperties.setup(null);
    Collection<Object[]> coll = getReferencedCatalogUrlsUsingRdfXml(setupProps.getProperty("baseUri"));
    return coll;/*from   w ww.  j ava2  s.c  o m*/
}

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

public static Properties getSystemPropertiesByName(String name) {
    Properties props = systemProperties.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);//w  ww.j av a 2  s . co m
    }
    return p;
}

From source file:gobblin.runtime.api.TopologySpec.java

/** Creates a builder for the TopologySpec based on values in a topology properties config. */
public static TopologySpec.Builder builder(URI catalogURI, Properties topologyProps) {
    String name = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_NAME_KEY);
    String group = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_GROUP_KEY, "default");

    try {//from  w  ww.  j a va 2  s. co m
        URI topologyURI = new URI(catalogURI.getScheme(), catalogURI.getAuthority(), "/" + group + "/" + name,
                null);
        TopologySpec.Builder builder = new TopologySpec.Builder(topologyURI)
                .withConfigAsProperties(topologyProps);
        String descr = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_DESCRIPTION_KEY, null);
        if (null != descr) {
            builder = builder.withDescription(descr);
        }

        return builder;
    } catch (URISyntaxException e) {
        throw new RuntimeException("Unable to create a TopologySpec URI: " + e, e);
    }
}

From source file:net.duckling.ddl.web.bean.ClbHelper.java

public static String getClbToken(int docId, int version, Properties properties) {
    HttpClient client = HttpClientUtil.getHttpClient(LOGGER);
    PostMethod method = new PostMethod(getClbTokenUrl(properties));
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
    method.addParameter("appname", properties.getProperty("duckling.clb.aone.user"));
    method.addParameter("docid", docId + "");
    method.addParameter("version", version + "");
    try {/*from   ww  w . j  a v a  2  s  .c o m*/
        method.addParameter("password",
                Base64.encodeBytes(properties.getProperty("duckling.clb.aone.password").getBytes("utf-8")));
    } catch (IllegalArgumentException | UnsupportedEncodingException e) {

    }
    try {
        int status = client.executeMethod(method);
        String responseString = null;
        if (status < 400) {
            responseString = method.getResponseBodyAsString();
            org.json.JSONObject j = new org.json.JSONObject(responseString);
            Object st = j.get("status");
            if ("failed".equals(st)) {
                LOGGER.error("?clb token?");
                return null;
            } else {
                return j.get("pf").toString();
            }
        } else {
            LOGGER.error("STAUTS:" + status + ";MESSAGE:" + responseString);
        }
    } catch (HttpException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (ParseException e) {
        LOGGER.error("", e);
    }
    return null;
}