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

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:Main.java

public static Map<String, List<String>> getLocationFromUrl(String string) {
    try {/*from   w ww . ja  v a 2 s .  co m*/
        Map<String, List<String>> params = new HashMap<String, List<String>>();
        String[] urlParts = string.split("\\?");
        if (urlParts.length > 1) {
            String query = urlParts[1];
            for (String param : query.split("&")) {
                String[] pair = param.split("=");
                String key = URLDecoder.decode(pair[0], "UTF-8");
                String value = "";
                if (pair.length > 1) {
                    value = URLDecoder.decode(pair[1], "UTF-8");
                }

                List<String> values = params.get(key);
                if (values == null) {
                    values = new ArrayList<String>();
                    params.put(key, values);
                }
                values.add(value);
            }
        }

        return params;
    } catch (UnsupportedEncodingException ex) {
        throw new AssertionError(ex);
    }
}

From source file:com.thoughtworks.twist.mingle.core.MingleUtils.java

public static String getQueryUrlAfterEncodingURL(String fullUrl) throws UnsupportedEncodingException {
    String queryUrl = fullUrl.substring(fullUrl.indexOf('?') + 1);
    String[] split = queryUrl.split("&");
    ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
    for (String nameValuePair : split) {
        if (nameValuePair.contains("=")) {
            int indexOfEquals = nameValuePair.indexOf('=');
            String name = nameValuePair.substring(0, indexOfEquals);
            String value = nameValuePair.substring(indexOfEquals + 1);
            name = URLDecoder.decode(name, "utf-8");
            value = URLDecoder.decode(value, "utf-8");
            pairs.add(new NameValuePair(name, value));
        }//from w  w w .ja  v a 2 s  . c o  m
    }
    String formUrlEncode = EncodingUtil.formUrlEncode(pairs.toArray(new NameValuePair[0]), "utf-8");
    return formUrlEncode;
}

From source file:com.fatwire.dta.sscrawler.util.UriUtil.java

public static String extractPageName(final String uri) {
    final String qs = URI.create(uri).getRawQuery();
    if (qs != null) {
        for (final String p : qs.split("&")) {
            if (p.startsWith(UriUtil.PAGENAME_KEY)) {
                try {
                    return URLDecoder.decode(p.substring(UriUtil.PAGENAME_KEY.length()), UriUtil.UTF8);
                } catch (final UnsupportedEncodingException e) {
                    UriUtil.log.error(e, e);
                }//from  w ww.  j  av a 2s. c  om
            }
        }

    }
    return null;

}

From source file:jp.eisbahn.oauth2.server.utils.Util.java

/**
 * Decode the URL encoded string./*from   w w  w .  ja v  a2s .c o  m*/
 * @param source The URL encoded string.
 * @return The decoded original string.
 */
public static String decodeParam(String source) {
    try {
        return URLDecoder.decode(source, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:logic.core.file.FileSystemInit.java

static String getResourcePath(String resource) throws UnsupportedEncodingException {
    return URLDecoder.decode(GameRunner.class.getResource(resource).getPath(), "UTF-8");
}

From source file:io.lavagna.web.helper.Redirector.java

public static String cleanupRequestedUrl(String r) {
    try {/*from w w  w.  j ava  2  s  . c o m*/
        return (r == null || !r.startsWith("/")) ? "/" : URLDecoder.decode(r, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        return r;
    }
}

From source file:io.cloudslang.content.httpclient.build.Utils.java

public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode)
        throws UrlEncodeException {
    List<BasicNameValuePair> list = new ArrayList<>();

    String[] pairs = params.split("&");
    for (String pair : pairs) {
        String[] nameValue = pair.split("=", 2);
        String name = nameValue[0];
        String value = nameValue.length == 2 ? nameValue[1] : null;

        if (!urlEncode) {
            try {
                name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET);
                if (value != null) {
                    value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET);
                }// w  ww .  j  a v a2s  . co m
            } catch (UnsupportedEncodingException e) {
                //never happens
                throw new RuntimeException(e);
            } catch (IllegalArgumentException ie) {
                throw new UrlEncodeException(ie.getMessage(), ie);
            }
        }
        list.add(new BasicNameValuePair(name, value));
    }
    return list;
}

From source file:tsapalos.bill.play4share.UrlUtils.java

public static String getRawPageUrl(String facebookUrl) throws UnsupportedEncodingException {
    String start = "u=";
    String end = "&h=";
    // decode URL special characters
    facebookUrl = URLDecoder.decode(facebookUrl, "UTF-8");
    // clean the stripped url from page pointers
    if (facebookUrl.lastIndexOf("/#") == facebookUrl.lastIndexOf("/"))
        facebookUrl = facebookUrl.replaceAll("/#.*", "/");

    if (!facebookUrl.contains(start)) {
        return facebookUrl;
    }//  ww w .ja  va2 s.  c  o m
    String rawURL = facebookUrl.substring(facebookUrl.indexOf(start) + 2, facebookUrl.indexOf(end));
    return rawURL;
}

From source file:com.jivesoftware.sdk.util.JiveSDKUtils.java

public static String decodeUrl(String url) {
    try {// w  ww  .  ja v a  2  s . c om
        return URLDecoder.decode(url, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException uee) {
        //TODO: LOGGER
        System.err.println("Failed decoding URL using UTF-8 charset" + uee.getMessage());
        //noinspection deprecation
        return url;
    }
}

From source file:cn.edu.xmu.comm.action.json.TempParkingRegisterAction.java

@Override
public String execute() {
    try {/*w w w  . j a  v a 2  s .  c om*/
        license = URLDecoder.decode(license, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    data = new HashMap<String, Object>();
    if (parkingService.isRentCar(license))
        data.put("TYPE", "RENT");
    else
        data.put("TYPE", "TEMP");
    return SUCCESS;
}