Java URL is Absolute getAbsoluteURL(String relativeURL, String baseURL)

Here you can find the source of getAbsoluteURL(String relativeURL, String baseURL)

Description

get Absolute URL

License

Open Source License

Declaration

private static String getAbsoluteURL(String relativeURL, String baseURL) throws MalformedURLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    private static String getAbsoluteURL(String relativeURL, String baseURL) throws MalformedURLException {
        if (relativeURL.equals("")) {
            return "";
        } else {// ww  w .j  a  v  a  2  s  .  c  o  m
            URL url;
            // convert link to url, assume absolute url then default to relative url with base url of http://m.facebook.com
            try {
                url = new URL(relativeURL);
            } catch (Exception e) {
                // maybe its not a relative url
                try {
                    url = new URL(new URL(baseURL), relativeURL);
                } catch (Exception e2) {
                    // this isn't really an html link...its something like an email or a telephone link, just return null string
                    return "";
                }
            }
            return url.toString();
        }
    }
}

Related

  1. getAbsoluteUrl(String base_url, String rel_url)
  2. getAbsoluteURL(String baseUrl, String url)
  3. getAbsoluteURL(String baseURLString, String relURlString)
  4. getAbsoluteURL(String url, URL base)
  5. getAbsoluteUrl(URL baseUrl, String relativeUrl)
  6. getAbsoluteUrlFromFile(final String file)
  7. getAbsoluteUrlPathFromFile(String file)