Example usage for java.net URI getFragment

List of usage examples for java.net URI getFragment

Introduction

In this page you can find the example usage for java.net URI getFragment.

Prototype

public String getFragment() 

Source Link

Document

Returns the decoded fragment component of this URI.

Usage

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static boolean areEqual(URI lhs, URI rhs) {
    Validate.notNull(lhs, "lhs");
    Validate.notNull(rhs, "rhs");

    URI lhsCopy;/*  w  w  w. j  ava 2s .  c  om*/
    URI rhsCopy;
    try {
        lhsCopy = new URI(lhs.getScheme(), lhs.getUserInfo(), lhs.getHost(), URIUtils.getPort(lhs),
                lhs.getPath(), lhs.getQuery(), lhs.getFragment());
        rhsCopy = new URI(rhs.getScheme(), rhs.getUserInfo(), rhs.getHost(), URIUtils.getPort(rhs),
                rhs.getPath(), rhs.getQuery(), rhs.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to transform uri for equality check", e);
    }

    return lhsCopy.equals(rhsCopy);
}

From source file:info.rmapproject.webapp.utils.WebappUtils.java

/**
 * Remove the namespace URL and just return the term
 *
 * @param url the url//from   w w w . ja  v a 2 s. c  om
 * @return the term
 */
public static String removeNamespace(String url) {
    try {
        URI uri = new URI(url);
        String term = null;

        if (url.contains("#")) {
            term = uri.getFragment();
        } else if (url.contains("/")) {
            term = url.substring(url.lastIndexOf("/") + 1);
        }
        return term;
    } catch (URISyntaxException e) {
        //it's not a uri... that's OK, send it back...
        return url;
    }
}

From source file:URISupport.java

/**
 * Creates a URI with the given query//from  w w w. j  a va  2s. c  o  m
 */
public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query,
            uri.getFragment());
}

From source file:org.apache.taverna.robundle.Bundles.java

public static Path uriToBundlePath(Bundle bundle, URI uri) {
    URI rootUri = bundle.getRoot().toUri();
    uri = relativizeFromBase(uri, rootUri);
    if (uri.isAbsolute() || uri.getFragment() != null)
        return null;
    return bundle.getFileSystem().provider().getPath(rootUri.resolve(uri));
}

From source file:com.google.caja.precajole.StaticPrecajoleMap.java

public static String normalizeUri(String uri) {
    try {/* w  w w.j  a va  2s  .  c  o m*/
        URI u = new URI(uri).normalize();
        if (u.getHost() != null) {
            u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(),
                    u.getPath(), u.getQuery(), u.getFragment());
        } else if (u.getScheme() != null) {
            u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment());
        }
        return u.toString();
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:URISupport.java

public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
    return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(),
            bindAddr.getQuery(), bindAddr.getFragment());
}

From source file:com.ibm.jaggr.core.util.PathUtil.java

public static URI stripJsExtension(URI value) throws URISyntaxException {
    if (value == null) {
        return null;
    }//  w w  w .j  ava2s .c  o m
    return value.getPath().endsWith(".js") ? //$NON-NLS-1$
            new URI(value.getScheme(), value.getAuthority(),
                    value.getPath().substring(0, value.getPath().length() - 3), value.getQuery(),
                    value.getFragment())
            : value;
}

From source file:org.apache.hadoop.hive.ql.exec.ArchiveUtils.java

/**
 * Makes sure, that URI points to directory by adding slash to it.
 * Useful in relativizing URIs.//  w  w w  .  java 2  s. c o  m
 */
public static URI addSlash(URI u) throws HiveException {
    if (u.getPath().endsWith("/")) {
        return u;
    } else {
        try {
            return new URI(u.getScheme(), u.getAuthority(), u.getPath() + "/", u.getQuery(), u.getFragment());
        } catch (URISyntaxException e) {
            throw new HiveException("Couldn't append slash to a URI", e);
        }
    }
}

From source file:org.apache.hadoop.yarn.server.webproxy.ProxyUriUtils.java

/**
 * Get a proxied URI for the original URI.
 * @param originalUri the original URI to go through the proxy, or null if
 * a default path "/" can be used. /*from   w ww  .  j a va  2  s .c  om*/
 * @param proxyUri the URI of the proxy itself, scheme, host and port are used.
 * @param id the id of the application
 * @return the proxied URI
 */
public static URI getProxyUri(URI originalUri, URI proxyUri, ApplicationId id) {
    try {
        String path = getPath(id, originalUri == null ? "/" : originalUri.getPath());
        return new URI(proxyUri.getScheme(), proxyUri.getAuthority(), path,
                originalUri == null ? null : originalUri.getQuery(),
                originalUri == null ? null : originalUri.getFragment());
    } catch (URISyntaxException e) {
        throw new RuntimeException("Could not proxify " + originalUri, e);
    }
}

From source file:org.apache.hadoop.fs.s3native.S3xLoginHelper.java

/**
 * Canonicalize the given URI.//from   w w  w .  ja  v  a2s  . c  o m
 *
 * This strips out login information.
 *
 * @return a new, canonicalized URI.
 */
public static URI canonicalizeUri(URI uri, int defaultPort) {
    if (uri.getPort() == -1 && defaultPort > 0) {
        // reconstruct the uri with the default port set
        try {
            uri = new URI(uri.getScheme(), null, uri.getHost(), defaultPort, uri.getPath(), uri.getQuery(),
                    uri.getFragment());
        } catch (URISyntaxException e) {
            // Should never happen!
            throw new AssertionError("Valid URI became unparseable: " + uri);
        }
    }

    return uri;
}