Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

In this page you can find the example usage for java.lang String toString.

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:com.cbtec.eliademyutils.EliademyUtils.java

public static String serviceCall(String data, String webService, String token, String serviceClient) {

    String retval = null;// w  w w.  j  a  va2  s . c  o m
    Log.d("EliademyUtils", "Service: " + data + " Service: " + webService);

    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        if (data.toString().length() > 0) {
            JSONObject jsObj = new JSONObject(data.toString());
            nameValuePairs.addAll(nameValueJson(jsObj, ""));
        }
        nameValuePairs.add(new BasicNameValuePair("wstoken", token));
        nameValuePairs.add(new BasicNameValuePair("wsfunction", webService));
        nameValuePairs.add(new BasicNameValuePair("moodlewsrestformat", "json"));

        HttpPost httppost = new HttpPost(serviceClient + "/webservice/rest/server.php?");

        Log.d("EliademyUtils", nameValuePairs.toString());
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            StringBuilder jsonStr = new StringBuilder();
            InputStream iStream = entity.getContent();
            BufferedReader bufferReader = new BufferedReader(new InputStreamReader(iStream));
            String jpart;
            while ((jpart = bufferReader.readLine()) != null) {
                jsonStr.append(jpart);
            }
            iStream.close();
            return jsonStr.toString();
        }
    } catch (Exception e) {
        Log.e("EliademyUtils", "exception", e);
        return retval;
    }
    return retval;
}

From source file:com.jive.myco.seyren.core.util.config.SeyrenConfig.java

private static String[] splitBaseUrl(String baseUrl) {
    String[] baseParts = new String[4];

    if (baseUrl.toString().contains("://")) {
        baseParts[0] = baseUrl.toString().split("://")[0];
        baseUrl = baseUrl.toString().split("://")[1];
    } else {//  w  w  w  .  j  a  v a2 s. c  om
        baseParts[0] = "http";
    }

    if (baseUrl.contains(":")) {
        baseParts[1] = baseUrl.split(":")[1];
    } else {
        baseParts[1] = "443";
    }

    if (baseUrl.contains("/")) {
        baseParts[2] = baseUrl.split("/")[0];
        baseParts[3] = "/" + baseUrl.split("/", 2)[1];
    } else {
        baseParts[2] = baseUrl;
        baseParts[3] = "";
    }

    return baseParts;
}

From source file:com.easyway.java.rpc.secure.security.Encodes.java

