Example usage for java.net URL getQuery

List of usage examples for java.net URL getQuery

Introduction

In this page you can find the example usage for java.net URL getQuery.

Prototype

public String getQuery() 

Source Link

Document

Gets the query part of this URL .

Usage

From source file:Main.java

public static Bundle parseUrl(String url) {
    url = url.replace("#", "?");
    try {/*from   w ww.  ja  v  a2 s  .  c  o  m*/
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        Bundle ref = decodeUrl(u.getRef());
        if (ref != null)
            b.putAll(ref);
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 * //  www.j  a  v a 2s .  co m
 * @param url the URL to parse
 * @return a dictionary bundle of keys and values
 */
public static Bundle parseUrl(String url) {
    // hack to prevent MalformedURLException
    url = url.replace("fbconnect", "http");
    try {
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        b.putAll(decodeUrl(u.getRef()));
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

public static String getQueryValue(String url, String name) {
    try {//from w w  w.  j a va 2s  .c  o  m
        URL dUrl = new URL("http://" + url);
        Map<String, String> query = getQueryMap(dUrl.getQuery());
        return query.get(name);

    } catch (Exception e) {
    }

    return null;
}

From source file:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 *
 * @param url the URL to parse/*from w  ww .ja  v a2 s.c om*/
 * @return a dictionary bundle of keys and values
 */
@Deprecated
public static Bundle parseUrl(String url) {
    // hack to prevent MalformedURLException
    url = url.replace("fbconnect", "http");
    try {
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        b.putAll(decodeUrl(u.getRef()));
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

public static String getParameterFromUrl(String url, String param) {
    //Log.d(TAG, "getParameterFromUrl:"+url+"-p:"+param);
    URL iurl;
    try {/* w  ww. jav  a2  s  . c o m*/
        iurl = new URL(url);
        String iquery = iurl.getQuery();
        if (iquery == null) {
            return "";
        } else {
            String[] q = iquery.split("&");
            for (int i = 0; i < q.length; i++) {
                String[] xx = q[i].split("=");
                if (xx[0].equals(param) && xx.length > 1) {
                    return xx[1];
                }
            }
            return "";
        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    }
}

From source file:com.mmj.app.common.util.URLUtils.java

@SuppressWarnings("unchecked")
public static Map<String, Object> getParams(URL url) {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    String query = url.getQuery();
    if (query == null) {
        return paramMap;
    }//ww  w . j  a v  a 2 s  . com
    String[] params = query.split(split);
    for (String param : params) {
        if (StringUtils.isEmpty(param)) {
            continue;
        }
        String name = param.substring(0, param.indexOf("="));
        String value = param.substring(param.indexOf("=") + 1, param.length());
        if (paramMap.containsKey(name)) {
            Object object = paramMap.get(name);
            List<String> values = null;
            if (object instanceof List) {
                values = (List<String>) object;
            } else {
                values = new ArrayList<String>();
                values.add(object.toString());
            }
            values.add(value);
            paramMap.put(name, values);
        } else {
            paramMap.put(name, value);
        }
    }
    return paramMap;
}

From source file:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 * /*  w ww . j a  v a  2s.  co  m*/
 * @param url
 *            the URL to parse
 * @return a dictionary bundle of keys and values
 */
public static Map<String, String> parseUrl(String url) {
    // hack to prevent MalformedURLException
    url = url.replace("fbconnect", "http");
    try {
        URL u = new URL(url);
        Map<String, String> params = decodeUrl(u.getQuery());
        params.putAll(decodeUrl(u.getRef()));
        return params;
    } catch (MalformedURLException e) {
        return new HashMap<String, String>();
    }
}

From source file:Main.java

/**
 * @deprecated//w w  w.  java  2s  .com
 */
public static String shortNameForURL(String url) {
    if (url == null || "".equals(url))
        return "(None)";

    try {
        URL u = new URL(url);
        String rsrcName = u.getPath();
        String query = u.getQuery();
        boolean hasParams = (query != null && !"".equals(query));

        if (hasParams)
            return rsrcName + " (with parameters)";
        else
            return rsrcName;
    } catch (Exception e) {
        ;
    }

    if (url.indexOf("&") > 0)
        return url.substring(0, url.indexOf("&"));

    return url;
}

From source file:Main.java

private static String escapeUrlString(String urlString) throws MalformedURLException, URISyntaxException {
    URL url = new URL(urlString);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    return uri.toURL().toString();
}

From source file:org.apache.hadoop.mapreduce.security.SecureShuffleUtils.java

/**
 * Shuffle specific utils - build string for encoding from URL
 * @param url//w  w w.  j av a2 s .c  om
 * @return string for encoding
 */
public static String buildMsgFrom(URL url) {
    return buildMsgFrom(url.getPath(), url.getQuery(), url.getPort());
}