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:org.unitedinternet.cosmo.dav.caldav.report.MultigetReport.java

private static URL normalizeHref(URL context, String href) throws CosmoDavException {
    URL url = null;/* w  w w.j a va2s .  com*/
    try {
        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.toString());
        } catch (URISyntaxException | MalformedURLException e2) {
            throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new BadRequestException("Malformed href " + href + ": " + e.getMessage());
    }
}

From source file:sce.RESTAppMetricJob.java

public static URL convertToURLEscapingIllegalCharacters(String string) {
    try {/*from   w  ww.  ja va  2  s  .c  o m*/
        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();
        return null;
    }
}

From source file:UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified port.
 * @param u the URL on which to base the returned URL
 * @param newPort the new port to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified port
 * @throws MalformedURLException if there is a problem creating the new URL
 *//* w w  w.j  av a 2 s.  c om*/
public static URL getUrlWithNewPort(final URL u, final int newPort) throws MalformedURLException {
    return createNewUrl(u.getProtocol(), u.getHost(), newPort, u.getPath(), u.getRef(), u.getQuery());
}

From source file:UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified host.
 * @param u the URL on which to base the returned URL
 * @param newHost the new host to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified host
 * @throws MalformedURLException if there is a problem creating the new URL
 *///from  w  w w  . ja  va  2  s . c  o  m
public static URL getUrlWithNewHost(final URL u, final String newHost) throws MalformedURLException {
    return createNewUrl(u.getProtocol(), newHost, u.getPort(), u.getPath(), u.getRef(), u.getQuery());
}

From source file:UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified path.
 * @param u the URL on which to base the returned URL
 * @param newPath the new path to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified path
 * @throws MalformedURLException if there is a problem creating the new URL
 *///w w w . j  a v a  2 s .c o m
public static URL getUrlWithNewPath(final URL u, final String newPath) throws MalformedURLException {
    return createNewUrl(u.getProtocol(), u.getHost(), u.getPort(), newPath, u.getRef(), u.getQuery());
}

From source file:UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified protocol.
 * @param u the URL on which to base the returned URL
 * @param newProtocol the new protocol to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified protocol
 * @throws MalformedURLException if there is a problem creating the new URL
 *//*from w w w.  jav a  2  s . co  m*/
public static URL getUrlWithNewProtocol(final URL u, final String newProtocol) throws MalformedURLException {
    return createNewUrl(newProtocol, u.getHost(), u.getPort(), u.getPath(), u.getRef(), u.getQuery());
}

From source file:UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified query string.
 * @param u the URL on which to base the returned URL
 * @param newQuery the new query string to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified query string
 * @throws MalformedURLException if there is a problem creating the new URL
 *///  www .j a v a  2s.  c  o  m
public static URL getUrlWithNewQuery(final URL u, final String newQuery) throws MalformedURLException {
    return createNewUrl(u.getProtocol(), u.getHost(), u.getPort(), u.getPath(), u.getRef(), newQuery);
}

From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java

/**
 * The URL-safe version of a string is obtained by an URL encoding to a
 * string value./*from ww w.ja v  a  2  s .c o m*/
 * 
 * @throws R2RMLDataError
 * @throws MalformedURLException
 */
public static String getURLSafeVersion(String value) throws R2RMLDataError {
    if (value == null)
        return null;
    URL url = null;
    try {
        url = new URL(value);
    } catch (MalformedURLException mue) {
        // This template should be not a url : no encoding
        return value;
    }
    // No exception raised, this template is a valid url : perform
    // percent-encoding
    try {
        java.net.URI uri = new java.net.URI(url.getProtocol(), url.getAuthority(), url.getPath(),
                url.getQuery(), url.getRef());
        String result = uri.toURL().toString();
        // Percent encoding : complete with no supported char in this
        // treatment
        result = result.replaceAll("\\,", "%2C");
        return result;
    } catch (URISyntaxException e) {
        throw new R2RMLDataError("[R2RMLToolkit:getIRISafeVersion] This value " + value
                + " can not be percent-encoded because " + e.getMessage());
    } catch (MalformedURLException e) {
        throw new R2RMLDataError("[R2RMLToolkit:getIRISafeVersion] This value " + value
                + " can not be percent-encoded because " + e.getMessage());
    }
}

From source file:org.wso2.carbon.identity.provider.openid.OpenIDUtil.java

/**
 * Generate OpenID for a given user.//from w w w . ja  v a  2 s.  c  om
 *
 * @param user User
 * @return Generated OpenID
 * @throws IdentityProviderException
 */
public static String generateOpenID(String user) throws IdentityProviderException {

    ServerConfiguration serverConfig = null;
    String openIDUserUrl = null;
    String openID = null;
    URI uri = null;
    URL url = null;
    String encodedUser = null;

    serverConfig = ServerConfiguration.getInstance();
    openIDUserUrl = getOpenIDServerURL();

    encodedUser = normalizeUrlEncoding(user);

    openID = String.format(openIDUserUrl, encodedUser);

    try {
        uri = new URI(openID);
    } catch (URISyntaxException e) {
        log.error("Invalid OpenID URL :" + openID, e);
        throw new IdentityProviderException("Invalid OpenID URL :" + openID, e);
    }

    try {
        url = uri.normalize().toURL();
        if (url.getQuery() != null || url.getRef() != null) {
            log.error("Invalid user name for OpenID :" + openID);
            throw new IdentityProviderException("Invalid user name for OpenID :" + openID);
        }
    } catch (MalformedURLException e) {
        log.error("Malformed OpenID URL :" + openID, e);
        throw new IdentityProviderException("Malformed OpenID URL :" + openID, e);
    }

    openID = url.toString();

    if (log.isDebugEnabled()) {
        log.debug("OpenID generated successfully : " + openID);
    }

    return openID;
}

From source file:org.wso2.carbon.identity.provider.openid.util.OpenIDUtil.java

/**
 * Generate OpenID for a given user./*from w w w  .j  a v a  2 s  .  co m*/
 *
 * @param user User
 * @return Generated OpenID
 * @throws IdentityProviderException
 */
public static String generateOpenID(String user, String openIDUserUrl) throws IdentityException {
    String openID = null;
    URI uri = null;
    URL url = null;

    String normalizedUser = normalizeUrlEncoding(user);
    openID = String.format(openIDUserUrl, normalizedUser);

    try {
        uri = new URI(openID);
    } catch (URISyntaxException e) {
        log.error("Invalid OpenID URL :" + openID, e);
        throw new IdentityException("Invalid OpenID URL");
    }

    try {
        url = uri.normalize().toURL();
        if (url.getQuery() != null || url.getRef() != null) {
            log.error("Invalid user name for OpenID :" + openID);
            throw new IdentityException("Invalid user name for OpenID");
        }
    } catch (MalformedURLException e) {
        log.error("Malformed OpenID URL :" + openID, e);
        throw new IdentityException("Malformed OpenID URL");
    }

    openID = url.toString();

    if (log.isDebugEnabled()) {
        log.debug("OpenID generated successfully : " + openID);
    }

    return openID;
}