//
import java.io.*;
import java.net.*;

public class VerifieURL {

 public static void verifie(URLConnection u)
 throws IOException
    {if (!u.getContentType().equals("text/html")) 
       {System.out.println("seuls les text/html sont verifies.");
        System.exit(0);};
     DataInputStream dis =new DataInputStream(u.getInputStream());
     String s=dis.readLine();
     String motif1="<A HREF=";
     String motif2=">";
     String ref;
     int i,j;
     while (s!=null)
       {i=s.indexOf(motif1);
        if (i!=-1) 
          {j=s.indexOf(motif2);
           ref=s.substring(i+motif1.length()+1,j-1);
           try 
             {ValiditeURLConnexion.test(ref);}
           catch (IOException e)
             {System.out.println("Wrong URL : "+ref);}
           }
        s=dis.readLine();}
     dis.close();
    }
       
  public static void main(String args[])
  throws MalformedURLException, IOException
    {if (args.length!=1) 
      {System.out.println("Usage : java verifieURL ");
       System.exit(0);}
     URLConnection c=null; 
     try 
        {URL url =new URL(args[0]);
         ValiditeURLConnexion.test(url);
         c= url.openConnection();}
     catch (IOException e)
         {System.out.println("Wrong URL : "+args[0]);
          System.exit(0);}
     verifie(c);
    }
}