Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

@Deprecated
public static String decode(String s) 

Source Link

Document

Decodes a x-www-form-urlencoded string.

Usage

From source file:com.example.android.rowanparkingpass.Networking.Sync.SyncDrivers.java

public synchronized void sync(Context c) {
    if (SaveData.getSync()) {
        SendInfoDriver sendInfoDriver = new SendInfoDriver();
        JSONObject json = sendInfoDriver.syncDrivers(c);
        JSONArray jsonArray;//from  ww  w .j  a v  a  2 s .com
        States[] arrayStates = States.values();
        try {
            String s = json.getString("JSONS");
            s = URLDecoder.decode(s);
            Log.d("S", s);
            jsonArray = new JSONArray(s);
            Log.d("JSON ARRAY", jsonArray.toString());
            DatabaseHandlerDrivers db = new DatabaseHandlerDrivers(c);
            for (int i = 0; i < jsonArray.length(); i++) {
                //[{"model":"zaz","color":"1","state":"23","user_id":"10","year":"1945","license":"bingling","vehicle_id":"3","make":"me a sammich"}

                JSONObject jsonObj = jsonArray.getJSONObject(i);
                //Log.d("JSONOBJ", jsonObj.toString());
                String driverID = jsonObj.getString("driver_id");
                String fullName = jsonObj.getString("full_name");
                String street = jsonObj.getString("street");
                String city = jsonObj.getString("city");
                String state = jsonObj.getString("state");
                String zip = Utilities.appendZipZero(jsonObj.getString("zip"));
                try {
                    db.addDriver(Integer.parseInt(driverID), Utilities.fakeByte, fullName, street, city,
                            arrayStates[Integer.parseInt(state)]
                                    .valueOf(arrayStates[Integer.parseInt(state)].name()).toString(),
                            zip);
                } catch (SQLiteConstraintException sqlC) {
                    Log.d("SQLite Exception", sqlC.getMessage());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:Main.java

static public String getNodeValue(Element parent, String nodeName) {
    NodeList nodes = parent.getElementsByTagName(nodeName);
    if (nodes.getLength() == 0)
        return null;
    Element curElem = (Element) nodes.item(0);
    Node textNode = curElem.getFirstChild();
    if (textNode != null) {
        String encVal = curElem.getAttribute("enc");
        String charSetVal = curElem.getAttribute("charSet");
        String returnVal = textNode.getNodeValue();
        if (encVal != null && encVal.equals("t")) {
            if (charSetVal == null)
                return (URLDecoder.decode(returnVal));
            else/*  w  w w  .  j av a  2  s. c  o m*/
                try {
                    return (URLDecoder.decode(returnVal, charSetVal));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        }
        return (returnVal);
    } else
        return ("");
}

From source file:com.web.server.WebServer.java

/**
 * This method parses the encoded url //  w  ww .  j av a2  s. co m
 * @param urlEncoded
 * @return
 */
public static ConcurrentHashMap parseUrlEncoded(String urlEncoded) {
    ConcurrentHashMap ParamValue = new ConcurrentHashMap();
    URLDecoder urlDecoder = new URLDecoder();
    StringTokenizer paramGroup = new StringTokenizer(urlDecoder.decode(urlEncoded), "&");

    while (paramGroup.hasMoreTokens()) {

        StringTokenizer token = new StringTokenizer(paramGroup.nextToken(), "=");
        String key = "";
        String value = "";
        if (token.hasMoreTokens())
            key = token.nextToken();
        if (token.hasMoreTokens())
            value = token.nextToken();
        ParamValue.put(key, value);

    }
    return ParamValue;
}

From source file:com.wbtech.dao.NetworkUitlity.java

public static MyMessage post(String url, String data) {
    // TODO Auto-generated method stub
    String returnContent = "";
    MyMessage message = new MyMessage();
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {//from  www .j  ava2 s  . c o  m
        StringEntity se = new StringEntity("content=" + data, HTTP.UTF_8);
        Log.d("postdata", "content=" + data);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();

        String returnXML = EntityUtils.toString(response.getEntity());
        returnContent = URLDecoder.decode(returnXML);
        switch (status) {
        case 200:
            message.setFlag(true);
            message.setMsg(returnContent);
            break;

        default:
            Log.e("error", status + returnContent);
            message.setFlag(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        JSONObject jsonObject = new JSONObject();

        if (e.getMessage().equalsIgnoreCase("no route to host")) {
            try {
                jsonObject.put("err", "??,???");
                returnContent = jsonObject.toString();
                message.setFlag(false);
                message.setMsg(returnContent);
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

        else if (e.getMessage().equalsIgnoreCase("network unreachable")
                || e.getMessage().equalsIgnoreCase("www.cobub.com")) {
            try {
                jsonObject.put("err", "");
                returnContent = jsonObject.toString();
                message.setFlag(false);
                message.setMsg(returnContent);
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

        else {
            try {
                jsonObject.put("err", "");
                returnContent = jsonObject.toString();
                message.setFlag(false);
                message.setMsg(returnContent);
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

    }
    return message;
}

From source file:Main.java

/**
 * URL decoding of query parameters of a URL
 * /*from w w  w  .  j a  v a  2  s  .c o  m*/
 * @param s
 *            URL to be decoded
 * @return Map of parameter and values
 */
public static Map<String, String> decodeUrl(String s) {
    Map<String, String> params = new HashMap<String, String>();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length > 1) {
                params.put(URLDecoder.decode(v[0]), v.length > 1 ? URLDecoder.decode(v[1]) : null);
            }
        }
    }
    return params;
}

From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java

/**
 * &?URL???key-value??/* w ww .  ja va2  s  .  c  om*/
 * 
 * @param s
 *            &?URL?
 * @return key-value??
 */
@SuppressWarnings("deprecation")
public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length > 1) {
                params.putString(v[0], URLDecoder.decode(v[1]));
            }
        }
    }
    return params;
}

From source file:com.ds.kaixin.Util.java

/**
 * &URLkey-value/* ww w .j  av a  2s .  co  m*/
 * 
 * @param s
 *            &URL
 * @return key-value
 */
public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length > 1) {
                params.putString(v[0], URLDecoder.decode(v[1]));
            }
        }
    }
    return params;
}

From source file:lordkbx.FileHash.FileHash.java

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    String url = args.getString(0);
    url = URLDecoder.decode(url);
    System.out.println("File root system " + context.getPackageName());
    JSONObject r = new JSONObject();
    String ealgo = "";
    if (action.equals("md2")) {
        ealgo = "MD2";
    }// www.j av a 2 s .com
    if (action.equals("md5")) {
        ealgo = "MD5";
    }
    if (action.equals("sha1")) {
        ealgo = "SHA-1";
    }
    if (action.equals("sha256")) {
        ealgo = "SHA-256";
    }
    if (action.equals("sha384")) {
        ealgo = "SHA-384";
    }
    if (action.equals("sha512")) {
        ealgo = "SHA-512";
    }
    if (action.equals("md2") || action.equals("md5") || action.equals("sha1") || action.equals("sha256")
            || action.equals("sha384") || action.equals("sha512")) {
        String[] rez = central(url, ealgo);
        if (rez[1] == "") {
            r.put("file", url);
            r.put("algo", ealgo);
            r.put("result", rez[0]);
            callbackContext.success(r);
        } else {
            r.put("code", rez[0]);
            r.put("message", rez[1]);
            callbackContext.error(r);
        }
    } else {
        r.put("code", 1);
        r.put("message", this.errorCodes[1]);
        callbackContext.error(r);
    }
    return true;
}

From source file:com.exquance.jenkins.plugins.HarbormasterHookReceiver.java

/**
 * Harbormaster sends payload as urlencoded query string <pre>payload=JSON</pre>
 * @throws IOException//from   w  w w.  j a  va2  s .c o m
 */
public void doIndex(StaplerRequest req) throws IOException {
    if (req.getRequestURI().contains("/" + HARBORMASTER_HOOK_URL + "/")) {
        String body = URLDecoder.decode(req.getQueryString());
        if (body.startsWith("payload="))
            body = body.substring(8);

        LOGGER.log(Level.FINE, "Received commit hook notification : {0}", body);
        JSONObject payload = JSONObject.fromObject(body);

        payloadProcessor.processPayload(payload, req);
    } else {
        LOGGER.log(Level.WARNING,
                "The Jenkins job cannot be triggered. You might not have configured correctly the WebHook on Harbormaster with the last slash `http://<JENKINS-URL>/harbormaster-hook/`");
    }
}

From source file:com.web.server.WebServer.java

/**
 * This method obtains the url parameters
 * @param url//from w  w  w . j a v a2  s  .c  o m
 * @param params
 * @return string
 */
public String ObtainUrlAndParams(String url, ConcurrentHashMap params) {

    URLDecoder decoder = new URLDecoder();
    url = decoder.decode(url);
    if (url.indexOf("?") > -1) {
        String paramaters = url.substring(url.indexOf("?") + 1);
        StringTokenizer paramGroup = new StringTokenizer(paramaters, "&");

        while (paramGroup.hasMoreTokens()) {

            StringTokenizer value = new StringTokenizer(paramGroup.nextToken(), "=");
            String param = null;
            if (value.hasMoreTokens()) {
                param = value.nextToken();
            }
            String paramValue = null;
            if (value.hasMoreTokens()) {
                paramValue = value.nextToken();
            }
            if (param != null && paramValue != null) {
                if (params.get(param) != null) {
                    if (params.get(param) instanceof String[]) {
                        String[] parameters = (String[]) params.get(param);
                        String[] paramValues = new String[parameters.length + 1];
                        for (int paramcount = 0; paramcount < parameters.length; paramcount++) {
                            paramValues[paramcount] = parameters[paramcount];
                        }
                        paramValues[parameters.length] = paramValue;
                        params.put(param, paramValues);
                    } else if (params.get(param) instanceof String) {
                        String[] paramValues = new String[2];
                        paramValues[0] = (String) params.get(param);
                        paramValues[1] = paramValue;
                        params.put(param, paramValues);
                    }
                } else {
                    params.put(param, paramValue);
                }
            }
        }
    }
    if (url.indexOf("?") != -1) {
        return url.substring(0, url.indexOf("?"));
    }
    return url;
}