title: Recursively retrieving links from web page in Java
body: <p>I'm working on a simplified website downloader (Programming Assignment) and I have to recursively go through the links in the given url and download the individual pages to my local directory. </p>
  
  <p>I already have a function to retrieve all the hyperlinks(href attributes) from a single page, <code>Set&lt;String&gt; retrieveLinksOnPage(URL url)</code>. This function returns a vector of hyperlinks. I have been told to download pages up to level 4. (Level 0 being the Home Page) Therefore I basically want to retrieve all the links in the site but I'm having difficulty coming up with the recursion algorithm. In the end, I intend to call my function like this : </p>
  
  <p><code>retrieveAllLinksFromSite("http://www.example.com/ldsjf.html",0)</code></p>
  
  <pre><code>Set&lt;String&gt; Links=new Set&lt;String&gt;();
  Set&lt;String&gt; retrieveAllLinksFromSite (URL url, int Level,Set&lt;String&gt; Links)
  {
      if(Level==4)
         return;
      else{
  
          //retrieveLinksOnPage(url,0);
          //I'm pretty Lost Actually!
          }
  
  }
  </code></pre>
  
  <p>Thanks!</p>