List of utility methods to do URL is Absolute
String | getAbsoluteUrl(String base_url, String rel_url) get Absolute Url URL base = new URL(base_url); URL abs = new URL(base, rel_url); return abs.toString(); |
URL | getAbsoluteURL(String baseUrl, String url) get Absolute URL try { return new URL(url); } catch (MalformedURLException e) { try { return new URL(appendPath(baseUrl, url)); } catch (MalformedURLException e1) { throw e; |
String | getAbsoluteURL(String baseURLString, String relURlString) get Absolute URL try { URL baseURL = new URL(baseURLString); String url = baseURL.getProtocol() + "://" + baseURL.getHost() + ":" + baseURL.getPort() + toRelativeURL(relURlString); return url; } catch (IOException e) { return ""; |
String | getAbsoluteURL(String relativeURL, String baseURL) get Absolute URL if (relativeURL.equals("")) { return ""; } else { URL url; try { url = new URL(relativeURL); } catch (Exception e) { try { ... |
URL | getAbsoluteURL(String url, URL base) interprets url w.r.t base and returns the corresponding absolute URL (only if url is indeed a relative URL ; returns the original url otherwise) URL res = null; if (url.startsWith("http:") || url.startsWith("file:") || url.startsWith("ftp:")) { try { res = new URL(url); return res; } catch (MalformedURLException mue) { System.err.println("Error:Utils.getAbsoluteURL():malformed URL: " + url); mue.printStackTrace(); ... |
URL | getAbsoluteUrl(URL baseUrl, String relativeUrl) get Absolute Url if (isAbsolute(relativeUrl)) { return new URL(relativeUrl); return new URL(baseUrl, relativeUrl); |
String | getAbsoluteUrlFromFile(final String file) Converts a file String to a valid URL String. Example: index.html converts to file://C:/path/to/file/index.html .
if (file == null) { throw new IllegalArgumentException("file must not be null"); final URL url = ClassLoader.getSystemResource(file); if (url == null) { throw new NullPointerException("url from file=" + file + " is null"); return url.toString(); ... |
String | getAbsoluteUrlPathFromFile(String file) Removes file name from URL string String url = getAbsoluteUrlFromFile(file); return url.substring(0, url.lastIndexOf('/')); |
boolean | isAbsolute(String uri) is Absolute if (isWindowsDrive(uri)) { return true; } else if (hasScheme(uri)) { uri = chopScheme(uri); if (startsWith(uri, LINUX_FILE_SEP) || startsWith(uri, WIN_FILE_SEP) || isWindowsDrive(uri)) { return true; return false; |
boolean | isAbsolute(String uri) is Absolute int colon = uri.indexOf(':'); if (colon < 1) return false; return true; |