title: Processing URLs found in HTML page
body: <p>I have a <code>HTML</code> page. I parse it using <code>jsoup</code>, here is the part of the code</p>
  
  <pre><code>Document doc = Jsoup.parse(content);
  
  org.jsoup.select.Elements images = doc.select("[src]");
  
  for(org.jsoup.nodes.Element img : images) {
      // Here I need to determine the type of the URL and convert it to absolute URL
  }
  </code></pre>
  
  <p>I need to change all URLs inside this HTML to absolute URLs.
  The problem is that, <code>src</code> attribute of <code>&lt;img&gt; &lt;/img&gt;</code> could be of type, if host if <code>www.example.com</code>:</p>
  
  <pre><code> 1. http://www.example.com/images/1.png
   2. http://example.com/images/1.png
   3. www.example.com/images/1.png
   4. example.com/images/1.png
   5. /example.com/images/1.png
   6. //example.com/images/1.png
   7. /images/1.png
  </code></pre>
  
  <p>I came up with this list, while I was testing, so I should support them all. So I need some function which will outputs me the absolute URL(<code>http://www.example.com/images/1.png</code>) for all inputs listed above.
  The problem is even complicated when the URL is for resource from another location, for example <code>haha.com/images/1.png</code>.</p>
  
  <p>So I need a way to determine the type of URL, something like:</p>
  
  <ul>
  <li>relative(<code>/images/1.png</code>);</li>
  <li>absolute(<code>http://example.com/images/1.png</code>);</li>
  <li>protocol relative(<code>example.com/images/1.png</code>).</li>
  </ul>
  
  <p>What is the best approach to solve this problem in java? Thank you.</p>