* @param url Target URL.
* @return The HTML document.
* @throws Exception
*/
Document loadURL(URL url) throws Exception{
SAXBuilder builder=new SAXBuilder();
Document xml=null;
HttpURLConnection con=(HttpURLConnection) url.openConnection();
con.setInstanceFollowRedirects(true);
InputStream in;
try
{
in = con.getInputStream();
}
catch(Exception e)
{
in=con.getErrorStream();
}
String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
if(encoding.equals("gzip"))
{
in=new GZIPInputStream(con.getInputStream());
encoding="UTF-8";
}
String body = IOUtils.toString(in, encoding).replace(" & ", "&");
for(int i=0;i<this.attempts;i++)
{
try
{
xml=(Document) builder.build(new StringReader(body));
i+=this.attempts+1;
}
catch(JDOMParseException ex)
{
int line=ex.getLineNumber();