Java URI to Relative URI resolveRelativeURI(String baseURI, String uriRef)

Here you can find the source of resolveRelativeURI(String baseURI, String uriRef)

Description

Constructs an absolute URI from the given URI reference and a base URI.

License

Apache License

Parameter

Parameter Description
baseURI The base URI; if present, it must be an absolute URI.
uriRef A URI reference that may be relative to the given base URI.

Return

The resulting URI.

Declaration

public static URI resolveRelativeURI(String baseURI, String uriRef) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URI;

public class Main {
    /**/*w  w  w. j a  v  a  2 s .  c o m*/
     * Constructs an absolute URI from the given URI reference and a base URI.
     * 
     * @see <a href="http://tools.ietf.org/html/rfc3986#section-5.2">RFC 3986,
     *      5.2</a>
     * 
     * @param baseURI
     *            The base URI; if present, it must be an absolute URI.
     * @param uriRef
     *            A URI reference that may be relative to the given base URI.
     * @return The resulting URI.
     * 
     */
    public static URI resolveRelativeURI(String baseURI, String uriRef) {
        URI uri = (null != baseURI) ? URI.create(baseURI) : URI.create("");
        if (null != baseURI && null == uri.getScheme()) {
            throw new IllegalArgumentException("Base URI has no scheme component: " + baseURI);
        }
        return uri.resolve(uriRef);
    }
}

Related

  1. resolveFileUri(String fullPageURI, File rootPath)
  2. resolvePartUri(URI sourcePartUri, URI targetUri)
  3. resolvePath(URI root, String subPath)
  4. resolvePort(URI uri)
  5. resolveReferenceStartingWithQueryString(final URI baseURI, final URI reference)
  6. resolveRelativeURI(URI base, String rel)
  7. resolveURI(File base_dir, URI uri)
  8. resolveURI(final String path)
  9. resolveURI(String uri)