Resolve a relative URI by merging it with this URI. @param uri a URI to resolve against this URI. @return a new URI created by merging given URI with this URI. @see http://docs.oracle.com/javase/6/docs/ap
(URI uri)
| 818 | * @see <a href="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</a> |
| 819 | */ |
| 820 | public URI resolve(URI uri) { |
| 821 | if (isOpaque() || uri.isAbsolute()) { |
| 822 | return uri; |
| 823 | } |
| 824 | String thatPath = uri.getPath(); |
| 825 | String thatQuery = uri.getQuery(); |
| 826 | String thatAuthority = uri.getAuthority(); |
| 827 | String thatFragment = uri.getFragment(); |
| 828 | try { |
| 829 | // if standalone fragment was passed. |
| 830 | if (thatFragment != null |
| 831 | && (uri.getScheme() == null && thatPath == null && thatQuery == null && thatAuthority == null)) { |
| 832 | return new URI(getScheme(), getAuthority(), getPath(), getQuery(), thatFragment); |
| 833 | } |
| 834 | if (thatAuthority != null) { |
| 835 | return new URI(getScheme(), thatAuthority, thatPath, thatQuery, thatFragment); |
| 836 | } |
| 837 | // an absolute path was passed |
| 838 | if (thatPath != null && thatPath.charAt(0) == PATH_SEPARATOR) { |
| 839 | return new URI(getScheme(), getAuthority(), thatPath, thatQuery, thatFragment); |
| 840 | } |
| 841 | // a relative path was passed |
| 842 | String thisPath = getPath(); |
| 843 | if (thisPath != null) { |
| 844 | int index = thisPath.lastIndexOf(PATH_SEPARATOR); |
| 845 | if (index != -1) { |
| 846 | thisPath = thisPath.substring(index); |
| 847 | } |
| 848 | } |
| 849 | thisPath += PATH_SEPARATOR + thatPath; |
| 850 | return new URI(getScheme(), getAuthority(), thisPath, thatQuery, thatFragment).normalize(); |
| 851 | } catch (URISyntaxException use) { |
| 852 | // since both uri's are already validated, should never get here |
| 853 | throw new IllegalArgumentException(use.getMessage()); |
| 854 | } |
| 855 | |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Normalize a URI by removing any "./" segments, and "path/../" segments. |