title: Jsoup Modify Links
body: <p>I am, very new to spring and jsoup... I am using jsoup to parse an html file and copy some text inside a div tag and displaying it on my page. Now i am trying to modify the links and add exit.do to log the users out of the server. I have tried many different approach and my links dont work :( has anyone dealt with this link update before? any help is appriciated.</p>
  
  <p>here is my code.</p>
  
  <p>Thanks a lot.</p>
  
  <p>Lola</p>
  
  <pre><code>modelMap = referenceData( request, modelMap);   
  modelMap.put("externalUrl", externalUrlMap.get( request.getServletPath() ));
  modelMap.put("elementId", elementIdMap.get( request.getServletPath() ));
  
  /** Pass the url map to a string */
  String url = (String) externalUrlMap.get( request.getServletPath() );
  
  /** Pass the div map to a string */
  String eleId = (String) elementIdMap.get( request.getServletPath() );
  
  /** Retrieve and parse the document using Jsoup*/
  //URL externalUrl = new URL(url);
  //Document document = Jsoup.parse(externalUrl, 10000);
  File internalFile = new File(url);
  Document document = Jsoup.parse(internalFile, "UTF-8");
  
  /** Clean the document to prevent XSS only include tags and style below */
  //document = new Cleaner(Whitelist.basic().addTags("div", "em", "h1", "h2").addAttributes("div","class", "style")).clean(document); 
  
  /** Select privactText tags from the id */
  Element divContent = document.select(eleId).first(); 
  
  /** Returned the text inside the div tag */     
  String parsedExternalContent =  divContent.html();
  
  /** Get all links inside div tag */
  Elements links = divContent.select("a[href]");
  
  String exitUrl = "/exit?logout=true&amp;amp;uri="; 
  
  /** Loop through the links and if the links are relative path add the exit.do to the link */
  for (Element link : links) {            
      if (!link.attr("href").toLowerCase().startsWith("http://"))    {
  
          String urltext = link.attr("href");
          String exitText = "/exit?logout=true&amp;amp;uri=";
          ...
  
      }
  }               
  
  modelMap.addAttribute("parsedExternalContent", parsedExternalContent);  
  
  return new ModelAndView ("externalParserContent", modelMap);  
  </code></pre>