List of utility methods to do URL Resolve
URL | resolveResourceURL(Class> base, String resource) Resolve a resource. try { URL url = new URL(resource); return url; } catch (MalformedURLException e) { Logger.getAnonymousLogger().fine(String .format("The resource is not a valid URL: %s\n Trying to find a corresponding file", resource)); File configFile = new File(resource); ... |
URL | resolveRootUrl(Class knownClass) Useful in cases where we need to deal with files/resources in the test compilation output dir of the project. final String knownClassFileName = '/' + knownClass.getName().replace('.', separatorChar) + ".class"; final URL knownClassFileUrl = knownClass.getResource(knownClassFileName); final String knownClassFileUrlString = knownClassFileUrl.toExternalForm(); String rootUrlString = knownClassFileUrlString.substring(0, knownClassFileUrlString.lastIndexOf(separatorChar)); final String packageName = knownClass.getPackage().getName(); for (String packageNamePart : packageName.split("\\.")) { rootUrlString = rootUrlString.substring(0, rootUrlString.lastIndexOf(separatorChar)); ... |
String | resolveUrl(String url, Properties properties) Look for thinklab.resource.path in properties, if found scan the path to resolve the passed name as a file url. String ret = url; if (ret.contains(":/")) return ret; String prop = "."; for (String path : prop.split(";")) { if (path.startsWith("http") && path.contains("/")) { ret = path + url; break; ... |
URL | resolveURL(String urlValue) First try to use the externalURLValue as a URL string and if this fails to produce a valid URL treat the externalURLValue as a system property name from which to obtain the URL string. if (urlValue == null) return null; URL externalURL = null; try { externalURL = new URL(urlValue); } catch (MalformedURLException e) { String urlProperty = System.getProperty(urlValue); if (urlProperty == null) ... |
URL | resolveURL(URL base, String target) Resolve relative URL-s and fix a few java.net.URL errors in handling of URLs with embedded params and pure query targets. target = target.trim(); if (target.startsWith("?")) { return fixPureQueryTargets(base, target); return new URL(base, target); |
URL | resolveURL(URL contextURL, String url) resolve URL if (url == null) return null; try { if (contextURL == null) return normalizeToURL(url); return new URL(contextURL, url); } catch (MalformedURLException e) { return null; ... |
URL | resolveURL(URL url) Returns a resolved equivalent of url, use with the platform relative urls try { return FileLocator.resolve(url); } catch (IOException e) { return null; |
URI | resolveWsURI(String url) resolve Ws URI return url.startsWith("http") ? URI.create(url.replaceFirst("http", "ws")) : url.startsWith("https") ? URI.create(url.replaceFirst("https", "wss")) : URI.create(url); |
URL | resolveXmlConfigUrl(@Nullable URL defaultXmlConfigUrl) resolve Xml Config Url final String plainConfigUrl = System.getProperty("log4j.configuration", defaultXmlConfigUrl != null ? defaultXmlConfigUrl.toExternalForm() : null); if (plainConfigUrl == null) { throw new IllegalArgumentException("The system property 'log4j.configuration' is not set."); try { return new URL(plainConfigUrl); } catch (final MalformedURLException e) { ... |
String | reverseUrl(String urlString) Reverses a url's domain. return reverseUrl(new URL(urlString)); |