(URI uri)
| 737 | /// |
| 738 | /// - [http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#resolve%28java.net.URI%29](http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#resolve%28java.net.URI%29) |
| 739 | public URI resolve(URI uri) { |
| 740 | if (isOpaque() || uri.isAbsolute()) { |
| 741 | return uri; |
| 742 | } |
| 743 | String thatPath = uri.getPath(); |
| 744 | String thatQuery = uri.getQuery(); |
| 745 | String thatAuthority = uri.getAuthority(); |
| 746 | String thatFragment = uri.getFragment(); |
| 747 | try { |
| 748 | // if standalone fragment was passed. |
| 749 | if (thatFragment != null |
| 750 | && (uri.getScheme() == null && thatPath == null && thatQuery == null && thatAuthority == null)) { |
| 751 | return new URI(getScheme(), getAuthority(), getPath(), getQuery(), thatFragment); |
| 752 | } |
| 753 | if (thatAuthority != null) { |
| 754 | return new URI(getScheme(), thatAuthority, thatPath, thatQuery, thatFragment); |
| 755 | } |
| 756 | // an absolute path was passed |
| 757 | if (thatPath != null && thatPath.charAt(0) == PATH_SEPARATOR) { |
| 758 | return new URI(getScheme(), getAuthority(), thatPath, thatQuery, thatFragment); |
| 759 | } |
| 760 | // a relative path was passed |
| 761 | String thisPath = getPath(); |
| 762 | if (thisPath != null) { |
| 763 | int index = thisPath.lastIndexOf(PATH_SEPARATOR); |
| 764 | if (index != -1) { |
| 765 | thisPath = thisPath.substring(index); |
| 766 | } |
| 767 | } |
| 768 | thisPath += PATH_SEPARATOR + thatPath; |
| 769 | return new URI(getScheme(), getAuthority(), thisPath, thatQuery, thatFragment).normalize(); |
| 770 | } catch (URISyntaxException use) { |
| 771 | // since both uri's are already validated, should never get here |
| 772 | throw new IllegalArgumentException(use.getMessage()); |
| 773 | } |
| 774 | |
| 775 | } |
| 776 | |
| 777 | /// Normalize a URI by removing any "./" segments, and "path/../" segments. |
| 778 | /// |
no test coverage detected