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:com.dmsl.anyplace.utils.NetworkUtils.java

public static String encodeURL(String urlStr) throws URISyntaxException, MalformedURLException {
    URL url = new URL(urlStr);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    url = uri.toURL();/*ww  w .j a v  a2  s. c  o  m*/
    return url.toString();
}

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

/**
 * URL??key-value??/*from   w  w  w  . ja  va 2s  .  co  m*/
 * 
 * @param url
 *            ?url
 * @return key-value??
 */
public static Bundle parseUrl(String url) {
    url = url.replace("#", "?");
    try {
        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:org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider.java

/**
 * This provider can handle uris like//from  w  w w  .  j a v  a 2 s .  co m
 * https://git-codecommit.$AWS_REGION.amazonaws.com/v1/repos/$REPO .
 * @param uri uri to parse
 * @return {@code true} if the URI can be handled
 */
public static boolean canHandle(String uri) {
    if (!hasText(uri)) {
        return false;
    }

    try {
        URL url = new URL(uri);
        URI u = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (u.getScheme().equals("https")) {
            String host = u.getHost();
            if (host.endsWith(".amazonaws.com") && host.startsWith("git-codecommit.")) {
                return true;
            }
        }
    } catch (Throwable t) {
        // ignore all, we can't handle it
    }

    return false;
}

From source file:org.apache.jmeter.protocol.http.util.ConversionUtils.java

/**
 * Checks a URL and encodes it if necessary,
 * i.e. if it is not currently correctly encoded.
 * Warning: it may not work on all unencoded URLs.
 * @param url non-encoded URL/* www . ja  v  a 2s  .  co m*/
 * @return URI which has been encoded as necessary
 * @throws URISyntaxException if parts of the url form a non valid URI
 */
public static URI sanitizeUrl(URL url) throws URISyntaxException {
    try {
        return url.toURI(); // Assume the URL is already encoded
    } catch (URISyntaxException e) { // it's not, so encode it
        return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef()); // anchor or fragment
    }
}

From source file:sce.ElasticJob.java

public static URL convertToURLEscapingIllegalCharacters(String string) {
    try {//from w  w  w  .  jav a  2 s .  c om
        String decodedURL = URLDecoder.decode(string, "UTF-8");
        URL url = new URL(decodedURL);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        return uri.toURL();
    } catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) {
        e.printStackTrace(System.out);
        return null;
    }
}

From source file:eu.trentorise.smartcampus.network.RemoteConnector.java

private static String normalizeURL(String uriString) throws RemoteException {
    try {//from   w  w  w . j av  a2 s  .c  o  m
        URL url = new URL(uriString);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        uriString = uri.toURL().toString();
    } catch (Exception e) {
        throw new RemoteException(e.getMessage());
    }
    return uriString;
}

From source file:com.iStudy.Study.Renren.Util.java

/**
 * ?URL??key-value/*w w  w  .  j a  v  a  2 s . c om*/
 * 
 * @param url
 * @return
 */
public static Bundle parseUrl(String url) {
    url = url.replace("rrconnect", "http");
    url = url.replace("#", "?");
    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:org.osaf.cosmo.dav.caldav.report.MultigetReport.java

private static URL normalizeHref(URL context, String href) throws DavException {
    URL url = null;
    try {/*  www  .j  a v a  2s. c o  m*/
        url = new URL(context, href);
        // check that the URL is escaped. it's questionable whether or
        // not we should all unescaped URLs, but at least as of
        // 10/02/2007, iCal 3.0 generates them
        url.toURI();
        return url;
    } catch (URISyntaxException e) {
        try {
            URI escaped = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                    url.getRef());
            return new URL(escaped.toASCIIString());
        } catch (Exception e2) {
            throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new BadRequestException("Malformed href " + href + ": " + e.getMessage());
    }
}

From source file:com.skcraft.launcher.util.HttpRequest.java

/**
 * URL may contain spaces and other nasties that will cause a failure.
 *
 * @param existing the existing URL to transform
 * @return the new URL, or old one if there was a failure
 *///  w ww . j ava 2  s .c  om
private static URL reformat(URL existing) {
    try {
        URL url = new URL(existing.toString());
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();
        return url;
    } catch (MalformedURLException e) {
        return existing;
    } catch (URISyntaxException e) {
        return existing;
    }
}

From source file:org.wso2.carbon.identity.sso.saml.common.Util.java

/**
 * Generate OpenID for a given user./*from   ww  w.j  a va  2 s. c  o m*/
 *
 * @param user User
 * @return Generated OpenID
 * @throws org.wso2.carbon.identity.base.IdentityException
 */
public static String generateOpenID(String user) throws IdentityException {
    String openIDUserUrl = null;
    String openID = null;
    URI uri = null;
    URL url = null;
    openIDUserUrl = IdentityUtil.getProperty(IdentityConstants.ServerConfig.OPENID_USER_PATTERN);
    user = normalizeUrlEncoding(user);
    openID = openIDUserUrl + user;
    try {
        uri = new URI(openID);
    } catch (URISyntaxException e) {
        throw new IdentityException("Invalid OpenID URL :" + openID, e);
    }
    try {
        url = uri.normalize().toURL();
        if (url.getQuery() != null || url.getRef() != null) {
            throw new IdentityException("Invalid user name for OpenID :" + openID);
        }
    } catch (MalformedURLException e) {
        throw new IdentityException("Malformed OpenID URL :" + openID, e);
    }
    openID = url.toString();
    return openID;
}