import java.net.*;
import java.io.*;
import java.util.*;

/** This class does some downloading of tools.
 *  This appears to be working under the jvm1.1 and jview
 *
 *  @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 - Java shortcuts scripts, and class inspector,");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" g - source code for a language program");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" h - ginipad java editor");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" i - web code");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" edit - editor source code");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" x - simple editor source code");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" k - GetSomething configuror");
    sbUsageMessage.append(NEWLINE);
    sbUsageMessage.append(" wiki - wiki source code");
    sbUsageMessage.append(NEWLINE);

    String WINDOWS_DIR = "\\windows";

    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();

    WebDownload wdResource = new WebDownload();
    wdResource.showProgress();
 
    //--------------------------------------------
    //-- PUTTY
    //--
    if (sChoice.equalsIgnoreCase("a"))
    {
      wdResource.setLocalDirectory(WINDOWS_DIR);

      wdResource.setUrl(sPuttyUrl);
      wdResource.regetExisting(false);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);

      System.exit(-1);
    }

    //--------------------------------------------
    //-- PUTTY SFTP
    //--
    if (sChoice.equalsIgnoreCase("b"))
    {
      wdResource.setLocalDirectory(WINDOWS_DIR);

      wdResource.setUrl(sPuttySftpUrl);
      wdResource.regetExisting(false);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);

      System.exit(-1);
    }

    //--------------------------------------------
    //-- FIREFOX
    //--
    if (sChoice.equalsIgnoreCase("c"))
    {
      wdResource.setUrl(sFirefoxUrl);
      wdResource.regetExisting(false);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);

      System.exit(-1);

    }

    //--------------------------------------------
    //-- UPLOAD TO BUMBLE
    //--
    if (sChoice.equalsIgnoreCase("d"))
    {
      wdResource.setLocalDirectory(WINDOWS_DIR);


      wdResource.regetExisting(false);
      wdResource.setUrl(sBumbleFileScriptUrl);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);

      System.exit(-1);

    }

    //--------------------------------------------
    //-- BLUEj
    //--
    if (sChoice.equalsIgnoreCase("e"))
    {
      sUrl = sBlueJUrl;


      wdResource.setUrl(sBlueJUrl);
      wdResource.regetExisting(false);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);
      System.exit(-1);
    }

    //--------------------------------------------
    //-- CLASS INFO
    //--
    if (sChoice.equalsIgnoreCase("f"))
    {


      wdResource.setLocalDirectory(WINDOWS_DIR);


      wdResource.setUrl("http://bumble.sf.net/lang/ClassInfo.java");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.overwrite();
      wdResource.setUrl("http://bumble.sf.net/lang/ci.bat");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.setUrl("http://bumble.sf.net/lang/ClassInfo.class");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.setUrl("http://bumble.sf.net/lang/web/jc.bat");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.setUrl("http://bumble.sf.net/lang/web/jp.bat");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.setUrl("http://bumble.sf.net/lang/web/jr.bat");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.overwrite(false);

      System.exit(-1);
    }

    //--------------------------------------------
    //-- THE GET SOMETHING CONFIGUROR
    //--
    if (sChoice.equalsIgnoreCase("k"))
    {

      wdResource.setUrl("http://bumble.sf.net/lang/web/GetSomething.java");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.overwrite();
      wdResource.setLocalDirectory(WINDOWS_DIR);
      wdResource.setUrl("http://bumble.sf.net/lang/web/gs.bat");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());

      wdResource.setUrl("http://bumble.sf.net/lang/web/GetSomething.class");
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.overwrite(false);

      System.exit(-1);
    }


    //--------------------------------------------
    //-- LANG TUTOR
    //--
    if (sChoice.equalsIgnoreCase("g"))
    {
      File fDir = new File(File.separator + "lang");
      if (!fDir.exists())
      {
        fDir.mkdir();
      }

      Vector hhUrl = new Vector();
      hhUrl.addElement("http://bumble.sf.net/lang/Record.java");
      hhUrl.addElement("http://bumble.sf.net/lang/Translation.java");
      hhUrl.addElement("http://bumble.sf.net/lang/TranslationSet.java");
      hhUrl.addElement("http://bumble.sf.net/lang/Transcription.java");
      hhUrl.addElement("http://bumble.sf.net/lang/DataFile.java");
      hhUrl.addElement("http://bumble.sf.net/lang/DownloadManager.java");
      hhUrl.addElement("http://bumble.sf.net/lang/SoundDownload.java");
      hhUrl.addElement("http://bumble.sf.net/lang/TutorApplet.java");
      hhUrl.addElement("http://bumble.sf.net/lang/TutorPanel.java");
      //hhUrl.addElement("http://bumble.sf.net/lang/.java");

      String sCurrentUrl;

      wdResource.setLocalDirectory(fDir.toString());
      //wdResource.overwrite();

      for (int ii = 0; ii < hhUrl.size(); ii++)
      {
        sCurrentUrl = (String)hhUrl.elementAt(ii);
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }
      //wdResource.overwrite(false);
      System.exit(-1);
    } //-- choice g

    //--------------------------------------------
    //-- WIKI
    //--
    if (sChoice.equalsIgnoreCase("wiki"))
    {
      File fDir = new File(File.separator + "wiki");
      if (!fDir.exists())
      {
        fDir.mkdir();
      }

      Vector hhUrl = new Vector();
      hhUrl.addElement("http://bumble.sf.net/lang/web/FAQ.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/FaqDocument.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/FolderDocument.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Folder.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/FaqItem.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Answer.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Question.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Title.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/BufferLoad.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/web-faq.txt");

      String sCurrentUrl;

      wdResource.setLocalDirectory(fDir.toString());

      for (int ii = 0; ii < hhUrl.size(); ii++)
      {
        sCurrentUrl = (String)hhUrl.elementAt(ii);
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }

      System.exit(-1);
    } //-- choice wiki

    //--------------------------------------------
    //-- THE EDITOR
    //--
    if (sChoice.equalsIgnoreCase("edit"))
    {
      File fDir = new File(File.separator + "editor");
      if (!fDir.exists())
      {
        fDir.mkdir();
      }

      Vector hhUrl = new Vector();
      hhUrl.addElement("http://bumble.sf.net/edit/EditPanel.java");
      hhUrl.addElement("http://bumble.sf.net/edit/EditApplet.java");
      hhUrl.addElement("http://bumble.sf.net/edit/WindMillLabel.java");
      hhUrl.addElement("http://bumble.sf.net/edit/make-jar.bat");
      hhUrl.addElement("http://bumble.sf.net/edit/compile.bat");
      hhUrl.addElement("http://bumble.sf.net/edit/run.bat");
      hhUrl.addElement("http://bumble.sf.net/edit/j2ssh-small.jar");
      hhUrl.addElement("http://bumble.sf.net/edit/SftpConnect.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/SftpUpload.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/run-SftpUpload.bat");
      hhUrl.addElement("http://bumble.sf.net/lang/web/compile-SftpUpload.bat");
      hhUrl.addElement("http://bumble.sf.net/lang/web/WebDownload.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Task.java");
      //hhUrl.addElement("http://bumble.sf.net/lang/.java");

      String sCurrentUrl;

      wdResource.setLocalDirectory(fDir.toString());

      for (int ii = 0; ii < hhUrl.size(); ii++)
      {
        sCurrentUrl = (String)hhUrl.elementAt(ii);
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }

      System.exit(-1);
    } //-- choice j

    //--------------------------------------------
    //-- A SIMPLE EDIT APPLICATION
    //--
    if (sChoice.equalsIgnoreCase("x"))
    {
      File fDir = new File(File.separator + "simple-editor");
      if (!fDir.exists())
      {
        fDir.mkdir();
      }

      Vector hhUrl = new Vector();
      hhUrl.addElement("http://bumble.sf.net/edit/SimpleEditPanel.java");
      hhUrl.addElement("http://bumble.sf.net/edit/EditApplet.java");
      hhUrl.addElement("http://bumble.sf.net/edit/WindMillLabel.java");
      //hhUrl.addElement("http://bumble.sf.net/edit/make-jar.bat");
      //hhUrl.addElement("http://bumble.sf.net/edit/compile.bat");
      //hhUrl.addElement("http://bumble.sf.net/edit/run.bat");
      hhUrl.addElement("http://bumble.sf.net/lang/web/WebDownload.java");
      hhUrl.addElement("http://bumble.sf.net/lang/web/Task.java");

      String sCurrentUrl;

      wdResource.setLocalDirectory(fDir.toString());

      for (int ii = 0; ii < hhUrl.size(); ii++)
      {
        sCurrentUrl = (String)hhUrl.elementAt(ii);
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }

      System.exit(-1);
    } //-- choice x


    //--------------------------------------------
    //-- GINIPAD
    if (sChoice.equalsIgnoreCase("h"))
    {
      sUrl = "http://www.mokabyte.it/ginipad/download/ginipad2_0_3.jar";
      wdResource.setUrl(sUrl);
      wdResource.regetExisting(false);
      System.out.println(wdResource.printStartMessage());
      wdResource.download();
      System.out.println(wdResource.printStatistics());
      wdResource.regetExisting(true);


      System.exit(-1);
    } //-- choice h


    //--------------------------------------------
    //-- WEB SOURCE
    //--
    if (sChoice.equalsIgnoreCase("i"))
    {
      String sDirectory =
        File.separator + "lang" + File.separator + "web";

      File fDir = new File(sDirectory);
      if (!fDir.exists())
      {
        fDir.mkdir();
      }

      String sWebDir = "http://bumble.sf.net/lang/web/";
      Vector hhUrl = new Vector();
      hhUrl.addElement(sWebDir + "Value.java");
      hhUrl.addElement(sWebDir + "Reference.java");
      hhUrl.addElement(sWebDir + "ReferenceDocument.java");

      String sCurrentUrl;

      wdResource.setLocalDirectory(fDir.toString());

      /*
      Iterator ii = hhUrl.iterator();
      while (ii.hasNext())
      {
        sCurrentUrl = (String)ii.next();
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }
      */

      for (int ii = 0; ii < hhUrl.size(); ii++)
      {
        sCurrentUrl = (String)hhUrl.elementAt(ii);
        wdResource.setUrl(sCurrentUrl);
        
        System.out.println(wdResource.printStartMessage());
        wdResource.download();
        System.out.println(wdResource.printStatistics());
      }

      System.exit(-1);
    } //-- choice i

    StringBuffer sMessage = new StringBuffer("");

  } //-- main()
  
} //-- GetSomething class
