Java URI to Relative URI resolveUri(URI baseUri, String resourceUriStr)

Here you can find the source of resolveUri(URI baseUri, String resourceUriStr)

Description

resolve Uri

License

Common Public License

Declaration

public static URI resolveUri(URI baseUri, String resourceUriStr)
            throws URISyntaxException, MalformedURLException 

Method Source Code

//package com.java2s;
//License from project: Common Public License 

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static URI resolveUri(URI baseUri, String resourceUriStr)
            throws URISyntaxException, MalformedURLException {
        URI targetUri = null;//from  w  w w. ja  v  a  2 s . co  m
        if (baseUri.toString().startsWith("jar:")) {
            URI temp = new URI(resourceUriStr);
            if (temp.isAbsolute()) {
                targetUri = temp;
            } else {
                URL targetUrl = new URL(baseUri.toURL(), resourceUriStr);
                targetUri = targetUrl.toURI();
            }
        } else {
            targetUri = baseUri.resolve(resourceUriStr);
        }
        return targetUri;
    }
}

Related

  1. resolveRelativeURI(URI base, String rel)
  2. resolveURI(File base_dir, URI uri)
  3. resolveURI(final String path)
  4. resolveURI(String uri)
  5. resolveUri(URI base, String rel)
  6. resolveUri(URI baseUri, URI requestedUri, URI matchedUri)