public static String decodeXX(String str) {
    StringBuffer buff2 = new StringBuffer();
    // ?/*from w ww. j a v a2 s .c o  m*/
    int length = list.size();
    // ? ?? ?
    for (char c : str.toString().toCharArray()) {
        // ?  
        int i = list.indexOf(c);
        // ? list ??? ??
        if (i < 0) {
            buff2.append(c);
            continue;
        }
        // ??
        i = i - offset >= 0 ? i - offset : i - offset + length;
        // 
        buff2.append(list.get(i));
    }
    String deStr = buff2.toString();
    byte[] base64de = Encodes.decodeBase64(deStr);
    try {
        return new String(base64de, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        return "";
    }
}

From source file:com.fluidops.iwb.api.ValueResolver.java

/**
 * Create a URL link// www  . ja  v a2 s. co  m
 * @param value The URL link
 * @return Returns a link
 */
private static String resolveURL(String value, String linkName) {
    String valueStr = value.toString();

    valueStr = XssSafeHttpRequest.cleanXSS(valueStr);

    if (linkName == null)
        linkName = value;
    linkName = StringEscapeUtils.escapeHtml(linkName);
    return "<a href='" + valueStr + "' target='_blank'>" + linkName + "</a>";
}

From source file:com.netsteadfast.greenstep.base.model.SqlGenerateUtil.java

private static Map<String, Object> getByPK(String fieldName, Object entityObject) throws Exception {
    String tableName = getTableName(entityObject);
    String pk = getPKname(entityObject);
    Object value = getPKvalue(entityObject);
    if ("".equals(tableName.trim()) || null == pk || "".equals(pk) || null == value) {
        throw new java.lang.IllegalArgumentException(NOT_ENTITY_BEAN);
    }/*from  ww w. jav a2  s . c o  m*/
    String sql = " select " + fieldName + " from " + tableName + " where " + pk + "=?";
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put(RETURN_SQL, sql.toString());
    queryMap.put(RETURN_PARAMS, new Object[] { value });
    return queryMap;
}

From source file:com.ikon.module.jcr.stuff.JCRUtils.java

/**
 * Obtain lock token from node id/*from w w w.j a v a 2s  .  c o  m*/
 */
public static String getLockToken(String id) {
    StringBuffer buf = new StringBuffer();
    buf.append(id.toString());
    buf.append('-');
    buf.append(getCheckDigit(id.toString()));
    return buf.toString();
}

From source file:com.easyway.java.rpc.secure.security.Encodes.java

public static String decode(String str) {
    StringBuffer buff2 = new StringBuffer();
    // ?//from   www . j  a v  a  2  s  .c o m
    int length = list.size();
    // ? ?? ?
    for (char c : str.toString().toCharArray()) {
        // ?  
        int i = list.indexOf(c);
        // ? list ??? ??
        if (i < 0) {
            if (c == '+') {
                buff2.append("-");
            } else if (c == '/') {
                buff2.append("_");
            } else {
                buff2.append(c);
            }
            continue;
        }
        // ??
        i = i - offset >= 0 ? i - offset : i - offset + length;
        // 
        buff2.append(list.get(i));
    }
    String deStr = buff2.toString();
    try {
        // byte[] deStrbyte=deStr.getBytes("ISO-8859-1");
        byte[] base64de = Base64.decodeBase64(deStr);
        return new String(base64de, "GBK");
    } catch (UnsupportedEncodingException e) {
        return "";
    }
}

From source file:Logica.prueba.java

public static String ExportarRespuestas() throws UnsupportedEncodingException {
    HttpClient client = HttpClients.createDefault();
    HttpPost post = new HttpPost("http://localhost/index.php?r=admin/remotecontrol");
    post.setHeader("Content-type", "application/json");
    System.out.println(post);//from  ww  w .ja v  a2  s .  c  o m
    try {
        HttpResponse response = client.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String sessionKey = parse(EntityUtils.toString(entity));
            System.out.println(sessionKey);
            JsonObject request = new JsonObject();
            JsonObject params = new JsonObject();
            request.addProperty("id", 1);
            request.addProperty("method", "export_responses");
            params.addProperty("sSessionKey", sessionKey.toString());
            params.addProperty("iSurveyID", 68124);
            params.addProperty("sDocumentType", "json");
            request.add("params", params);
            System.out.println("Request: " + request.toString());
            post.setEntity(new StringEntity(request.toString()));
            response = client.execute(post);
            if (response.getStatusLine().getStatusCode() == 200) {
                entity = response.getEntity();
                JsonParser gson = new JsonParser();
                JsonObject respuesta = (JsonObject) gson.parse(EntityUtils.toString(entity));
                String ans = respuesta.get("result").getAsString();
                String stringFromBase = new String(Base64.decodeBase64(ans));
                System.out.println("reponse: " + stringFromBase);
            }
        }
        // post.setEntity( new
        // StringEntity("{\"method\": \"list_groups\", \"params\": {\"sSessionKey \": "+sessionKey+", \"iSurveyID \": \"436586\" }, \"id\": 1}"));
        // response = client.execute(post);
        // if(response.getStatusLine().getStatusCode() == 200){
        // entity = response.getEntity();
        // System.out.println(EntityUtils.toString(entity));
        // }
        // }

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:ips1ap101.lib.base.util.TimeUtils.java

public static java.util.Date parse(String pdq) {
    String string = pdq == null ? null : pdq.toString().trim();
    if (string == null || string.isEmpty()) {
        return null;
    }//from w  w w . j  av  a  2  s  .co  m
    int year = 1970;
    int monthOfYear = 1;
    int dayOfMonth = 1;
    int hourOfDay = 0;
    int minuteOfHour = 0;
    int secondOfMinute = 0;
    String xm = "";
    String xs = "";
    String format = getDateFormat();
    int len = string.length();
    switch (len) {
    case 22:
        xm = string.substring(20);
    case 19:
        if (xm.isEmpty()) {
            xs = string.substring(17, 19);
        }
        if (xs.equalsIgnoreCase("AM") || xs.equalsIgnoreCase("PM")) {
            xm = xs;
        } else {
            secondOfMinute = Integer.parseInt(string.substring(17, 19));
        }
    case 16:
        minuteOfHour = Integer.parseInt(string.substring(14, 16));
        hourOfDay = Integer.parseInt(string.substring(11, 13));
        if (xm.equalsIgnoreCase("AM") && hourOfDay == 12) {
            hourOfDay = 0;
        }
        if (xm.equalsIgnoreCase("PM") && hourOfDay <= 11) {
            hourOfDay += 12;
        }
        format = getTimestampFormat();
    case 10:
        switch (format.substring(0, 2)) {
        case "yy":
            year = Integer.parseInt(string.substring(0, 4));
            monthOfYear = Integer.parseInt(string.substring(5, 7));
            dayOfMonth = Integer.parseInt(string.substring(8, 10));
            break;
        case "MM":
            year = Integer.parseInt(string.substring(6, 10));
            monthOfYear = Integer.parseInt(string.substring(0, 2));
            dayOfMonth = Integer.parseInt(string.substring(3, 5));
            break;
        case "dd":
        default:
            year = Integer.parseInt(string.substring(6, 10));
            monthOfYear = Integer.parseInt(string.substring(3, 5));
            dayOfMonth = Integer.parseInt(string.substring(0, 2));
            break;
        }
        break;
    case 8:
        xm = string.substring(6);
    case 6:
        minuteOfHour = Integer.parseInt(string.substring(3, 5));
        hourOfDay = Integer.parseInt(string.substring(0, 2));
        if (xm.equalsIgnoreCase("AM") && hourOfDay == 12) {
            hourOfDay = 0;
        }
        if (xm.equalsIgnoreCase("PM") && hourOfDay <= 11) {
            hourOfDay += 12;
        }
        break;
    default:
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, monthOfYear - 1);
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    c.set(Calendar.HOUR_OF_DAY, hourOfDay);
    c.set(Calendar.MINUTE, minuteOfHour);
    c.set(Calendar.SECOND, secondOfMinute);
    c.set(Calendar.MILLISECOND, 0);
    return new Date(c.getTimeInMillis());
}

From source file:yodlee.ysl.api.io.HTTP.java

public static String doGet(String url, Map<String, String> sessionTokens)
        throws IOException, URISyntaxException {
    String mn = "doIO(GET :" + url + ", sessionTokens =  " + sessionTokens.toString() + " )";
    System.out.println(fqcn + " :: " + mn);
    URL myURL = new URL(url);
    System.out.println(fqcn + " :: " + mn + ": Request URL=" + url.toString());
    HttpURLConnection conn = (HttpURLConnection) myURL.openConnection();
    //conn.setRequestMethod("GET");
    conn.setRequestProperty("User-Agent", userAgent);
    //conn.setRequestProperty("Content-Type", contentTypeJSON);
    //conn.setRequestProperty("Accept",);
    conn.setRequestProperty("Authorization", sessionTokens.toString());
    conn.setDoOutput(true);/* w  w  w  .  ja  va 2s.c  o  m*/
    System.out.println(fqcn + " :: " + mn + " : " + "Sending 'HTTP GET' request");
    int responseCode = conn.getResponseCode();
    System.out.println(fqcn + " :: " + mn + " : " + "Response Code : " + responseCode);
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;
    StringBuilder jsonResponse = new StringBuilder();
    while ((inputLine = in.readLine()) != null) {
        System.out.println(inputLine);
        jsonResponse.append(inputLine);
    }
    in.close();
    System.out.println(fqcn + " :: " + mn + " : " + jsonResponse.toString());
    return new String(jsonResponse);
}