Helper that constructs a normalized url string usable as cache key. @param url a URL object @return the normalized string
(final URL url)
| 1276 | * @return the normalized string |
| 1277 | */ |
| 1278 | public static String normalize(final URL url) { |
| 1279 | final StringBuilder result = new StringBuilder(); |
| 1280 | result.append(url.getProtocol()) |
| 1281 | .append("://") |
| 1282 | .append(url.getHost()) |
| 1283 | .append(':') |
| 1284 | .append((url.getPort() == -1) ? url.getDefaultPort() : url.getPort()); |
| 1285 | |
| 1286 | // Compare the files. |
| 1287 | String f = url.getFile(); |
| 1288 | if (f.isEmpty()) { |
| 1289 | result.append('/'); |
| 1290 | } |
| 1291 | else { |
| 1292 | if (f.indexOf('.') > 0) { |
| 1293 | try { |
| 1294 | f = url.toURI().normalize().toURL().getFile(); |
| 1295 | } |
| 1296 | catch (final Exception ignored) { |
| 1297 | // ignore |
| 1298 | } |
| 1299 | } |
| 1300 | result.append(f); |
| 1301 | } |
| 1302 | |
| 1303 | return result.toString(); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
| 1307 | * Constructs a {@link URI} using the specified URL. |