downloader-1.0-SNAPSHOT

16:35:26.218 INFO  jd.cli.Main - Decompiling downloader-1.0-SNAPSHOT.jar
package com.eviware.downloader;

import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class VersionDetector
{
  static final String LATEST_VERSION_XML_LOCATION = "http://dl.eviware.com/version-update/loadui-version.xml";
  private String latestVersion;
  
  public String getLatestVersionAvailable(Proxy proxy)
    throws IOException, ParserConfigurationException, SAXException
  {
    Document doc = getVersionDocument(proxy);
    
    doc.getDocumentElement().normalize();
    NodeList nodeLst = doc.getElementsByTagName("version");
    
    Node fstNode = nodeLst.item(0);
    if (fstNode.getNodeType() == 1)
    {
      Element fstElmnt = (Element)fstNode;
      
      NodeList vrsnNmbrElmntLst = fstElmnt.getElementsByTagName("version-number");
      Element vrsnNmbrElmnt = (Element)vrsnNmbrElmntLst.item(0);
      NodeList vrsnNmbr = vrsnNmbrElmnt.getChildNodes();
      latestVersion = vrsnNmbr.item(0).getNodeValue().toString();
    }
    return latestVersion;
  }
  
  protected Document getVersionDocument(Proxy proxy)
    throws ParserConfigurationException, SAXException, IOException
  {
    URL versionUrl = new URL("http://dl.eviware.com/version-update/loadui-version.xml");
    URLConnection conn;
    URLConnection conn;
    if (proxy != null) {
      conn = versionUrl.openConnection(proxy);
    } else {
      conn = versionUrl.openConnection();
    }
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(conn.getInputStream());
    return doc;
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.VersionDetector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.eviware.downloader;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.URI;
import java.net.URL;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class ProgressBar
{
  private static final String MAVEN_LOADUI_DOWNLOADER_PRO = "maven.loadui.downloader.pro";
  private static final String LOADUI_PIC_24_BIT_PNG = "Installer_pic_loadUI_PNG.png";
  private static final String PRO_LOADUI_PIC_24_BIT_PNG = "loadUI-pro-general_installer-pic-24-bit-PNG.png";
  private static final String FRAME_ICON = "loadui-logo-icon-16.png";
  private static final String RESOURCES = "/";
  private static final String FRAME_TITLE = "Setup - soapUI installer";
  private static final String PRO_FRAME_ICON = "loadui-logo-icon-16-pro.png";
  private JFrame frame;
  private JProgressBar progressBar;
  private boolean pro;
  
  public ProgressBar(int size)
  {
    if (System.getProperty("maven.loadui.downloader.pro") != null) {
      pro = Boolean.valueOf(System.getProperty("maven.loadui.downloader.pro")).booleanValue();
    }
    frame = new JFrame("Setup - soapUI installer");
    frame.setIconImage(getFrameIcon().getImage());
    
    frame.setDefaultCloseOperation(0);
    addClosingListener();
    
    frame.setResizable(false);
    frame.setLocation(300, 300);
    
    Container content = frame.getContentPane();
    progressBar(size);
    
    content.add(westPanel(), "West");
    
    content.add(centerPanel(), "Center");
    
    content.add(eastPanel(), "East");
    
    frame.setSize(500, 350);
    frame.setVisible(true);
  }
  
  private ImageIcon getLoaduiImage()
  {
    String path = null;
    if (pro) {
      path = "/loadUI-pro-general_installer-pic-24-bit-PNG.png";
    } else {
      path = "/Installer_pic_loadUI_PNG.png";
    }
    return getImageIcon(path);
  }
  
  private ImageIcon getImageIcon(String path)
  {
    URL imgURL = null;
    try
    {
      File file = new File(path);
      if (file.exists()) {
        imgURL = file.toURI().toURL();
      } else {
        imgURL = getClass().getResource(path);
      }
      return new ImageIcon(imgURL);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  private ImageIcon getFrameIcon()
  {
    String path = null;
    if (pro) {
      path = "/loadui-logo-icon-16-pro.png";
    } else {
      path = "/loadui-logo-icon-16.png";
    }
    return getImageIcon(path);
  }
  
  private void progressBar(int size)
  {
    if (size != -1) {
      progressBar = new JProgressBar(0, size);
    } else {
      progressBar = new JProgressBar();
    }
    progressBar.setStringPainted(true);
    progressBar.setString("");
    progressBar.setValue(0);
    progressBar.setBorderPainted(false);
    progressBar.setBackground(Color.WHITE);
    progressBar.setBorder(BorderFactory.createMatteBorder(5, 7, 5, 7, Color.WHITE));
    if (pro) {
      progressBar.setForeground(new Color(255, 127, 32));
    } else {
      progressBar.setForeground(Color.GREEN);
    }
  }
  
  private JLabel westPanel()
  {
    JLabel westArea = new JLabel(getLoaduiImage());
    return westArea;
  }
  
  private JPanel centerPanel()
  {
    JPanel centerArea = new JPanel();
    centerArea.setBackground(Color.WHITE);
    centerArea.setLayout(new BoxLayout(centerArea, 1));
    centerArea.add(Box.createRigidArea(new Dimension(0, 140)));
    centerArea.add(new JLabel("Downloading loadUI " + (pro ? "Pro" : "")));
    centerArea.add(new JLabel("Please wait..."));
    centerArea.add(Box.createRigidArea(new Dimension(0, 20)));
    centerArea.add(progressBar);
    centerArea.add(Box.createVerticalGlue());
    return centerArea;
  }
  
  private JPanel eastPanel()
  {
    JPanel eastArea = new JPanel();
    eastArea.setBackground(Color.WHITE);
    eastArea.setBorder(BorderFactory.createMatteBorder(5, 16, 5, 16, Color.WHITE));
    eastArea.setLayout(new BoxLayout(eastArea, 1));
    JButton button = new JButton(new CancelAction(null));
    button.setText("Cancel");
    eastArea.add(Box.createRigidArea(new Dimension(0, 280)));
    eastArea.add(button, "Center");
    eastArea.add(Box.createVerticalGlue());
    return eastArea;
  }
  
  public void setProgressValue(int progress)
  {
    progressBar.setValue(progress);
  }
  
  protected JProgressBar getProgressBar()
  {
    return progressBar;
  }
  
  private void addClosingListener()
  {
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        ProgressBar.this.confirmClose();
      }
    });
  }
  
  private void confirmClose()
  {
    int confirmed = JOptionPane.showConfirmDialog(null, "Are you sure?", "Cancel download", 0);
    if (confirmed == 0)
    {
      Downloader.removeTempFile();
      closeWindow();
    }
  }
  
  public void closeWindow()
  {
    if (frame != null)
    {
      frame.setVisible(false);
      frame.dispose();
    }
    System.exit(0);
  }
  
  private class CancelAction
    extends AbstractAction
  {
    private CancelAction() {}
    
    public void actionPerformed(ActionEvent e)
    {
      ProgressBar.this.confirmClose();
    }
  }
  
  public JFrame getFrame()
  {
    return frame;
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.ProgressBar
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.eviware.downloader;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

class ProgressBar$1
  extends WindowAdapter
{
  ProgressBar$1(ProgressBar paramProgressBar) {}
  
  public void windowClosing(WindowEvent e)
  {
    ProgressBar.access$100(this$0);
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.ProgressBar.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.eviware.downloader;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;

class ProgressBar$CancelAction
  extends AbstractAction
{
  private ProgressBar$CancelAction(ProgressBar paramProgressBar) {}
  
  public void actionPerformed(ActionEvent e)
  {
    ProgressBar.access$100(this$0);
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.ProgressBar.CancelAction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.eviware.downloader;

import java.io.PrintStream;

public class OS
{
  private static final String SH = ".sh";
  private static final String EXE = ".exe";
  private static final String DMG = ".dmg";
  public static final String EXTENSION = isMac() ? ".dmg" : isWindows() ? ".exe" : ".sh";
  
  private static boolean isWindows()
  {
    Boolean isWindows = new Boolean(System.getProperty("os.name").indexOf("Windows") >= 0);
    return isWindows.booleanValue();
  }
  
  public static boolean isMac()
  {
    Boolean isMac = new Boolean(System.getProperty("os.name").indexOf("Mac") >= 0);
    return isMac.booleanValue();
  }
  
  public static String[] createCommand(String file)
  {
    String[] commandsWin = { "cmd.exe", "/c", file };
    String[] commandsLinux = { "sh", file };
    String[] commandsMac = { "hdiutil", "attach", file };
    
    System.err.println(commandsMac[0] + "__" + commandsMac[1] + "__" + commandsMac[2]);
    return isMac() ? commandsMac : isWindows() ? commandsWin : commandsLinux;
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.OS
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.eviware.downloader;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

public class Downloader
{
  private static final String PREFIX = "loadUI";
  private static File tempFile;
  private static ProgressBar progressBar;
  private static Proxy proxy;
  private static final String VERSION_TOKEN = "version";
  
  public static void main(String[] args)
    throws ParserConfigurationException, SAXException, IOException
  {
    if (args.length < 1)
    {
      System.out.println("Please specify a download url link template");
      return;
    }
    initProxy(args);
    
    String downloadPathWithVersion = getLatestVersionPath(args[0]);
    
    boolean success = download(downloadPathWithVersion);
    if ((success) && (shouldInstall())) {
      startInstaller();
    }
    removeTempFile();
    closeWindow();
  }
  
  private static String getLatestVersionPath(String downloadPathTemplate)
    throws IOException, ParserConfigurationException, SAXException
  {
    String version = new VersionDetector().getLatestVersionAvailable(proxy);
    return downloadPathTemplate.replaceAll("version", version) + OS.EXTENSION;
  }
  
  private static boolean shouldInstall()
  {
    int confirmed = JOptionPane.showConfirmDialog(null, "loadUI has now been downloaded, the installer is located here:\n" + tempFile + "\nDo you want to start the loadUI installer?", "Start loadUI installer", 0);
    if (confirmed == 0) {
      return true;
    }
    return false;
  }
  
  private static void initProxy(String[] args)
  {
    if (args.length >= 2)
    {
      String host = args[1];
      String port = args[2];
      if ((host.length() == 0) || (port.length() == 0)) {
        return;
      }
      int portNum;
      try
      {
        portNum = Integer.parseInt(port);
      }
      catch (NumberFormatException nfe)
      {
        System.out.println("you have to specify valid port number!");
        return;
      }
      SocketAddress addr = new InetSocketAddress(host, portNum);
      proxy = new Proxy(Proxy.Type.HTTP, addr);
    }
  }
  
  private static boolean download(String urlLink)
  {
    BufferedInputStream in = null;
    BufferedOutputStream fout = null;
    try
    {
      URL url = new URL(urlLink);
      URLConnection conn;
      if (proxy != null) {
        conn = url.openConnection(proxy);
      } else {
        conn = url.openConnection();
      }
      if (conn != null) {
        conn.setConnectTimeout(20000);
      }
      int size = conn.getContentLength();
      in = new BufferedInputStream(conn.getInputStream());
      tempFile = File.createTempFile("loadUI", OS.EXTENSION);
      fout = new BufferedOutputStream(new FileOutputStream(tempFile));
      downloading(in, fout, size);
      return true;
    }
    catch (Exception e)
    {
      URLConnection conn;
      if (progressBar != null) {
        JOptionPane.showMessageDialog(progressBar.getFrame(), "Error - loadUI installer was not downloaded!\n " + e.getMessage());
      } else {
        System.out.println("Error - loadUI installer was not downloaded!\n " + e.getMessage());
      }
      return 0;
    }
    finally
    {
      try
      {
        if (in != null) {
          in.close();
        }
        if (fout != null) {
          fout.close();
        }
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
  }
  
  private static void downloading(BufferedInputStream in, BufferedOutputStream fout, int size)
    throws IOException
  {
    byte[] data = new byte['?'];
    
    progressBar = new ProgressBar(size);
    int count;
    while ((count = in.read(data, 0, 1024)) != -1)
    {
      fout.write(data, 0, count);
      int progress = progressBar.getProgressBar().getValue() + count;
      progressBar.setProgressValue(progress);
    }
    progressBar.setProgressValue(progressBar.getProgressBar().getMaximum());
  }
  
  private static Process startInstaller()
  {
    ProcessBuilder pb = new ProcessBuilder(OS.createCommand(tempFile.getAbsolutePath()));
    pb.directory(tempFile.getParentFile());
    Process p = null;
    try
    {
      byte[] buffer = new byte['?'];
      p = pb.start();
      BufferedInputStream reader = new BufferedInputStream(p.getInputStream());
      reader.read(buffer, 0, buffer.length);
      if (OS.isMac())
      {
        String response = new String(buffer);
        response = response.replaceAll("[\t]", ";");
        String[] fileNames = response.split(";");
        System.out.println("Looking for files in " + fileNames[(fileNames.length - 1)].trim().replaceAll("\n", ""));
        
        File targetDir = new File(fileNames[(fileNames.length - 1)].trim().replaceAll("\n", ""));
        System.out.println("Is Directory " + targetDir.getAbsolutePath() + "__" + targetDir.isDirectory());
        File[] files = targetDir.listFiles();
        System.out.println("Running installer " + files[0]);
        if (files.length > 0)
        {
          String[] arg = new String[2];
          arg[0] = "open";
          arg[1] = files[0].getAbsolutePath();
          pb = new ProcessBuilder(arg);
          pb.start().waitFor();
        }
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
    return p;
  }
  
  public static void removeTempFile()
  {
    if ((tempFile != null) && (tempFile.exists())) {
      tempFile.deleteOnExit();
    }
  }
  
  public static void closeWindow()
  {
    if (progressBar != null)
    {
      if (progressBar.getFrame() != null)
      {
        progressBar.getFrame().setVisible(false);
        progressBar.getFrame().dispose();
      }
      System.exit(0);
    }
  }
}

/* Location:
 * Qualified Name:     com.eviware.downloader.Downloader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd