Example usage for java.net URL getRef

List of usage examples for java.net URL getRef

Introduction

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

Prototype

public String getRef() 

Source Link

Document

Gets the anchor (also known as the "reference") of this URL .

Usage

From source file:Main.java

public static Bundle urlToBundle(String url) {
    int index = url.indexOf("://");
    if (index >= 0) {
        url = "http://" + url.substring(index + 1);
    } else {//from w w  w  . ja  v  a2s .  co m
        url = "http://" + url;
    }

    try {
        URL e = new URL(url);
        Bundle b = decodeUrl(e.getQuery());
        b.putAll(decodeUrl(e.getRef()));
        return b;
    } catch (Throwable var4) {
        return new Bundle();
    }
}

From source file:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 * /*w  w  w  . j av  a2 s . c o 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 Bundle parseUrl(String url) {
    url = url.replace("#", "?");
    try {/*from www .j av  a 2  s.c om*/
        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

public static Bundle parseUrl(String url) {
    Bundle ret;/*from w w  w. j  av a 2 s  . c o  m*/
    url = url.replace("bdconnect", "http");
    try {
        URL urlParam = new URL(url);
        ret = decodeUrl(urlParam.getQuery());
        ret.putAll(decodeUrl(urlParam.getRef()));
        return ret;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 *
 * @param url the URL to parse//from ww  w.jav  a  2 s  .  c o  m
 * @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

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:Main.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 * /*  w  w  w.j  a  va 2  s.  c o 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

public static String encodeDocumentUrl(String urlString) {
    try {//w ww . j a  va  2  s .  c  o  m

        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.toASCIIString();

    } catch (MalformedURLException e) {
        return null;
    } catch (URISyntaxException e) {
        return null;
    }

}

From source file:com.threadswarm.imagefeedarchiver.FeedUtils.java

/**
 * Returns a hierarchical {@code URI} constructed from individual components 
 * of the supplied {@code urlString} argument.
 * <p>// w w  w.  j a v a2s .com
 * The {@code urlString} argument is first used to instantiate a {@code URL} 
 * which in turn is used to construct a {@code URI} based on the individual 
 * components of the former.  This more robust then simply calling {@code URL.toURI()}.
 * 
 * @param urlString the {@code String} based representation of a URL
 * @return a {@code URI} constructed from the individual URL components
 * @throws URISyntaxException if a valid {@code URI} cannot be constructed from the supplied {@code urlString} argument
 * @throws MalformedURLException if the {@code urlString} cannot be used to instantiate a {@code URL}
 */
public static URI getUriFromUrlString(String urlString) throws URISyntaxException, MalformedURLException {
    URL url = new URL(urlString);
    return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
}

From source file:net.turnbig.pandora.utils.Encodes.java

/**
 * URL ?, EncodeUTF-8.//  ww w  . ja v  a  2  s .  c o  m
 */
public static String uriEncode(String uri) {
    try {
        URL url = new URL(uri);
        URI temp = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), url.getRef());
        return temp.toString();
    } catch (URISyntaxException e) {
        throw Exceptions.unchecked(e);
    } catch (MalformedURLException e) {
        throw Exceptions.unchecked(e);
    }
}