List of utility methods to do URL Resolve
File | resolve(final URL url) resolve File resultFile = null; URL resolved = url; if (!url.getProtocol().equals("file")) { throw new IllegalArgumentException("Unsupported protocol: " + url.getProtocol()); try { resultFile = new File(resolved.toURI()); ... |
URL | resolve(URL base, String relUrl) Create a new absolute URL, from a provided existing absolute URL and a relative URL component. if (relUrl.startsWith("?")) relUrl = base.getPath() + relUrl; if (relUrl.indexOf('.') == 0 && base.getFile().indexOf('/') != 0) { base = new URL(base.getProtocol(), base.getHost(), base.getPort(), "/" + base.getFile()); return new URL(base, relUrl); |
URL | resolve(URL base, String uri) Resolves specified uri to a specified base URL. try { return new URL(base, uri); } catch (MalformedURLException e) { if (WINDOWS_PATH.matcher(uri).matches()) { return new URL("file:/" + uri); } else { throw e; |
String | resolveGoogleRedirect(String url) Exctract redirect target from google's redirect url String query = new URI(url).getRawQuery(); for (String param : query.split("&")) if (param.contains("=")) { String[] parts = param.split("="); if (parts.length == 2 && parts[0].equals("url")) { return URLDecoder.decode(parts[1], "UTF-8"); throw new IllegalArgumentException("google redirect not found for url: " + url); |
String | resolveHref(String baseUrl, String href) This method takes an base url and resolves the href to an url URL currentUrl = new URL(baseUrl); if (href.startsWith("http://") || href.startsWith("https://")) { return href; } else if (href.startsWith("//")) { return currentUrl.getProtocol() + ":" + href; } else if (href.startsWith("?")) { return currentUrl.getProtocol() + "://" + currentUrl.getHost() + currentUrl.getPath() + href; } else { ... |
List | resolveManifestResources(final URL manifestUrl, final List resolve Manifest Resources return resources.stream().map(name -> { try { return Optional.of(new URL(manifestUrl, "../" + name)); } catch (final MalformedURLException e) { return Optional.<URL>empty(); }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); |
String | resolvePlatformUrl(String urlspec) resolve Platform Url String result = null; try { urlspec = urlspec.replace('\\', '/'); URL url = new URL(urlspec); URL resolvedURL = FileLocator.resolve(url); result = resolvedURL.toString(); } catch (Exception e) { return result; |
URL | resolveRelativeURL(final URL primaryUrl, final String relativeLoc) Create a new URL by resolving a given relative string (such as "mydir/myfile.ext") against a given url (such as "http://www.company.com/mycontent/content.html"). String url = primaryUrl.toString(); url = url.replaceAll("\\%2[F,f]", "/"); return new URL(new URL(url), relativeLoc); |
String | resolveRelativeURL(String contextUri, String relativeUri) resolve Relative URL try { URL contextUrl = new URL(contextUri); URL absoluteUrl = new URL(contextUrl, relativeUri); String result = absoluteUrl.toString(); return result; } catch (MalformedURLException e) { throw new IllegalArgumentException(e); |
URL | resolveResourceAsURL(Class clazz, String name) Same as java.lang.Class#getResource() but works with and without jars reliably. URL url = clazz.getResource(name); if (url == null) { name = name.startsWith("/") ? name.substring(1) : "/" + name; url = clazz.getResource(name); return url; |