Create a relative URI object against this URI, given the uri parameter. @param uri @return @see http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29
(URI uri)
| 784 | * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29">http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29</a> |
| 785 | */ |
| 786 | public URI relativize(URI uri) { |
| 787 | if (isOpaque() || uri.isOpaque()) { |
| 788 | return uri; |
| 789 | } |
| 790 | if (getScheme() == null || uri.getScheme() == null || getScheme().equals(uri.getScheme()) == false) { |
| 791 | return uri; |
| 792 | } |
| 793 | String thisAuthority = null; |
| 794 | String thatAuthority = null; |
| 795 | String thisPath = null; |
| 796 | String thatPath = null; |
| 797 | if ((thisAuthority = getAuthority()) == null || (thatAuthority = uri.getAuthority()) == null |
| 798 | || thisAuthority.equals(thatAuthority) == false) { |
| 799 | return uri; |
| 800 | } |
| 801 | if ((thisPath = getPath()) == null || (thatPath = uri.getPath()) == null |
| 802 | || thatPath.startsWith(thisPath + PATH_SEPARATOR) == false) { |
| 803 | return uri; |
| 804 | } |
| 805 | try { |
| 806 | return new URI(null, null, thatPath.substring(thisPath.length() + 1), uri.getQuery(), uri.getFragment()); |
| 807 | } catch (URISyntaxException e) { |
| 808 | // Since the two URIs are pre-validated, we should never get here. |
| 809 | throw new IllegalArgumentException(e.getMessage()); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Resolve a relative URI by merging it with this URI. |