Makes the given URI relative to a relative URI against the URI represented by this instance. @param relative the URI which has to be relativized against this URI. @return the relative URI.
(URI relative)
| 1437 | * @return the relative URI. |
| 1438 | */ |
| 1439 | public URI relativize(URI relative) { |
| 1440 | if (relative.opaque || opaque) { |
| 1441 | return relative; |
| 1442 | } |
| 1443 | |
| 1444 | if (scheme == null ? relative.scheme != null : !scheme |
| 1445 | .equals(relative.scheme)) { |
| 1446 | return relative; |
| 1447 | } |
| 1448 | |
| 1449 | if (authority == null ? relative.authority != null : !authority |
| 1450 | .equals(relative.authority)) { |
| 1451 | return relative; |
| 1452 | } |
| 1453 | |
| 1454 | // normalize both paths |
| 1455 | String thisPath = normalize(path); |
| 1456 | String relativePath = normalize(relative.path); |
| 1457 | |
| 1458 | /* |
| 1459 | * if the paths aren't equal, then we need to determine if this URI's |
| 1460 | * path is a parent path (begins with) the relative URI's path |
| 1461 | */ |
| 1462 | if (!thisPath.equals(relativePath)) { |
| 1463 | // if this URI's path doesn't end in a '/', add one |
| 1464 | if (!thisPath.endsWith("/")) { //$NON-NLS-1$ |
| 1465 | thisPath = thisPath + '/'; |
| 1466 | } |
| 1467 | /* |
| 1468 | * if the relative URI's path doesn't start with this URI's path, |
| 1469 | * then just return the relative URI; the URIs have nothing in |
| 1470 | * common |
| 1471 | */ |
| 1472 | if (!relativePath.startsWith(thisPath)) { |
| 1473 | return relative; |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | URI result = new URI(); |
| 1478 | result.fragment = relative.fragment; |
| 1479 | result.query = relative.query; |
| 1480 | // the result URI is the remainder of the relative URI's path |
| 1481 | result.path = relativePath.substring(thisPath.length()); |
| 1482 | result.setSchemeSpecificPart(); |
| 1483 | return result; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * Resolves the given URI {@code relative} against the URI represented by |
nothing calls this directly
no test coverage detected