import java.net.*;
import java.io.*;
import java.util.*;

/** This class does some downloading of tools.
 *  @author matth3wbishop<at>yahoo!<dot>com 
 */
 
  
public class GetSomething extends Object
{
  //--------------------------------------------
  private static String NEWLINE = System.getProperty("line.separator");
  
  public GetSomething()
  {

  } //-- constr: ()


  //--------------------------------------------
  //-- get somethings from the web
  public static void main(String[] args) throws Exception
  {
    String sPuttyUrl = "http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe";
    String sPuttySftpUrl = "http://the.earth.li/~sgtatham/putty/latest/x86/psftp.exe";
    String sPuttyScpUrl = "http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe";
    String sPuttyGenUrl = "http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe";
    String sFirefoxUrl =
     "http://download.mozilla.org/?product=firefox-1.0.7&os=win&lang=en-US";
    String sBumbleFileScriptUrl = "http://bumble.sf.net/eg/bat/ub.bat";
    String sBlueJUrl = "http://www.bluej.org/download/files/bluejsetup-205.exe";
    String sGetSomethingClassUrl = "http://bumble.sf.net/lang/GetSomething.class";
    String sGetSomethingUrl = "http://bumble.sf.net/lang/GetSomething.java";
    String sWebDownloadClassUrl = "http://bumble.sf.net/lang/WebDownload.class";
    String sWebDownloadUrl = "http://bumble.sf.net/lang/WebDownload.java";
    String sClassInfoClassUrl = "http://bumble.sf.net/lang/ClassInfo.class";
    String sClassInfoUrl = "http://bumble.sf.net/lang/ClassInfo.java";


    
    StringBuffer sbUsageMessage = new StringBuffer("");
    sbUsageMessage.append("usage: java GetSomething x");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" choices:");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" a - Putty ssh program");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" b - Putty secure ftp program");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" c - Firefox browser ");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" d - Putty bumble.sf.net script");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" e - BlueJ a minimalist java editor");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" f - A java class inspector");
    sbUsageMessage.append(NEWLINE);


    if (args.length == 0)
    {	    
      System.out.println(sbUsageMessage);
      System.exit(-1);
    }

    String sChoice = new String(args[0]);
    String sUrl = new String("");

    Runtime rtMachine;
    rtMachine = Runtime.getRuntime();

    if (sChoice.equalsIgnoreCase("a"))
     { sUrl = sPuttyUrl; }
    if (sChoice.equalsIgnoreCase("b"))
     { sUrl = sPuttySftpUrl; }
    if (sChoice.equalsIgnoreCase("c"))
     { sUrl = sFirefoxUrl; }
    if (sChoice.equalsIgnoreCase("d"))
     { sUrl = sBumbleFileScriptUrl; }
    if (sChoice.equalsIgnoreCase("e"))
     { sUrl = sBlueJUrl; }
    if (sChoice.equalsIgnoreCase("f"))
     { sUrl = sClassInfoClassUrl; }

    StringBuffer sMessage = new StringBuffer("");

    WebDownload wdResource = new WebDownload(sUrl);
    sMessage.append("Attempting to get " + wdResource.getUrl());
    sMessage.append(NEWLINE);
    System.out.println(sMessage);

    wdResource.download();
    System.out.println(wdResource.printStatistics());
  } //-- main()
  
} //-- GetSomething class
